1

Pyplot

I wrote the code to plot and display a simple graph in Python:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import interactive
interactive(True)

x = np.arange(0,5,0.1)
y = np.sin(x)
plt.plot(x,y)
plt.show

And all I got is a blank screen.

And when I remove the "interactive" thing it shows no error but diplays nothing.

How can I display the graph?

(P.S: I use Python 2.7)

4 Answers 4

3

Remove these lines, they are not for a simple graphic:

from matplotlib import interactive
interactive(True)

And you're missing the () in the plt.show()

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

1

There is a syntax error. Replace plt.show with plt.show()

Comments

0

Just a note for others for future reference the full code should also include plt.figure() with the interactive elements removed.

Here what I came up with.

import matplotlib.pyplot as plt
import numpy as np
plt.figure()
x = np.arange(0, 5, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.show()

But this may be a 3.5 problem I've not tried in 2.7

Comments

0

You can also plot graphs with pyformulas. First pip install pyformulas, then

import pyformulas as pf
import numpy as np

x = np.linspace(-10,10,100)
y = x**2 + x*np.e**(np.cos(x)**2)
pf.plot(x, y)

Disclaimer: I'm the maintainer of pyformulas

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.