1D Plotting Autoplot

From ComputingForScientists

Jump to: navigation, search

Contents

  1. GUI
  2. Scripting
    1. Plotting array elements
    2. Annotation
    3. Line Color
    4. Marker Style
    5. Line Style
    6. Style Combinations
    7. Multiple lines
      1. Method 1
      2. Method 2
    8. Axis Numbering
    9. Multiple Plots on One Canvas
    10. Setting Canvas Size
    11. Multiple Windows
    12. Setting Window Position and Size
    13. Saving State
  3. Problems
    1. Scalar Time Series Plots I
    2. Scalar Time Series Plots II

1. GUI

2. Scripting

To test the following scripts, start the development version of Autoplot, select Expert Mode in the upper-right, and then select Options->Enable Feature->Script Panel. You should now see a tab labeled script above the plot window; select and drag this to the right so that it separates from the plot window.

Copy and paste scripts from this page into the script panel and press Execute to run them.

2.1. Plotting array elements

In Autoplot, line plots are created using the plot function.

reset() # Clear the plot window
# Create an array to plot
A =  [1.0,4.0,16.0,32.0]
plot(A)

Image:Line Plots1 Autoplot.png

The plot(A) command caused a plot of the values of A to be shown with the values in A shown on the y-axis. The x-axis values were assumed to be [1,2,3,4]. The above commands are equivalent to

reset() # Clear the plot window
A = [1.0,4.0,16.0,32.0] 
x = [1,2,3,4] 
plot(x,A)
# Files will be written to home directory
writeToPng('file.png') 
writeToPdf('file.pdf')

Write files to a specific directory that already exists (Linux/OS-X):

writeToPng('/home/username/autoplot/file.png')
writeToPdf('/home/username/autoplot/file.pdf')

Write files to a specific directory that already exists (Windows):

writeToPng('C:\Users\username\file.png')
writeToPdf('C:\Users\username\file.pdf')

Image:Line Plots2 Autoplot.png

To change the x-axis values, modify the first array that is passed to the plot function.

reset() # Clear the plot window
A = [1.0,4.0,16.0,32.0] 
x = [10,20,30,40]   # x-values will be 10,20,30,40
plot(x,A)

Image:Line Plots3 Autoplot.png

2.2. Annotation

To add a grid, set the option drawGrid to True. To add a axis labels and a title, use xtitle, ytitle, and title keywords and the plot command.

A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
reset()
dom.options.drawGrid=True
plot(x,A,xtitle='Time [seconds]',ytitle='Height [meters]',title='Experiment 1 results')

Image:Line Plots4b Autoplot.png

2.3. Line Color

A style argument may be specified when calling the plot function. This set of commands will create a red line.

reset()
A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
plot(x,A,color='red')

Image:Line Plots5 Autoplot.png

Other colors may be used by specifying a set of r,g,b values. This set of commands will create a maroon line.

reset()
A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
plot(x,A,color='0.5,0,0' )

Image:Line Plots6 Autoplot.png

Other colors may be used by specifying a set of r,g,b values. This set of commands will create a maroon line.

reset()
A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
plot(x,A,color='#800000' )

Image:Line Plots6 Autoplot.png

2.4. Marker Style

Marker styles are one of stars,circles,diamonds,exes,boxes

A = [1.0,4.0,16.0,64.0]
x = [1,2,3,4]
reset()
plot(x,A,symbol='stars')

Image:Line Plots7 Autoplot.png

Marker colors may be specified using the same syntax as the line color

A = [1.0,4.0,16.0,64.0]
x = [1,2,3,4]
reset()
plot(x,A,symbol='stars',color='red')

Image:Line Plots8 Autoplot.png

Marker size may be specified using symbolSize followed by a comma and a number.

A = [1.0,4.0,16.0,64.0];
x = [1,2,3,4];
plot(x,A,symbol='stars',color='red',symbolSize=10)

Image:Line Plots9 Autoplot.png

2.5. Line Style

By default, the points are connected with lines. Options include SOLID,DOTFINE,DASHFINE

A = [1.0,4.0,16.0,64.0]
x = [1,2,3,4]
plot(x,A,lineStyle='DOTFINE')

Image:Line Plots10 Autoplot.png

Line width may be specified using lineWidth followed by a comma and an integer.

A = [1.0,4.0,16.0,64.0]
x = [1,2,3,4];
plot(x,A,lineWidth=5)

Image:Line Plots11 Autoplot.png

2.6. Style Combinations

Multiple styles may be specified. For example, to create a red solid line, use the two keywords together:

A = [1.0,4.0,16.0,32.0];
x = [1,2,3,4];
plot(x,A,color='red',lineStyle='solid');

Image:Line Plots12 Autoplot.png

Multiple styles may be specified. For example, to create a red solid line, use the two keywords together:

A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
plot(x,A,color='red',lineStyle='solid')

