IaGraph Examples: Overplotting and Multiple Windows

Settings and Data

Here we give examples of overplotting and going back and forth between windows. As a result, unlike the other example web pages, the order the examples are executed on this page is important, as are the window commands.

We first import the necessary packages for the examples:

>>> import MA
>>> import Numeric as N
>>> from IaGraph import *

We will create 4 sets of example data. The first two are 2-D data for contouring and the second two are x-y data for line/scatter plots.

The first dataset gives two "distorted" bulls-eyes centered at the top and bottom of the plot (this is the data used in the general contour plot examples:

>>> xd = N.arange(29) * 10.0
>>> yd = N.arange(21) * 10.0 - 100.0
>>> data = N.outerproduct( N.sin(yd*N.pi/360.) \
...                      , N.cos((xd-140.)*N.pi/360.))

The second dataset is a single bulls-eye centered around the (x,y) coordinates (70,30). The last logical line in creating this dataset sets all very small values exactly to zero. This is to prevent VCS from thinking that point is non-zero:

>>> xd1 = N.array([40, 50, 60, 70, 80, 90, 100])
>>> yd1 = N.array([-20, 0, 20, 40, 60, 80])
>>> data1 = N.outerproduct( N.sin(N.arange(6)/5.0*N.pi) \
...                       , N.sin(N.arange(7)/6.0*N.pi) )
>>> N.putmask( data1 \
...          , N.where(N.absolute(data1) < 1e-10, 1, 0), 0. )

The third dataset is a few sine wave cycles, with a few points set to "missing" (the missing value value is 1e+20):

x1 = N.arange(30) * 5.0
y1 = 50.0 * N.sin(x1/(4.0*N.pi))
y1[13:16] = 1e+20
y1 = MA.masked_values(y1, 1e+20)

The last dataset is just a series of (x,y) points, with no particular pattern:

x2 = N.array([10,  40, 60, 89, 123, 160, 192])
y2 = N.array([-82, 21, -3, 34,  54,  31, -23])

A link to the full source code for all the examples on this page is at the bottom of this page. For more information on any command cmd, type help(cmd).


Examples

Overplot a Scatter Plot Onto a Line Plot

In window 0 we plot the sine curves (without any plot symbols) and overplot only the plot symbols from the fourth dataset (as triangles). Note that there are more points in the (x2, y2) dataset than are plotted. This is because only points that fall within the (x,y) range defined by the (x1, y1) dataset are overplotted. The code>(x1, y1) dataset also has missing values.

>>> window(0)
>>> plot(x1, y1, psym=0)
>>> oplot(x2, y2, psym=5)

Overplot a Line Plot Onto a Contour Plot

We open a new window (number 1) and make a filled contour plot, with overlain contour lines, using a rainbow color map. Then we overplot the (x2, y2) data as a line plot, with the dash-dot linestyle.

>>> window(1)
>>> contour(data, xd, yd)
>>> oplot(x2, y2, linestyle=3)

Return To An Old Window And Add a Scatter Plot

Let's go back to the first plot (in window 0) and add on another scatter plot. This new scatter plot uses the (x2, y2) dataset, except the ordinates values are the negative of the original values. We plot these new values with plus symbols. Note that when you return to an old window the previous canvas is restored as you had left it; any subsequent changes (such as this addition of another overplot) will be stored onto this canvas.

>>> window(0)
>>> oplot(x2, -y2, psym=1)

Overplot A Line Contour Plot Onto a Default Contour Plot

In window 2 we plot a default contour plot, which is a filled contour plot with contour lines overlain, of the first dataset. On top of that we overplot a line contour plot of the second dataset, the single bulls-eye. Note that the default overplot contour plot is a line contour plot, which differs from the default plot type for contour.

>>> window(2)
>>> contour(data, xd, yd)
>>> ocontour(data1, xd1, yd1)

Overplot A Line Contour Plot Onto a Contour Plot, Illustrating the [xy]range Keywords

We open another new window (number 3) and plot the 2-D datasets, except in a reverse order as in the previous example. The second dataset is plotted as a filled contour plot. Note we use the [xy]range keywords to make the plot frame large enough to fit the range of the first dataset. We overplot the first dataset as a line contour plot.

>>> window(3)
>>> contour( data1, xd1, yd1, plottype='fill' \
...        , xrange=[0,280], yrange=[-100,100] )
>>> ocontour(data, xd, yd)

Overplot A Fill Contour Plot Onto a Line Contour Plot

Finally, we do the same overplot as in the previous plot, except we plot the fill contour on top of the line contour. This was only possible beginning with IaGraph v3.1.1 and CDAT 4.0.

>>> window(4)
>>> contour( data, xd, yd, plottype='line' \
...        , xrange=[0,280], yrange=[-100,100] )
>>> ocontour(data1, xd1, yd1, plottype='fill')


Full Code For Examples


Return to IaGraph Home Page.
Return to Johnny Lin's Python Library.

Updated: May 11, 2004 by Johnny Lin <email address>. License.