Forums

Run matplotlib commands

I am currently studying matplotlib and I want to practice it online. How do I run it here? Sample code: x = linspace(0,5,10) y = x ** 2 plot(x,y) show()

This help page should help you get started.

Thanks Giles. Sorry if my ques is very dumb - i am pretty new to this. How do I create a file and save and also what Python interpreter should I use to create a file and save it?

you could just create a file by entering a file name and clicking new file under the files tab. remember to name it with the .py ending though. ie. xyz.py

i would suggest using python3.4 for the interpreter. if you use the save and run button at the file editor page, it defaults to that.

Thanks Conrad! I was able to create the sample file matplots.py and I put the below contents in the file:

import matplotlib

matplotlib.use("Agg")

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)

ax.plot(range(100))

plt.show()

But when I hit save and run it is just prompting(>>> ) and I cannot see the output - how do I see the output for the above code. Should I enter something in the interpreter after hitting save and run?

Please check the help page that Giles pointed you to above.

You won't be able to see the output like that. Change plt.show() to fig.savefig("graph.png"), and then you should get a file called graph.png in your home directory.

Thanks jgmdavies. Thanks everyone - I am now able to run and see the output in the file!!!

Good news! Jim

Awesome, thanks for confirming!