Difference between revisions of "MatPlotLib Tutorial 1"

From dftwiki3
Jump to: navigation, search
(The Simplest Approach)
(Scatter Plot of (X, Y) points)
Line 53: Line 53:
  
 
==The Simplest Approach==
 
==The Simplest Approach==
[[Image:MatPlotLib_SimplestApproach.png|200px|right]]
+
[[Image:MatPlotLib_SimplestApproach.png|300px|right]]
 
* You have an array of ''N'' Y-values, and you want to display them at X-values ranging from 0 to ''N''-1:
 
* You have an array of ''N'' Y-values, and you want to display them at X-values ranging from 0 to ''N''-1:
  
Line 76: Line 76:
 
<br />
 
<br />
 
==Changing Colors and Adding Markers==
 
==Changing Colors and Adding Markers==
[[Image:MatPlotLib_SimplestApproachColorMarkers.png|200px|right]]
+
[[Image:MatPlotLib_SimplestApproachColorMarkers.png|300px|right]]
 
<br />
 
<br />
 
<source lang="python">
 
<source lang="python">

Revision as of 10:39, 25 April 2011

--D. Thiebaut 10:27, 25 April 2011 (EDT)



MatPlotLib.png



This tutorial will introduce you to the MatPlotLib Python library for generating graphs.




Other Sources of Information

Setup

We use the Eclipse IDE and PyDev to develop Python packages. If you want to setup your environment to match the one used here you will need to install:

  1. Eclipse: http://www.eclipse.org/downloads/
  2. Python: http://www.python.org/download/
  3. PyDev: http://pydev.org/download.html
  4. EDP from Enthought: https://www.enthought.com/products/. It contains all you need to run MatPlotLib.

Default Python

  • You should make the Python version installed by EDP as the default Python interpreter for Eclipse/PyDev.
  • First open a Terminal window and type:
 which python
 /Library/Frameworks/Python.framework/Versions/Current/bin/python
  • Record the answer to the command and enter it in Eclipse's Preference window for PyDev:

EclipsePyDevDefaultPythonInterpreter.png

Testing


MatPlotLib1.png


Scatter Plot of (X, Y) points

The Simplest Approach

MatPlotLib SimplestApproach.png
  • You have an array of N Y-values, and you want to display them at X-values ranging from 0 to N-1:


def plot2():
    plt.plot([1,3,2,4])
    plt.ylabel('Intensity')
    plt.show()







Changing Colors and Adding Markers

MatPlotLib SimplestApproachColorMarkers.png


def plot3():
    plt.plot([1,3,2,4], 'ro' )
    plt.ylabel('Intensity')
    plt.show()