简体   繁体   中英

matplotlib blit how to change xaxis and yaxis

I use wxpython and matplotlib to draw a figure. The data is from fpga, and I have to refresh the figure when data comes. In my code I use the matplotlib restore_region .blit method to draw faster, but sometimes I want to change the xticks yticks and labels to see the detail of the figure, but I dont know how to. I just got the following result:

setlabel to the whole scale: 将标签设置为整个比例

After changing the ticks and labels: 更改刻度和标签后

The following is my function to set xticks and yticks.

def setSpLabel(self, begin_X=70, end_X=5995,begin_Y=-120,end_Y=60): 
    self.ylabel('dBm')
    self.xlabel('MHz')
    self.ylim(begin_Y,end_Y)
    self.xlim(begin_X,end_X)
    yticks=linspace(begin_Y,end_Y,15)
    yticklabels = [str(int(i)) for i in yticks]  
    xticks=linspace(begin_X,end_X,15)

    xticklabels = [str(int(i)) for i in xticks]
    self.axes.set_xticks(xticks)
    self.axes.set_xticklabels(xticklabels,rotation=0)
    self.axes.set_yticks(yticks)
    self.axes.set_yticklabels(yticklabels,rotation=0)
    self.axes.grid(True)

    self.axes.get_xaxis().set_animated(True)
    self.axes.get_yaxis().set_animated(True)
    self.FigureCanvas.draw()
    self.axes.get_xaxis().set_animated(False)
    self.axes.get_yaxis().set_animated(False)

    self.axes.draw_artist(self.axes.get_xaxis())
    self.axes.draw_artist(self.axes.get_yaxis())
    self.FigureCanvas.blit(self.axes.bbox)
    self.background=self.FigureCanvas.copy_from_bbox(self.axes.bbox)

How can I change the ticks and labels, and at the same time refresh the plot data?

How about scheduling auto-scaling method every 1 s or so? You can use wx.Timer for this.

self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.setSpLabel, self.timer)        
self.timer.Start(1000) # every 1000 ms

And in setSpLabel, you can look at the current data buffer and scale axes accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM