Code Monkey home page Code Monkey logo

Comments (3)

rgerum avatar rgerum commented on May 17, 2024

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()

from pylustrator.

rgerum avatar rgerum commented on May 17, 2024

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()

from pylustrator.

Atcold avatar Atcold commented on May 17, 2024

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.
image

Also, I believe some y's are missing.
image

from pylustrator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.