10

I'm working on my matplotlibwidget that I've created with QtDesigner.

When i draw my testpoints into my plot, they are mostly arranged at the border or cross the axes. Which does not look very familiar to me.

So my question is, how can i tell matplotlib to add some kind of "inner padding" between plot-border and test points. So for example if my minimum value is "500" i would like to plot the left border at around 400, so there is some margin between the least point and border.

Thank you in advance!

1

1 Answer 1

22

plt.margins can be used to adjust the automatic padding around your data as below.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)
y = np.power(x, 3)

plt.plot(x, y, 'ro')

# Create a 5% (0.05) and 10% (0.1) padding in the 
# x and y directions respectively.
plt.margins(0.05, 0.1)

plt.show()

Plot

If you had a minimum value of 500 and wanted the border to be around 400 then you could choose an x-margin percentage of 0.2 as in plt.margins(0.2, 0.2).

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't seem to work with subplots (or maybe it adds space around the whole figure, in a proportion which is hard to understand).
In subplots, use Axes.margins instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.