-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] The window shrink after using the matplotlib.pyplot.show() #4561
Comments
The PySimpleGUI GitHub Issues bot has determined there is a problem with your Issue's form. Please fix the problems by editing the first comment or the title and then reopen your issue to have it checked again. More detailed information: Title must be ONE of: |
No executable short code to show what the issue. Basically, PySimpleGUI use backend IMO, they use different DPI or Scale for GUI, so you got the odd issue. import numpy as np
import matplotlib.pyplot as plt
import PySimpleGUI as sg
def set_scale(scale):
root = sg.tk.Tk()
root.tk.call('tk', 'scaling', scale)
root.destroy()
def show():
x = np.random.randint(low=1, high=11, size=50)
y = x + np.random.randint(1, 5, size=x.size)
data = np.column_stack((x, y))
ax1.scatter(x=x, y=y, marker='o', c='r', edgecolor='b')
ax1.set_title('Scatter: $x$ versus $y$')
ax1.set_xlabel('$x$')
ax1.set_ylabel('$y$')
ax2.hist(data, bins=np.arange(data.min(), data.max()), label=('x', 'y'))
ax2.legend(loc=(0.65, 0.8))
ax2.set_title('Frequencies of $x$ and $y$')
ax2.yaxis.tick_right()
plt.show()
sg.theme("DarkBlue3")
sg.set_options(font=("Courier New", 80))
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 4))
set_scale(fig.dpi/72) # Set DPI of PySimpleGUI/tkinter to be same as it of Matplotlib/Qt5
layout = [[sg.Button("Show")]]
window = sg.Window('Title', layout, location=(0, 0) , finalize=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == "Show":
show()
window.close() |
Thanks for replying. My code runs well when I added the ’set_scale‘ function. At least the size of PysimpleGUI window is stable.I'd be appreciate if you could tell me what the function exactly does in this case. I guess it probably locked the setting of tkinter?Thank you again. |
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(8, 4))
scale = fig.dpi/72 # why you changed it to fig.dpi/36 ?
root = sg.tk.Tk()
root.tk.call('tk', 'scaling', scale)
root.destroy() Just to set the setting of DPI same in both GUI libraries.
or, you can get the DPI of PySimpleGUI/tkinter, then set the DPI of Matplotlib/Qt5 to it. |
I always thought matplotlib was entirely tkinter based internally. I appreciate the education! |
In following code, you can see there're 21 backends in matplotlib 3.4.2/python 3.9.5 on my WIN10, not only >>> import matplotlib.rcsetup as rcsetup
>>>
>>> print(rcsetup.interactive_bk)
['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo']
>>> print(rcsetup.non_interactive_bk)
['agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
>>> print(rcsetup.all_backends)
['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
>>> len(rcsetup.all_backends)
21 |
For the scale factor, you can refer here jason990420/PySimpleGUI-Solution#80 |
Thanks again.I will ask for help if I encounter other problems. |
Thank you for the open source code that provides me a learning platform! |
Type of Issue (Enhancement, Error, Bug, Question)
Bug
Operating System
Win10
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Version information can be obtained by calling
sg.main_get_debug_data()
Or you can print each version shown in ()
Python version (
sg.sys.version
)3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 12:30:02) [MSC v.1900 64 bit (AMD64)]
PySimpleGUI Version (
sg.__version__
)PySimpleGUI version: 4.45.0
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)tkinter version: 8.6.6
Your Experience In Months or Years (optional)
Years Python programming experience
Years Programming experience overall
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
I've defined a button that, when clicked, will call a drawing function and draw a ’plt‘ image. However when the image has been drawn, the entire window will be smaller than it was before, and the font will be smaller.But the function will still work except for the size.Thank you .
Code To Duplicate
A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)
This pre-formatted code block is all set for you to paste in your bit of code:
Screenshot, Sketch, or Drawing
The text was updated successfully, but these errors were encountered: