X-Y Line Plot


How do you do an x-y line plot?


First the good news: If you're willing to settle for a basic line plot, this is pretty easy. Say you have the following data (points along a sine curve):

import Numeric as N
x = N.arange(17)*N.pi/8.
y = N.sin(x)

Then this will give you the x-y plot:

import vcs
v = vcs.init()
v.xvsy(x, y, 'default', 'default', name='Sine Curve')

The two 'default' arguments refer to the graphics method and template that are used. The keyword name gives the title of the plot.

Now the bad news: Even a slightly more complex line plot (say, one that includes axis titles) is a lot more work. In order to make one, we have to understand how to use graphics methods and templates, text objects, and coordinate systems on the canvas. I put these ideas together in my complex line plot example.

A side note: If you want to do an x-y plot of a section of a cdms data object, with a latitude or longitude dimension, make sure that you specify the data from the latitude/longitude dimension, and not the axis object. Ray Pierrehumbert provides more information on this in his Python Lectures for Climate Science.

Notes: This discussion applies to CDAT 3.3.

Return to the Tips and Examples index page.

Updated: December 3, 2003 by Johnny Lin <email address>. License.