我对新的Matplotlib 2.0.0有一个问题。在
默认情况下,新的autolimit_mode值会向帧添加填充。 我不想把它变成一个数字。在
如果我更改rcParams,这些更改会影响到任何生成的图形。在
我可以为单个图形更改此参数而不影响其他图形的行为吗?在
更新
我用一些代码更新了问题,得到了不同的结果。在
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def remove_frame_border(ax):
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
def draw1(xserie, yserie):
fig = plt.figure(figsize=(8,3))
ax = fig.add_subplot(111)
ax.plot(xserie, yserie)
ax.grid(True)
remove_frame_border(ax)
fig.savefig('out1.png', format='png', bbox_inches='tight', pad_inches=0)
def draw2(xserie, yserie):
fig = plt.figure(figsize=(8,3))
ax = fig.add_subplot(111)
# Fixed autolimit padding in matplotlib 2.0.0
ax.set_xmargin(0)
ax.set_ymargin(0)
ax.autoscale_view()
ax.plot(xserie, yserie)
ax.grid(True)
remove_frame_border(ax)
# Restore default matplotlib params
matplotlib.rcParams.update(matplotlib.rcParamsDefault)
fig.savefig('out2.png', format='png', bbox_inches='tight', pad_inches=0)
def draw3(xserie, yserie):
# Fixed autolimit padding in matplotlib 2.0.0
matplotlib.rcParams['axes.autolimit_mode'] = 'round_numbers'
matplotlib.rcParams['axes.xmargin'] = 0
matplotlib.rcParams['axes.ymargin'] = 0
fig = plt.figure(figsize=(8,3))
ax = fig.add_subplot(111)
ax.plot(xserie, yserie)
ax.grid(True)
remove_frame_border(ax)
# Restore default matplotlib params
matplotlib.rcParams.update(matplotlib.rcParamsDefault)
fig.savefig('out3.png', format='png', bbox_inches='tight', pad_inches=0)
xserie = np.array([1,2,3,4,5,6,7,8,9,10])
yserie = np.array([0, 22.2, 33.4, 55.6, 66.6, 77.7, 100.3, 123.3, 90.4, 93.3])
draw1(xserie, yserie)
draw2(xserie, yserie)
draw3(xserie, yserie)
Matplotlib提供方法^{} :
如此设置
删除填充。在
然而,这似乎要产生效果,人们还需要打电话 ^{}
^{pr2}$我不完全理解
autoscale_view
的docstring,但是这里的组合似乎可以工作。在相关问题 更多 >
编程相关推荐