Image:Line Plots12 Autoplot.png

or

To create a red solid line with stars at the connecting points, use r*-

A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]
plot(x,A,lineWidth=3,symbolSize=10,symbol='stars')

Image:Line Plots14 Autoplot.png

2.7. Multiple lines

2.7.1. Method 1

If you entered the commands

A = [1.0,4.0,16.0,32.0]
B = [1.1,4.4,16.9,32.9]
setLayoutOverplot(2)
plot(0,A,color='red')
plot(1,B,color='blue')

To create a legend, use legendLabel:

A = [1.0,4.0,16.0,32.0]
B = [1.1,4.4,16.9,32.9]
setLayoutOverplot(2)
plot(0,A,color='red',legendLabel='Red')
plot(1,B,color='blue',legendLabel='Blue')

Image:Line Plots15 Autoplot.png

2.7.2. Method 2

TODO: See if this could be done with bundle.

If instead of calling plot with an array, you call it with a matrix, each column will be plotted as a line.

M = [1.0,1.1;4.0,4.4;16.0,16.9;32.0,32.9]
plot(M)
legend('Column 1','Column 2');

Image:Line Plots16 Autoplot.png

2.8. Axis Numbering

In this example, note that by default MATLAB chose to label the values in 0.5 increments. This is not a good default - all of the x-values are integers. The following example shows how to modify the values that are labeled.

A = [1.0,4.0,16.0,32.0]
x = [1,2,3,4]

plot(x,A,xtitle='Time [seconds]',
   ytitle='Height [meters]', 
   title='Experiment 1 results' )

da= dom.plots[0].xaxis.controller.dasAxis
# Set tick Values (minor, major)
da.setTickV([1.5,2.5,3.5],[1,2,3,4])
dom.options.setDrawMinorGrid(True)

To modify the x-position labels, use YTick instead of XTick.

2.9. Multiple Plots on One Canvas

When you call Autoplot with higher plot numbers to add plots, it will automatically stack the plots to make a series. You can control this more with the setLayout command:

setLayout(2,3)  # make two rows of three plots.
plot([1,2,3], index=0) # Plot in first row, first column
plot([1,2,3], index=1) # Plot in first row, second column
plot([1,2,3], index=5) # Plot in last row, last column

2.10. Setting Canvas Size

The canvas is the inner area where the plot appears.

setCanvasSize(640,480)

2.11. Multiple Windows

To make a second window, you can make a new application and send data to it:

window1 = getWindow() # Get reference to default window for later
plot( [4,3,2,1], color='blue' )
setCanvasSize(640,480)
setWindowLocation(1000,200)

window2 = newWindow('Better Data',300,300,600,600) # Window title will be "Better Data"
setWindow(window2) # Plot to new window
setCanvasSize(640,480)
setWindowLocation(1000,200)
plot( [1,2,3,2], color='red' )

setWindow(window1) # Plots now will go to default window
plot( [1,2,3,2], color='green' )

2.12. Setting Window Position and Size

Placing a single window

window1 = getWindow() # Get reference to default window for later 
plot( [4,3,2,1], color='blue' )

window1.setLocation(100,100) # Place upper-left at 100, 100 on screen
window1.setCanvasSize(640,480) # Make window size 640x480

Placing multiple windows

window1 = getWindow() # Get reference to default window for later
plot( [4,3,2,1], color='blue' )
window1.setLocation(0,0)
window1.setCanvasSize(640,480) # Make window size 640x480

window2 = newWindow('Better Data') # Window title will be "Better Data"
window2.setLocation(641,0)
window2.setCanvasSize(640,480) # Make window size 640x480
setWindow(window2) # Plot to new window
plot( [1,2,3,2], color='red' )

2.13. Saving State

Save vap file

3. Problems

3.1. Scalar Time Series Plots I

Create a the plot shown below. Plot must have a grid, labels, x symbols of size 20, and a green line of width 3.

Turn in your program and a print-out of the plot (you can print the program with ???? and the plot from within Autoplot using File-Print.)

Image:lineplot1 Autoplot.png

3.2. Scalar Time Series Plots II

The following program computes population for two different scenarios.

  • An initial population of 100 and a growth rate of 1%/yr.
  • An initial population of 1000 and a decay rate of 10%/yr.
Pa= zeros(40)
Pa[0] = 100.
for i in range(1,40):
    Pa[i] = Pa[i-1] + 0.05*Pa[i-1]

Pb= zeros(40)
Pb[0] = 1000.
for i in range(1,40):
    Pb[i] = Pb[i-1] - 0.10*Pb[i-1]

setLayoutOverplot( 2 )
plotx( 0, Pa, color='red' )
plotx( 1, Pb, color='blue' )

Plot both population scenarios and draw a vertical line at the year in which the populations are nearest each other.

The plot should contain a legend and axis labels on the plot.

Personal tools