Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...