This is a hash to store information about the axes (ticks, range, grid, etc) with some helper methods. The hash is further split into three smaller hashes: xaxis, yaxis, and styles.
Hash of data for the horizontal axis.
Hash of data for the vertical axis.
Hash of data for options for the general axis.
The axes object should be accessed through a Plots object using $plot->axes. The axes object is used to configure and retrieve information about the axes, as in the following examples.
Each axis and styles can be configured individually, such as:
$plot->axes->xaxis(min => -10, max => 10, tick_delta => 4);
$plot->axes->yaxis(min => 0, max => 100, tick_delta => 20);
$plot->axes->style(aria_label => 'Graph of function y = f(x).', show_grid => 0);
This can be combined using the set method by prepending either x or y in front of each key of the axes to configure (note keys that do not start with x or y sent to $plot->axes->style):
$plot->axes->set(
xmin => -10,
xmax => 10,
xtick_delta => 4,
ymin => 0,
ymax => 100,
ytick_delta => 20,
aria_label => 'Graph of function y = f(x).',
show_grid => 0,
);
The same methods also get the value of a single option, such as:
$xmin = $plot->axes->xaxis('min');
$ytick_delta = $plot->axes->yaxis('tick_delta');
$show_grid = $plot->axes->style('show_grid');
The methods without any inputs return a reference to the full hash, such as:
$xaxis = $plot->axes->xaxis;
$styles = $plot->axes->style;
It is also possible to get multiple options for both axes using the get method, which returns a reference to a hash of requested keys, such as:
$bounds = $plot->axes->get('xmin', 'xmax', 'ymin', 'ymax');
# The following is equivalent to $plot->axes->grid
$grid = $plot->axes->get('xmajor', 'xminor', 'xtick_delta', 'ymajor', 'yminor', 'ytick_delta');
It is also possible to get the bounds as an array in the order xmin, ymin, xmax, ymax using the $plot->axes->bounds method.
Each axis (the xaxis and yaxis) has the following configuration options:
The minimum value the axis shows. Default is -5.
The maximum value the axis shows. Default is 5.
This is the number of major tick marks to include on the axis. This number is used to compute the tick_delta as the difference between the max and min values and the number of ticks. Note that this is only used if tick_delta is zero and tick_distance is undefined. Default: 5.
This is the distance between each major tick mark, starting from the origin. If this is set to 0 and tick_distance is not 0, then this distance is computed to be the product of the tick_distance and the tick_scale, and if this is set to 0 and tick_distance is undefined then this is computed to be the difference between the max and min divided by the tick_num. Default: 0
This can be set to 1 to show the labels for the major ticks, 0 to not show the labels for the major ticks, or to a reference to a hash whose keys are tick positions, and whose values are tick labels to be shown at those positions. Default: 1
The following is an example of passing a reference to a hash for this option.
tick_labels => { 5 => '\(a\)' }
In this case if there is a major tick at 5, then the label that will be shown there is 'a' and the label will be rendered via MathJax. Note that if there is not a major tick at 5, then the label will be unused. At any other major tick that is shown, the position will be shown for the label and will be formatted according to the tick_label_format option.
This option is most useful in combination with the tick_positions option below. With that option the precise list of major ticks to be shown can be specified, and the labels for those ticks specified with this option. For example,
tick_positions => [2, 4],
tick_labels => { 2 => 'a', 4 => 'b' },
would place a tick at 2 labeled 'a', and a tick at 4 labeled 'b'. No other ticks would be shown on the axis.
Note that if the hash reference value is used, the tick_label_format does not apply. You are responsible for formatting the labels as you would like them to appear. If you want the labels rendered via MathJax, then wrap the labels in \( and \).
This can be one of "decimal", "fraction", "multiple", or "scinot". If this is "decimal", then tick labels will be displayed in decimal format. If this is "fraction", then tick labels will be displayed as (improper) fractions. If this is "mixed", then tick labels will be displayed as mixed numbers. If this is "scinot", then tick labels will be displayed in scientific notation. Default: "decimal"
The number of decimal places to round tick labels to when the tick_label_format is "decimal" or "scinot". Default: 2
This is the unscaled distance between each major tick mark starting from the origin when the axis is scaled by the tick_scale factor. If this is 0, then this will be computed to be the tick_delta divided by the tick_scale. Default: 0
This is used in combination with the tick_distance above to calculate the tick_delta. Default: 1
This is appended to major tick labels. Default: ''
Set this to a reference to an array of values to be used for the positions of ticks that will be shown on the axis. In this case the tick_delta, tick_distance, and tick_scale options will not be used to generate tick positions. If this is set to 0 (or is not an array reference), then the tick positions will be computed using the values of the tick_delta, tick_distance, and tick_scale options. Default: 0
This can be either 1 (show) or 0 (don't show) the tick lines. If ticks are not shown then tick labels won't be shown either. Default: 1
The axis label. Defaults are \(x\) and \(y\).
Show (1) or don't show (0) grid lines at the tick marks. Default is 1.
This sets the number of minor ticks (and minor grid lines if minor_grids is 1) per major tick. If this is set to 0, no minor ticks are shown. Default: 3
If this is 1, then grid lines are shown at minor ticks, and if this is 0, then grid lines are not shown at minor ticks. Default: 1
This sets if the axis is shown (1) or not (0) on the plot. Default is 1.
This sets the location of the axes relative to the graph. The possible options for each axis are:
xaxis => 'top', 'middle', 'bottom'
yaxis => 'left', 'center', 'right'
This places the axis at the appropriate edge of the graph. If 'center' or 'middle' are used, the axes appear on the inside of the graph at the appropriate axis position. Default 'middle' or 'center'.
The position in terms of the appropriate variable to draw the axis if the location is set to 'middle' or 'center'. Default is 0.
Configures if arrows should be drawn in both directions (1) or only in the positive direction (0) at the axis ends. In other words, this is a choice between the convention that arrows are meant to indicate that the axis lines continue forever, or the convention that arrows are meant to indicate the positive direction of the axis only. Default: 0
A hash reference of options to be passed to the JSXGraph axis object.
A hash reference of options to be passed to the JSXGraph grid object. Note that the grid is implemented as an axis with ticks the extend to infinity. So the options are really JSXGraph axis options.
The following styles configure aspects about the axes.
If this style is set, then the height of the graph will be computed using this aspect_ratio for the size of the image unless explicitly set. Default: ''
The ARIA label in JSX graph output. Default is 'Graph'.
The ARIA description in JSX graph output. This will be set to the images alt tag. Default is 'Generated graph'.
Either draw (1) or don't draw (0) the grid lines for the axis. Default is 1.
The color of the grid lines. Default is 'gray'.
The alpha value to use to draw the grid lines in Tikz. This is a number from 0 (fully transparent) to 100 (fully solid). Default is 40.
Configures if the Tikz axis should be drawn on top of the graph (1) or below the graph (0). Useful when filling a region that covers an axis, if the axis are on top they will still be visible after the fill, otherwise the fill will cover the axis. Default: 0
Note that this setting is not honored for the JSXGraph image type.
This is not the best way of ensuring that axis elements are not covered by a fill. If this is used, then not only is the fill region placed behind the axis and the grid, but all graphed elements are behind the axis and the grid which is usually not desirable. A better way is to use the "axis background" layer to only place the fill on the "axis background" layer, and leave everything else on top of the axis.
If this is 1, then tick labels will be displayed using MathJax. If this is 0, then ticks will be displayed as basic text. This only applies to the JSXGraph output type. Default: 1
Either allow (1) or don't allow (0) the user to pan and zoom the view port of the JSXGraph. Best used when plotting functions with the continue style. Note that if this option is 0, then the image can be clicked on to open a dialog showing a magnified version of the graph that can be zoomed in or out. Default: 0
A hash reference of options to be passed to the JSXGraph board object.
Additional options to be passed to the pgfplots axis definition. This should be a single string. For example, to make longer and thicker x axis ticks use
tikz_options => 'x tick style={line width=2pt},major tick length=0.6cm'