Here is a short example of some Python code which plots a matplotlib figure.
fig, ax = plt.subplots(1, 1)
ax.plot(df['timestamp'], df['price'])
ax.tick_params(axis='x', labelrotation=30)
fig.savefig('df.pdf')
fig.savefig('df.png')
The x-axis labels are drawn off the edge of the figure. This is caused by the long label text, which is a complete datetime string.
Is there a convenient way to automatically re-adjust the figure such that the the labels are drawn nicely inside the figure area?
There is one way to do it using tight_layout
. However, this does not respect the existing borders on the top and right hand side of the figure. I don’t personally like how figures look without approximatly equal margins around each edge of the figure.