NCL Home>
Application examples>
Plot techniques ||
Data files for examples
Panel Plots
gsn_panel
Note:
gsn_panel calls
draw and
frame automatically for
the user. You do not need to call these after you call
gsn_panel.
There are numerous examples of panel plots through this tutorial, but
we decided to create a separate page on the topic just to make it
easier to create panel plots.
panel_1.ncl: This is the simplest
panel plot. Three plots are draw and then placed on the page. In most
instances, the user will also want to add a common title or label
bar. Subsequent examples demonstrate these features.
gsn_panel is the plot interface that
creates panel plots.
gsnDraw and gsnFrame should be set to false when drawing the
individual plots so that they can be saved for the panel plot.
You do not, however, need to call these afterwards. gsn_panel calls them for you.
panel_2.ncl: Adds a common title to
the plot.
To add a title, it is necessary to create a set of resources that are
passed to only the panel template. It is best to give them a different
name than the resources used for the individual plots. (e.g.
resP = True)
txString is the resource that will
automatically allocate space for a title and apply the title to the
panel plot.
panel_3.ncl: Adds a common label bar
to the plot.
lbLabelBarOn = False, Turns off the
individual label bars, while gsnPanelLabelBar = True, adds a common label bar
at the bottom of the plot. lbLabelFontHeightF is used to decrease the
labels sizes of the common labelbar.
Remember to manually set the contour levels so that each plot has the
same interval. The common label bar is draw from the first plot, and
assumes all are the same.
panel_4.ncl: Adds some space at the
bottom of the plot for more text.
gsnPanelBottom = 0.05, Is the panel plot
resource that adds space at the bottom of the plot.
panel_5.ncl: Automatically adds text
strings to the panel plot. These strings can be anything you want, but
the text used here is most common.
gsnPanelFigureStrings = (/"a)","b)"/), is
the resource that will add a string to a corner in a panel plot.
The default position is the bottom right-hand corner. In this
example, we use amJust "TopLeft",
to move them to the upper left-hand corner.
Additionally, amOrthogonalPosF
and amParallelPosF will how close
the boxes are to the axis. Zero is the center of the line, and 0.5 is
flush with the right and -0.5 is flush with the left.
In NCL version 4.2.0.a28, you can use gsnPanelFigureStringsFontHeightF to adjust the
font heights of the figure strings. Values range between 0 and 1, with
the default being 0.01
In NCL version 4.2.0.a31, you can use gsnPanelFigureStringsPerimOn to turn off the box
around the FigureString, and
gsnPanelFigureStringsBackgroundFillColor to change the
background color.
panel_6.ncl: Demonstrates the
addition of white space to a panel plot. The first figure contains no
white space. You can see it is somewhat cramped. The second figure as
5% white space added in both x and y. It looks much nicer.
gsnPanelYWhiteSpacePercent = 5
gsnPanelXWhiteSpacePercent = 5, Adds the
white space to the panel plot.
panel_7.ncl: An example of a
compressed panel plot. In this case we remove the longitude labels and
tickmarks from the first two plots and keep only the one on the
bottom. Since the plot template judges the spacing of the panel plot
from the first plot, we need to add just a bit of space at the bottom
like we did in example 4 in order to see the long labels on the bottom
plot.
panel_8.ncl: Similar to example 7,
except that we really start turning the tickmarks and their associated
labels on and off.
panel_9.ncl: Create a panel plot
using viewport specifications. This is required if the plots are of
different shapes.
panel_10.ncl: There may be time
when it is necessary to panel plots next to each other that have
different sizes. If these plots can be attached, then the resulting
new plot can be paneled.
In this example, we attach a zonal average plot to a Hovmueller
diagram. The result is one plot that could then be paneled.
gsn_attach_plots is the plot
interface that will attach the a group plots along the y-axis
(default).
_________________________________
| | | | |
| plot1 | plot2 | plot3 | plot4 |
| | | | |
_________________________________
If you set
gsnAttachBorderOn to False,
then it will remove the interior borders and look like this:
_________________________________
| |
| plot1 plot2 plot3 plot4 |
| |
_________________________________
If you set
gsnAttachPlotsXAxis to True,
then the plot will be attached along the x-axis.
gsnAttachBorderOn gsnAttachBorderOn
= True (default) = False
_________ _________
| | | |
| plot1 | | plot1 |
| | | |
|-------| | |
| | | |
| plot2 | | plot2 |
| | | |
|-------| | |
| | | |
| plot3 | | plot3 |
| | | |
|-------| | |
| | | |
| plot4 | | plot4 |
| | | |
--------- ---------
Draw each plot separately, but then fine tune once you see them
attached, and "scrunched". In our example, we removed the minor
tickmarks and only plotted every other x-axis label.
HOW TO PANEL ATTACHED PLOTS:
- Ensure that each plot is given a unique variable name that is
never overwritten:
plot1 = gsn_csm_hov (wks, chi(:,{lonE:lonW}), hres)
xyplt1 = gsn_csm_xy(wks, x,y,xyres)
plot2 = gsn_csm_hov(wks, chi(:,{220:320}), hres)
xyplt2 = gsn_csm_xy(wks, x,y,xyres)
- The function gsn_attach_plots
returns a special id number (an integer), and not a plot (a graphical
object).
attachres1 = True
attachres1@gsnAttachPlotsXAxis = True ; attaches along x-axis
attachres2 = True
attachid1 =
gsn_attach_plots(plot1,xyplt1,attachres1,attachres2)
attachid2 =
gsn_attach_plots(plot2,xyplt2,attachres1,attachres2)
- The attached plot is now the first plot in the function call.
herefore, feed this into the panel procedure:
gsn_panel(wks,(/plot1,plot2/),(/2,1/),False)
- If you were so inclined the special id number could be used to
"unattach" an already attached plot by:
NhlRemoveAnnotation(plot1,attachid1)
plot1 would now only contain the original Hovmueller diagram.
panel_11.ncl: As of NCL version
4.2.0.a012,
gsn_panel has the option
of specifying how many plots should be placed on each row. To do this,
set
gsnPanelRowSpec = True.
The default layout is for the plots to be centered. You can change
this by setting gsnPanelCenter = False.
panel_12.ncl: Demonstrates putting two separate panel plots on one page, so that each can have its own unique label bar.
The important thing to remember here, is to create two separate plot
arrays to hold the individual plots for both panels. This is required
b/c the label bar is taken from the last plot drawn.
gsnPanelRight = 0.5, tells the plot to
only draw on the left 50% of the page, while gsnPanelLeft = 0.5, tells the plot to only draw
on the right 50% of the page.
panel_14.ncl: Demonstrates
combining a two-panel panel plot with two manually placed line
plots. This is required b/c
gsn_panel assumes all the plots are the same
size, and these plots are different enough to prevent their lining up
axis to axis. Thanks to Keith Lindsay for this example.
The trick here is to divide the page into two sections. The lower
section will just be for the contoured panel plot and its common label
bar. We can tell gsn_panel to only
draw its result in the lower half of the page by setting gsnPanelTop to 0.5.
Next, we make sure the width of the xy plots is the same as the
contour plots by setting vpWidthF to its
appropriate value. Finally, we exactly position each of the two xy
plots in ndc space so that their axis line up with the contour
plots. This is done by setting vpXF to
its appropriate value.
panel_15.ncl: Demonstrates using
gsn_panel twice in order to get
groups of plots with different label bars.
The trick here is the setting of gsnPanelBottom and gsnPanelTop for the two respective panel
plots. For the first panel, we move the bottom up to 0.4, which leaves
0.6 for the two panel plot. This means that each plot will be 0.3 in
size. For the third, single panel plot, we draw only up to where the
upper plot ended at 0.4. One more step is required, and that is to
move the bottom of the bottom panel up to 0.1 so that the total draw
area for this plot equals 0.3, just like we have for the upper
plots. If you do not set gsnPanelBottom
in this case, then the bottom plot has 0.4 space and will not be the
same size as the upper two plots.
panel_16.ncl: Demonstrates using
gsnPanelBottom and
gsnPanelTop to "squeeze" the panel plots to
approximately a column width for use in a publication. By setting
gsnPanelTop = .9 and
gsnPanelBottom = .2, the panel plots are drawn
on .7 of the page instead of the entire page. This is a very easy way
to shrink panel plots to a desired size.
panel_17.ncl: Demonstrates how to
panel four plots that have two separate labelbars and a main title.
The
gsnPanelTop and
gsnPanelBottom resources are used to make sure
the two sets of plots are drawn in an area of the same size so that
the plots are the same size, and then a small area is reserved for
drawing the main title using
gsn_text_ndc. The
generate_2d_array function is used to generate
dummy data for this example.
panel_18.ncl: Similar to
example 15, this
example demonstrates that the label bar need not explicitly have color in the middle.
This is shown in the bottom panel, as
cnFillColors
is manually being set, and the background color (0, = white for BlAqGrYeOrRe colormap)
is used to fill in all areas between -1 and 1.
panel_19.ncl: This example shows
how to use the
gsnPanelXF and
gsnPanelYF resources to adjust the X and/or Y
NDC positions
of the upper left corners of plots in a panel. The first frame shows
the paneled plots without adjustments, and the remaining two have both
X and Y adjustments.
These resources must be arrays of the same size as the number of plots
you have. Any individual plots that you don't want to adjust,
you can set a negative value and the default value will be used.
You can optionally set gsnPanelDebug
to True to have some debug information about the default X and Y
positions being used, so you know approximately how much to tweak
the values.
These resources will be added in version 4.3.0.
panel_21.ncl: This example shows
how to add a common title, and common x-axis and y-axis labels to a
panel plot using
gsn_text_ndc and
the
gsnPanelLeft,
gsnPanelRight resources.
This script was written by Jonathan Vigh, a PhD candidate student in
the Atmospheric Sciences department at Colorado State University.
panel_22.ncl: This example shows
how to add individual common titles to a panel plot that actually
contains two panelled plots (each 2 rows x 1 column).
You use the txString resource for the
title, and you also need to set the txPosXF resource to values between 0 and 1,
because otherwise both titles will be exactly centered on the page
(=0.5).