Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Description
Bug summary
A similar issues was opened and closed a few times. The bug is still there, though now it is a little different. The graphics window shows the buttons with text instead of the icon.
This is what it looks like
This is on Fedora Linux, recently updated matplotlib, using TkAgg.
Apologies perhaps for opening this as a new issue, but it does look different and I do not have permission to reopen the old issue.
Code for reproduction
#!/usr/bin/python""" GraphicsWindow.py: realtime graphics window for data acqusition """__author__="Mitchell C. Nelson, PhD"__copyright__="Copyright 2022, Mitchell C, Nelson"__version__="0.2"__email__="drmcnelson@gmail.com"__status__="alpha testing"versionstring='GraphicsWindow.py - version %s %s M C Nelson, PhD, (c) 2021'%(__version__,__status__)importnumpyasnpfromthreadingimportLock,Semaphore,Thread#from queue import SimpleQueue, EmptyfrommultiprocessingimportProcess,Queue,Valueimportqueuefromtimeimportsleep,time,process_time,thread_timeimportmatplotlibasmplmpl.use("TkAgg")#mpl.use("TkCairo" )importmatplotlib.pyplotaspltplt.rcParams['toolbar']='toolmanager'frommatplotlib.backend_toolsimportToolBase,ToolToggleBasefrommatplotlib.figureimportFigurefrommatplotlib.animationimportFuncAnimationfrommatplotlib.backends.backend_tkaggimportFigureCanvasTkAggfrommatplotlib.backends.backend_tkaggimportNavigationToolbar2Tk#from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg as NavigationToolbar2TkclassGraphicsWindow:def__init__(self,name,xdata=None,xrange=None,xlabel=None,ycols=None,yrange=None,ylabels=None,geometry='1000x600',queue=None,flag=None,nlength=0,ncolumns=0,debug=False ):# -----------------------# default the initial dataifnameisNone:name='Data'self.name=nameself.debug=debugifxdataisNone:xdata=np.linspace(0,nlength,nlength )self.xdata=xdataifxlabelisNone:xlabel='index'self.xlabel=xlabelself.xrange=xrangeifycolsisNone:ycols= [np.zeros(nlength)]*ncolumnsself.ycols=ycolsifylabelsisNone:ylabels= ['Chan %d'fordinrange(ncolumns) ]self.ylabels=ylabelsself.yrange=yrangeself.geometry=geometryifqueueisNone:self.queue=Queue()else:self.queue=queueifflagisNone:self.flag=Value('i',1)else:self.flag=flagself.flag.value=1self.thread=Noneself.history= []self.historypointer=0defanimation(self,interval=200,blit=True ):self.fig=plt.figure(self.name)ifself.geometryisnotNone:dpi=self.fig.get_dpi()width,height=self.geometry.lower().split('x',maxsplit=1)self.fig.set_size_inches(int(width)/dpi,int(height)/dpi )self.fig.subplots_adjust(top=0.9)# This gives us scrolling through the history recordself.fig.canvas.manager.toolmanager.add_tool('Prev',self.PreviousGraph,graphobj=self )self.fig.canvas.manager.toolmanager.add_tool('Next',self.NextGraph,graphobj=self )self.fig.canvas.manager.toolmanager.add_tool('Last',self.LastGraph,graphobj=self )self.fig.canvas.manager.toolbar.add_tool('Prev','toolgroup',-1)self.fig.canvas.manager.toolbar.add_tool('Next','toolgroup',-1)self.fig.canvas.manager.toolbar.add_tool('Last','toolgroup',-1)self.ax=self.fig.add_subplot(1,1,1)self.lns= []fory,labelinzip(self.ycols,self.ylabels ):ln=self.ax.plot(self.xdata,y,label=label )ln=ln[0]#print( 'ax.plot returned', ln )self.lns.append(ln)self.ylabels.append(label)self.txt=self.ax.text(0.99,0.99,'0',horizontalalignment='right',verticalalignment='top',transform=self.ax.transAxes )self.ax.legend(loc='upper left' )ifself.xrange:self.ax.set_xlim(self.xrange )ifself.yrange:self.ax.set_ylim(self.yrange )# still need plt.show() to launch it.ifself.queueisnotNone:self.ani=FuncAnimation(self.fig,self.animation_update,interval=200,blit=blit )self.fig.canvas.mpl_connect('close_event',self.close )plt.show()plt.close()defanimation_update(self,i ):ifself.flag.value:whileTrue:try:record=self.queue.get(block=False)self.graphrecord_(record )self.history.append(record)iflen(self.history)>100:self.history.pop(0)self.historypointer=len(self.history)-1#print( 'got record' )exceptqueue.Empty:breakelse:self.ani.event_source.stop()plt.close()#return tuple( self.lns) + ( self.txt, )return (self.txt,*self.lns )defstart(self,interval=200,blit=True ):self.thread=Process(target=self.animation,args=(interval,blit) )self.thread.start()defclose(self,ignored=None ):self.flag.value=0ifself.thread:try:self.thread.terminate()self.thread.join()exceptExceptionase:pass# ---------------------------------------------------------# graph (verb) the passed recorddefgraphrecord_(self,record ):ycols,text=recordiflen(ycols)>1:x=ycols[0]forn,yinenumerate(ycols[1:] ):self.lns[n].set_data(x,y )self.ax.set_xlim(left=min(x),right=max(x) )self.ax.relim()self.ax.autoscale_view()eliflen(ycols)==1:self.lns[0].set_ydata(ycols[0] )self.txt.set_text(text )# History button graph functionsclassLastGraph(ToolBase):default_keymap='up'description='last data vector'def__init__(self,*args,**kwargs):self.graph=kwargs.pop('graphobj')super().__init__(*args,**kwargs)#ToolBase.__init__(self, *args, **kwargs)deftrigger(self,*args,**kwargs):#print('last graph key pressed')try:record=self.graph.history[-1]self.graph.historypointer=len(self.graph.history)-1self.graph.graphrecord_(record )self.graph.fig.canvas.draw()exceptExceptionase:print("LastGraph",e )classNextGraph(ToolBase):default_keymap='right'description='next data vector'def__init__(self,*args,**kwargs):self.graph=kwargs.pop('graphobj')super().__init__(*args,**kwargs)#ToolBase.__init__(self, *args, **kwargs)deftrigger(self,*args,**kwargs):#print('next graph key pressed')ifself.graph.historypointer<len(self.graph.history)-1:self.graph.historypointer+=1record=self.graph.history[self.graph.historypointer]self.graph.graphrecord_(record )self.graph.fig.canvas.draw()else:print('already at last graph' )classPreviousGraph(ToolBase):default_keymap='left'description='prev data vector'def__init__(self,*args,**kwargs):self.graph=kwargs.pop('graphobj')super().__init__(*args,**kwargs)#ToolBase.__init__(self, *args, **kwargs)deftrigger(self,*args,**kwargs):#print('previous graph key pressed')ifself.graph.historypointer>0:self.graph.historypointer-=1record=self.graph.history[self.graph.historypointer]self.graph.graphrecord_(record )self.graph.fig.canvas.draw()else:print('already at first graph' )# ---------------------------------------------------------defgraphupdate(self,xdata=None,ycols=None,text=None ):ifycolsisnotNone:forln,yinzip(self.lns,ycols):ln.set_ydata(y )ifxdataisnotNone:forlninself.lns:ln.set_xdata(xdata )self.ax.set_xlim(left=min(xdata),right=max(xdata) )self.ax.relim()self.ax.autoscale_view()iftextisnotNone:self.txt.set_text(text )return (self.txt,*self.lns )
Actual outcome
Expected outcome
Normal looking graphics window with arrow icons and etc.
Additional information
Happens every time.
Operating system
Fedora Cinnamon Spin
Matplotlib Version
3.9.4
Matplotlib Backend
TkAgg
Python version
3.13.3
Jupyter version
No response
Installation
Linux package manager
Metadata
Metadata
Assignees
Labels
No labels