[英]set_data and autoscale_view matplotlib
I have multiple lines to be drawn on the same axes, and each of them are dynamically updated (I use set_data), The issue being that i am not aware of the x and y limits of each of the lines. 我在同一轴上绘制了多条线,并且每条线都是动态更新的(我使用set_data),问题是我不知道每条线的x和y限制。 And axes.autoscale_view(True,True,True) / axes.set_autoscale_on(True) are not doing what they are supposed to.
而axis.autoscale_view(True,True,True)/ axes.set_autoscale_on(True)并没有做到他们应该做的事情。 How do i auto scale my axes?
如何自动缩放我的轴?
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
I have referred to these already, this , this . 我已经提到了这些, 这个 , 这个 。 In all cases I have come across, the x,y limits are known.
在我遇到的所有情况下,x,y限制都是已知的。 I have multiple lines on the axes and their ranges change, keeping track of the ymax for the entire data is not practical
我在轴上有多条线并且它们的范围发生变化,跟踪整个数据的ymax是不切实际的
A little bit of exploring got me to this, 一点点探索让我这样,
xmin,xmax,ymin,ymax = matplotlib.figure.FigureImage.get_extent(FigureImage)
But here again, i do not know how to access FigureImage from the Figure instance. 但在这里,我不知道如何从图实例访问FigureImage。
Using matplotlib 0.99.3 使用matplotlib 0.99.3
From the matplotlib docs for autoscale_view : 来自autoscale_view的matplotlib文档 :
The data limits are not updated automatically when artist data are changed after the artist has been added to an Axes instance.
在将艺术家添加到Axes实例后更改艺术家数据时,不会自动更新数据限制。 In that case, use matplotlib.axes.Axes.relim() prior to calling autoscale_view.
在这种情况下,请在调用autoscale_view之前使用matplotlib.axes.Axes.relim()。
So, you'll need to add two lines before your plt.draw()
call after the set_data
call: 所以,你需要你之前添加两行
plt.draw()
的调用后set_data
电话:
axes.relim()
axes.autoscale_view(True,True,True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.