我试图表示如图2所示的信息,但结果是图1。我怎样才能像图2那样推边界。 `你知道吗
plot = newData.copy()
del plot['Region']; del plot['Country']; del plot['2016 Rank']
plot.index = range(0, 20)
fig = plt.figure(figsize=(8,4))
plt.title('Springfield')
plt.ylabel('CPI')
plt.yticks(range(20,90,10))
plt.xticks(num.arange(5), ( '2012 Score', '2013 Score', '2014 Score', '2015 Score', '2016 Score', ))
plt.grid(axis='both', which='major')
for x in plot.values:
plt.plot(x, color='gray', linewidth=1, marker='o', markerfacecolor='gray', markersize=6)
plt.show()
`
这里基本上是this answer的倒数:
在matplotlib 2.x中,在边上设置了一个自动边距,确保数据很好地拟合轴脊椎。默认情况下,以轴跨度为单位将其设置为0.05。默认情况下,2.x之前的matplotlib版本中不存在此边距。但是,用于设置边距的命令也存在于以前的版本中:
或者
取决于上下文。为两个轴方向设置单个值是同样可行的:
另见the documentation。你知道吗
如果要在整个脚本中设置边距,可以使用
在脚本的开头(当然y也是)。如果您想完全且永远地设置边距,您可能需要更改matplotlib rc file中的相应行。你知道吗
除了更改边距之外,还可以使用
plt.xlim(..)
或ax.set_xlim(..)
手动设置轴的限制,这样就不会留下空白。你知道吗相关问题 更多 >
编程相关推荐