简体   繁体   中英

Get size of resized matplotlib plot window

I am using matplotlib and Tkinter to plot some data. When I press a button, my graph is created in an independent window of given size. If I click again on the button, the graph is again created in the same position. Now, if I manually resize the window after pressing the button for the first time, the next time I press the button the window gets back to the original size that I set. Is there any way to 'read' the window size that I have manually modified with the mouse cursor so the next time the button is pressed the figure appears in the same window?

These are bits of my code:

plt.Figure()
thismanager = get_current_fig_manager()
thismanager.window.wm_geometry("500x500+890+300")
thismanager.set_window_title('Title')

plt.clf()
plt.xlabel('Xaxis',fontsize=16)

im=imshow(variableName,cmap='gray',origin='lower',vmin=0,vmax=255,interpolation='nearest')

cb=colorbar()
cb.set_label('Label',fontsize=16)
show()

I found myself a solution, this is the code:

plt.Figure()
thismanager = get_current_fig_manager()
thismanager.window.wm_geometry("500x500+890+300") #sets original size and position
button = Tkinter.Button(self,command=self.Click)

def Click(self):
   thismanager = get_current_fig_manager()
   thismanager.set_window_title('Title')
   plt.clf()
   plt.xlabel('Xaxis',fontsize=16)
   im=imshow(variable, cmap='gray', origin='lower',vmin=0,vmax=255,interpolation='nearest')
   cb=colorbar()
   cb.set_label('Label',fontsize=16)
   show()

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