NCL Home>
Application examples>
Special plots ||
Data files for examples
Special Topics: Histograms
gsn_histogram is available from NCL
version 4.2.0.a017.
There is one other histogram resource that has not been demonstrated on
this page:
gsnHistogramBinWidth Instead of
indicating number of bins, you can specify a bin width. Depending on
how gsnHistogramSelectNiceIntervals is
set, you will either get bins of exactly this size, or approximately
this size.
histo_1.ncl:
Example of a default histogram. The default number of bins is
approximately 10. NCL will determine the number of bins that result
in nice intervals.
gsn_histogram is the plot interface
that creates histograms.
histo_2.ncl: Histograms can be
panelled.
tmXBLabelStride = 2, Plots every
other x-axis tickmark label.
gsnHistogramNumberOfBins, Selects the
number of bins. Note, in this example, you are still getting less than
the expected number of bins, because NCL is still automatically
selecting nice bin intervals.
histo_5.ncl: Explicitly select the
bin intervals.
gsnHistogramClassIntervals allows the
user to specify bin intervals. Note that with these different sized
bins, the size of the histogram column remains the same by default.
If there is data outside the range of the bins you have chosen, they
will not be counted. You can set gsnHistogramMinMaxBinsOn to get a bins that
include all values that are greater than and less than the max and min
bins you have selected. This resource only works when gsnHistogramClassIntervals or gsnHistogramBinIntervals is also selected.
histo_6.ncl: Compares two arrays.
Both arrays are combined into a single array with the first dimension
equal to 2.
gsnHistogramCompare, will create two
histograms, one behind the other.
histo_7.ncl: Demonstrates changing the
color of the bins.
gsFillColor controls the color
of the bins. If you set it equal to one color the entire histogram
will be that color. If you set it to an array of colors it will cycle
through that array and repeat if necessary.
gsFillIndex will change the fill
pattern. Default is 0 or solid fill. There are many fill patterns to
choose from. gsFillIndex will
change the fill pattern. Default is 0 or solid fill. There are many
fill
patterns to choose from.
histo_9.ncl: A highly specialized
plot that draws a histogram on top of a map.
histo_10.ncl: Demonstrates how to
overlay multiple histograms on top of each other so that more than two
histograms can be compared. If you only have two, see example 6.
First we set the color of the histograms to transparent using gsFillColor, and then color the bin
edges using gsEdgeColor. With
the various colors, you can distinguish the height of the various
bins. The color of the last overlay will be the one on top .
histo_13.ncl: The tickmarks on the
bottom axis of a histogram are labelled by setting
tmXBMode to "Explicit", and setting
tmXBValues and
tmXBLabels to internally calculated values. The
normal resources for trying to control precision and/or formatting
will not work as expected.
This example demonstrates a kludgy method for reformatting the
tickmark labels on the bottom axis, by using the "BinLocs" attribute
returned by gsn_histogram.