Reputation: 77
I checked the Demo_Matplotlib.py script of PySimpleGUI DemoPrograms repository on GitHub, but could not find any demo programs created for embedding PySimpleGUI with PyLab. How can I embed PyLab into my PySimpleGUI code?
Upvotes: 1
Views: 543
Reputation: 5754
You can adapt the existing Matplotlib demo program and exchange the plotting calls with PyLab plotting calls.
A new PyLab demo is posted on the PySimpleGUI GitHub Demo Programs page: https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Matplotlib_PyLab.py
The important part of the code to change is at the top. If you want to modify the other Matplotlib demos, then replace the portion of the code where comments indicate is the location for MatplotLib code.
[EDIT] - While researching PyLab, I ran across this statement which I'll be adding to the Demo Program's comments:
PyLab is a convenience module that bulk imports matplotlib.pyplot (for plotting) and NumPy (for Mathematics and working with arrays) in a single name space. Although many examples use PyLab, it is no longer recommended.
This bit of code will draw a PyLab figure in the demo program's window:
from numpy import sin
from numpy import cos
x = pylab.linspace(-3, 3, 30)
y = x**2
pylab.plot(x, sin(x))
pylab.plot(x, cos(x), 'r-')
pylab.plot(x, -sin(x), 'g--')
fig = pylab.gcf()
figure_x, figure_y, figure_w, figure_h = fig.bbox.bounds
Upvotes: 2