简体   繁体   English

获取调整大小的matplotlib图窗口的大小

[英]Get size of resized matplotlib plot window

I am using matplotlib and Tkinter to plot some data. 我正在使用matplotlib和Tkinter绘制一些数据。 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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