我已制作图表,这是我的代码:
def graphdraw(self):
self.xaxis = []
self.yaxis = []
fig=plt.figure(1)
self.ax=fig.add_subplot(111)
plt.xlabel('Wavelenght[nm]')
plt.ylabel('Intensity[arb. unit]')
self.line, = self.ax.plot(self.xaxis,self.yaxis,'g-', linewidth=1.5, markersize=4)
self.ax.set_xlim(-250,250)
self.ax.set_ylim(0,40000)
def drawg(self):
self.graphdraw()
i = -200
while i <= 200:
self.xaxis.append(i)
self.yaxis.append(i*i)
self.line.set_data(self.xaxis,self.yaxis)
plt.draw()
plt.pause(0.1)
i = i + 1
但是我喜欢自动缩放轴,当我做这样的事情时:self.ax.autoscale_view(True,True,True)
代替这些行:self.ax.set_lim...
它不起作用。我知道这可能是一个愚蠢而微不足道的问题,但任何人都可以帮助我吗?
答案 0 :(得分:0)
好的,没关系。我已经制作了自己的自动缩放功能。
def graphdraw(self):
self.xaxis = []
self.yaxis = []
fig=plt.figure(1)
self.ax=fig.add_subplot(111)
plt.xlabel('Wavelenght[nm]')
plt.ylabel('Intensity[arb. unit]')
self.line, = self.ax.plot(self.xaxis,self.yaxis,'g-', linewidth=1.5, markersize=4)
self.ax.set_xlim(-250,250)
def drawg(self):
self.graphdraw()
i = -200
start = 50
while i <= 200:
z = random.randint(0,450)
self.ax.set_ylim(0,start)
self.xaxis.append(i)
self.yaxis.append(z)
if z > start:
start= z
self.ax.set_ylim(0,start + 50)
self.line.set_data(self.xaxis,self.yaxis)
plt.draw()
plt.pause(0.1)
i = i + 1