So currently learning how to import data and work with it in matplotlib and I am having trouble even tho I have the exact code from the book.
This is what t
In matplotlib 2.x there is an automatic margin set at the edges, which ensures the data to be nicely fitting within the axis spines. In this case such a margin is probably desired on the y axis. By default it is set to 0.05
in units of axis span.
To set the margin to 0
on the x axis, use
plt.margins(x=0)
or
ax.margins(x=0)
depending on the context. Also see the documentation.
In case you want to get rid of the margin in the whole script, you can use
plt.rcParams['axes.xmargin'] = 0
at the beginning of your script (same for y
of course). If you want to get rid of the margin entirely and forever, you might want to change the according line in the matplotlib rc file:
axes.xmargin : 0
axes.ymargin : 0
plt.xlim(..)
or ax.set_xlim(..)
to manually set the limits of the axes such that there is no white space left.