Generates a bar graph.


plotBar([myPlot, ]labels, height)
  • myPlot (struct) – Optional argument, a plotControl structure
  • labels (Nx1 numeric vector or Nx1 string array) – bar labels. If scalar 0, a sequence from 1 to rows(height) will be created.
  • height (NxK numeric vector) – bar heights. K overlapping or side-by-side sets of N bars will be graphed.


Basic example with string labels

// Create data and labels
labels = "January" $| "June";
temp = { 68, 105 };

// Draw bar graph
plotBar(labels, temp);

Basic example with numeric labels

You may also pass in a numeric vector for the X-axis labels. This example will produce the a graph which looks the same as the graph above, except for the X-axis labels.

// Create data and labels
labels = { 4, 5 };
temp = { 68, 105 };

// Draw bar graph
plotBar(labels, temp);

Customized horizontal bar plot


// Create 2x1 numeric vectors
seattle = { 47, 70 };
phoenix = { 68, 105 };

// Create 2x1 string labels
labels = "January" $| "June";

// Declare 'myPlot' to be a plotControl struct
// and fill with defaults settings for bar plots
struct plotControl myPlot;
myPlot = plotGetDefaults("bar");

// Create legend
leg_text = "Phoenix" $| "Seattle";
plotSetLegend(&myPlot, leg_text, "top left inside");

// Set legend border to zero pixels wide
plotSetLegendBorder(&myPlot, "gray", 0);

// Set Fill to two different fill patterns
// and 100% opacity
plotSetFill(&myPlot, 12|13, 1);

// Use HTML to create the degrees symbol
plotSetYLabel(&myPlot, "Temp °F");

// Concatenate temperature vectors
// into a 2x2 matrix
heights =  phoenix ~ seattle;

// Draw the graph
plotBar(myPlot, labels, heights);


To control the color and texture of the bars as well as whether they are stacked or side by side:

  • If you are passing a plotControl structure to plotBar(), you may use the function plotSetFill().
  • If you are not passing a plotControl structure, these properties are set in the Preferences. Select Tools > Preferences from the GAUSS main menu. Then choose Graphics from the left side of the preferences pane and select Bar from the list of graph Profiles.

See also

Functions plotBarH(), plotSetFill(), plotHist()