Closed Atcold closed 2 years ago
Apparently pylustrator does not work when using the pylab * import. I would strongly recommend to import matplotlib and numpy directly with "import matplotlib.pyplot as plt" and "import numpy as np" as it makes the code more readable. For example if you use "max" it is not clear if you are using the builtin function max or the numpy function max, as your approach silently overwrote it.
See also the warning box here: https://matplotlib.org/stable/api/index.html?highlight=pylab#module-pylab
As pylustrator overloads the plt.figure and plt.show commands, it cannot work if you have already imported them directly without still being in the namespace of a module. Therefore, you need to write it like this when using pylustrator.
import matplotlib.pyplot as plt
import numpy as np
π = np.pi
import pylustrator
pylustrator.start()
t = np.linspace(0, 1)
x = np.sin(2 * π * t)
plt.plot(t, x)
plt.show()
if you want to keep your code like this, you can alternatively just use plt.show() for opening the pylustrator and leave the rest as it is. As just this is the crucial part.
So this also works, although I would recommend against importing with *
from matplotlib.pylab import *
π = pi
import pylustrator
pylustrator.start()
t = linspace(0, 1)
x = sin(2 * π * t)
plot(t, x)
import matplotlib.pyplot as plt
plt.show()
Oh, thanks! It does work! 🎉
Thanks for the recommendation as well, but I'd rather use a calculator without the need to tell it where to find its functions. If I do write code, then yes, I use namespaces. If I do maths, then no, it just bogs down the thinking.
Finally, not sure this is a bug, but the button strings are quite illegible.
Also, I believe some y
's are missing.
When I try running the following code I get two white screens.
Commenting out the pylustrator's line, I get the following.
I'm using
matplotlib 3.5.1
.