matlibplot在按钮内绘图

时间:2014-02-24 01:38:53

标签: matplotlib

我想知道为什么我的matlibplot当前正在按钮内部绘图,如下所示:

Although kind of funny, quite annoying

代码如下所示

from gui export Index
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button

fig, ax = plt.subplots()
plt.subplots_adjust(buttom-0.2)

pos_trim = plt.axes([0.20, 0.05, .1, 0.075])
b_trim = Button(pos_trim, 'Trim', hoverclor='0.25')

callback = Index(c)
b_trim.on_clicked(callback.autoTrim) # from gui.index

freqs = np.arange(2,20,3)
t = np.arange(0.0, 1.0, 0.05)
s = np.sin(2*np.pi*freqs[0]*t)

l, = plt.plot(t,s,lw=2)
plt.show()

索引类:

class Index:

  def __init__(self, chart):
    self.__chart = chart

  def autoTrim(self, event):
    print "Autotrim"
    #self.__chart.autoTrim()
    plt.draw()

1 个答案:

答案 0 :(得分:1)

尝试更改您将数据绘制到的行:

l, = ax.plot(t,s,lw=2)

即,绘制您为绘图创建的轴(ax)。否则,您将绘制到您创建的最后一个轴,在这种情况下,是按钮。