我已經實現了一個sync block
,該函數在其work
函數內使用input_items
值進行繪製。現在問題在於繪圖機制對於輸入流不夠快(input_items
的值不斷變化)。由於快速輸入流而凍結成GNU Radio塊
我試圖儘可能簡化代碼並添加註釋。那就是:
....
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
temp = ''
class xyz(gr.sync_block):
def __init__(self,parent,title,order):
a = []
self.count = 1
gr.sync_block.__init__(self,
name="xyz",
in_sig=[numpy.float32,numpy.float32],
out_sig=None)
self.win = xyzPlot(parent) #I have a Top Block(wxFrame). I am just making it the parent of xyzPlot(wxPanel) here.
def work(self, input_items, output_items):
global temp
if (self.count == 1):
temp = input_items+list()
bool = not(np.allclose(temp,input_items))#bool will be true if the value of `input_items` changes.
.......
#the code that evaluates z1,z2 depending on the value of input_items
.......
if (bool or self.count == 1):
#If bool is true or it is the first time then I am calling plot() which plots the graph.
self.win.plot(tf(self.z1,self.z3),None,True,True,True,True)
self.count = 0
temp = input_items+list()
return len(input_items[0])
class xyzPlot(wx.Panel):
def __init__(self, parent, dB=None, Hz=None, deg=None):
wx.Panel.__init__(self , parent , -1 ,size=(600,475))
self.fig = Figure()
self.axes = self.fig.add_subplot(111)
def plot(self, syslist, omega=None, dB=None, Hz=None, deg=None, Plot=True, *args , **kwargs):
self.axes.clear() #I clear the graph here so that new values can be plotted.
.....
self.axes.semilogx(omega,mag,*args,**kwargs)
self.canvas = FigCanvas(self, -1, self.fig)
self.canvas.draw()
正如你可以看到我與wxPython的工作,但每當我改變input_items
太快(如果我改變它慢慢地它工作正常)的值面板凍結。任何建議?我是新來的。
請勿清除軸並重建藝術家。創建一次,並保留一個參考。然後你可以使用'set_data'來只改變數據點。畫布同樣適用。只創建一次,然後調用'draw'應該足以更新數字。 – hitzg
@hitzg:的確如此,但問題似乎在於他是異步的,並且以高速率繪製不是GUI線程的線程中的東西。我想你可能會更好地習慣matplotlib/wx集成,所以我很想看到你的評論在我的[答](http://stackoverflow.com/a/31068633/4433386)。 –
@MarcusMüllerꕺꕺ不是。我的評論僅僅是關於如何加快劇情更新的建議。 – hitzg