我在同一轴上绘制了多条线,并且每条线都是动态更新的(我使用set_data),问题是我不知道每条线的x和y限制.而axis.autoscale_view(True,True,True)/ axes.set_autoscale_on(True)并没有做到他们应该做的事情.如何自动缩放我的轴?
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
Run Code Online (Sandbox Code Playgroud)
我已经提到了这些,这个,这个.在我遇到的所有情况下,x,y限制都是已知的.我在轴上有多条线并且它们的范围发生变化,跟踪整个数据的ymax是不切实际的
一点点探索让我这样,
xmin,xmax,ymin,ymax = matplotlib.figure.FigureImage.get_extent(FigureImage)
Run Code Online (Sandbox Code Playgroud)
但在这里,我不知道如何从图实例访问FigureImage.
使用matplotlib 0.99.3
在使用matplotlib绘制图形后,我喜欢用y轴切换x轴吗?有什么简单的方法吗?提前致谢.