matplotlib修改自动缩放规则

时间:2013-04-14 19:19:22

标签: matplotlib

绘图时,matplotlib会自动设置绘制数据内容的比例。但似乎两个轴上的限制总是等于给定绘制的数据的最大值。它使得达到最大值的数据标记被捕获。我想改变这种行为,这样无论标记大小如何,它都会在图的四边留下一些空间。至少,有没有办法简单地设置静态的,用户定义的边距?

一个例子:

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)

这个例子清楚地显示了3个被裁剪的数据点。

1 个答案:

答案 0 :(得分:3)

(几乎直接从How to autoscale y axis in matplotlib?复制)

您想要margins doc

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

另见Add margin when plots run against the edge of the graph