我有多条线要在同一个轴上绘制,并且每一条线都是动态更新的(我使用set_data),问题是我不知道每条线的x和y限制。和轴。自动缩放视图(真,真,真)/轴。设置自动缩放为开(真)并没有做它们应该做的。如何自动缩放轴?
import matplotlib.pyplot as plt
fig = plt.figure()
axes = fig.add_subplot(111)
axes.set_autoscale_on(True)
axes.autoscale_view(True,True,True)
l1, = axes.plot([0,0.1,0.2],[1,1.1,1.2])
l2, = axes.plot([0,0.1,0.2],[-0.1,0,0.1])
#plt.show() #shows the auto scaled.
l2.set_data([0,0.1,0.2],[-1,-0.9,-0.8])
#axes.set_ylim([-2,2]) #this works, but i cannot afford to do this.
plt.draw()
plt.show() #does not show auto scaled
我已经提到过这些,this,this。 在我遇到的所有情况下,x,y极限都是已知的。我在轴上有多条线,它们的范围也在变化,跟踪整个数据的ymax是不实际的
一点点探索让我明白了这一点
xmin,xmax,ymin,ymax = matplotlib.figure.FigureImage.get_extent(FigureImage)
但是在这里,我不知道如何从Figure实例访问FigureImage。
使用matplotlib 0.99.3
从matplotlib docs for autoscale_view:
因此,您需要在
plt.draw()
调用之前和set_data
调用之后添加两行:相关问题 更多 >
编程相关推荐