matplotlib - plot function in python -
i'm complete newbie python (this first post) have experience programming in r. i've been going through crash course in python scientists tutorial.
i got far matplotlib bit-i havent been able go beyond plot function not recognized despite importing matplotlib. i'm using idle in python 2.7.3 (i'm using mac).
here's i'm trying do:
>>> import matplotlib >>> plot(range(20)) here's error message: # error message
traceback (most recent call last): file "<pyshell#9>", line 1, in <module> plot(range(20)) nameerror: name 'plot' not defined can out @ all? know there loads of other editors use prefer similar r console can type directly command line. still haven't figured out short cut running code directly idle editor-my f5 key else , doesn't run when type it.
plot function of matplotlib.pyplot, so:
import matplotlib.pyplot plt plt.plot(range(20)) edit:
to see plot, need call
plt.show() to display figure, or
plt.savefig('figname.png') to save figure file after calling plt.plot().
as @jrichardsnape pointed out in comments, import matplotlib.pyplot plt used convention, , implied around site. beginners guide has useful information on this.
Comments
Post a Comment