user1850133
user1850133

Reputation: 2993

matplotlib modify autoscaling rules

when plotting, matplotlib sets automatically the scales from the data content being plotted. But it seems the limits on both axes are always equal to the maxima from the data given to be plotted. It makes markers of data reaching maxima being copped. I would like to change this behaviour so that it leaves some space at the four sides of the plot whatever the marker size. At least, is there a way to simply set a static, user defined margin?

an example:

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(np.arange(10) ** 2, 's', ms = 20)

this example clearly shows 3 data points being cropped.

Upvotes: 1

Views: 1437

Answers (1)

tacaswell
tacaswell

Reputation: 87496

(copied almost directly from How to autoscale y axis in matplotlib?)

You want margins doc

ex

ax.margins(y=.1, x=.1)

Also see Add margin when plots run against the edge of the graph

Upvotes: 3

Related Questions