I am making a lot of plots in Matplotlib where the outer datapoints lie on the edge of the plot space, which obscures often important data. For instance, I would like to do something like:
f, ax = subplots(1, 1)
ax.plot([0, 1], [.25, .5], "o")
As written, I end up with a plot where the xaxis goes from 0 to 1 and it's really hard to get an impression of what the data look like (plus it wastes a lot of space).
I would like some way to reset the x axis limits so that a) it adds space on each side and b) the xticks cover the whole xaxis at reasonable (default) intervals. Obviously in the single case I could use ax.set_xlim() and ax.set_xticks(), but I am generating a lot of these plots and don't know ahead of time what the optimal way to adjust the plots will be.
Is there some option in Matplotlib to set the percentage of the x data range that the x axis spans, or similar?
use Axe.margins()
to set the margin of xais & yaxis.
ax.margins(0.1, 0.1)
(doc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With