Plotting in Pylab

The Open source Python libraries available are:

  • NumPy adds vectors, matrices, and many high-level mathematical functions
  • Scipy adds mathematical classes and functions useful to scientists
  • MatPlotLib adds an object-oriented API for plotting
  • PyLab combines the other libraries to provide a MATLAB-like interface

Pylab commands:

1. pylab.figure(1) :-> gives the figure name

2. pylab.plot() :-> produces the plot

  • The first two arguments to pylab.plot must be sequences of the same length.
  • First argument gives x-coordinates.
  • Second argument gives y-coordinates.

3. :-> displays the plot on output screen

Example :


Note : pylab.figure() should contain number or variable as argument. When tried to give string as argument, it gave below error:

NameError Traceback (most recent call last)
C:\Users\ananth\Documents\6.00.2x Files\ in <module>()
1 import pylab
—-> 2 pylab.figure(sample)
3 pylab.plot([1,3,5,7],[2,4,6,8])

NameError: name ‘sample’ is not defined


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s