Scripting > Plotting Basics

  
ViewportLayout Class

ViewportLayout objects hold information about the layout of an individual viewport within the plot dialog.  The use of ViewportLayout objects, in conjunction with PlotLayout objects, allows scripts to specify the same layout information accessible interactive via the “Configure Plot Layout” dialog.  A ViewportLayout object is obtained by calling one of the addViewport methods of a PlotLayout object.  ViewportLayout objects are only used to configure the plot layout.  Manipulation of axis labels, background colors, etc… is performed using Viewport objects as described in below. ViewportLayout methods are decribed below.

 

ViewportLayout Methods

Method

Returns

Description

addCurve(string axis, DataContainer curve)

None

Adds the specified curve to the specified axis of the ViewportLayout object.

getMajorGridXStyleString()

string

 

getMajorGridYStyleString()

string

 

getMinorGridXStyleString()

string

 

getMinorGridYStyleString()

string

 

getY1Data()

List

Returns a java.util.List of all curves that have been added to the Y1 axis of this object

getY2Data()

List

Returns a java.util.List of all curves that have been added to the Y2 axis of this object

hasY1Data()

0/1

Returns whether any curves have been added to the Y1 axis of this object

hasY2Data()

0/1

Returns whether any curves have been added to the Y2 axis of this object

setMajorGridXStyleString( string majorGridXStyle)

None

 

setMajorGridYStyleString( string majorGridYStyle)

None

 

setMinorGridXStyleString( string minorGridXStyle)

None

 

setMinorGridYStyleString( string minorGridYStyle)

None

 

setLinear(string axisName)

None

 

setLogarithmic(string axisName)

None

 

scaleAxisFromOpposite(  string axis)

None

 

 

The script in the example below reads precipitation, stage and flow data set from a DSS file, and configures a plot to display the precipitation on top in a viewport that occupies 30% of the available space and to display the stage and flow on separate axes of a bottom viewport that occupies the remaining 70% of available space.

 

Example : PlotLayout and ViewportLayout Objects

 

from hec.script import *                                     # for Plot class

from hec.heclib.dss import *                               # for DSS class

theFile = HecDss.open(“myFile.dss”)                   # open myFile.dss

precipPath = “/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"

stagePath = “/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"

flowPath = “/BASIN/LOC/FLOW/01NOV2002/1HOUR/OBS/"

precipData = theFile.get(precipPath)                    # read the precip

stageData = theFile.get(stagePath)                       # read the stage

flowData = theFile.get(flowPath)                        # read the flow

thePlot = Plot.newPlot()                                     # create a new Plot

layout = Plot.newPlotLayout()                            # create a new PlotLayout

topView = layout.addViewport(30)                      # get the top viewport

bottomView = layout.addViewport(70)                # get the bottom viewport

topView.addCurve(“Y1”, precipData)                  # add the precip to top

bottomView.addCurve(“Y1”, stageData)              # add the stage to bottom

bottomView.addCurve(“Y2”, flowData)               # add the flow to bottom

thePlot.configurePlotLayout(layout)                     # configure the plot

thePlot.showPlot()                                             # show the plot