Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create padding within plot

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!

like image 729
zarathustra Avatar asked May 12 '14 12:05

zarathustra


People also ask

What is padding in plot?

Padding is the empty space between the axis (ticks and labels) and the edge of the figure.

What is padding in Matplotlib?

Padding (height/width) between edges of adjacent subplots, as a fraction of the font size. Defaults to pad. rect : tuple (left, bottom, right, top), optional. A rectangle (left, bottom, right, top) in the normalized figure coordinate that the whole subplots area (including labels) will fit into. Default is (0, 0, 1, 1) ...

How do I increase padding in Matplotlib?

Using subplots_adjust() method to set the spacing between subplots. We can use the plt. subplots_adjust() method to change the space between Matplotlib subplots.


1 Answers

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).

like image 160
Ffisegydd Avatar answered Sep 19 '22 23:09

Ffisegydd