Skip to content

Make it possible to set custom tick positions and labels with the plots.pl macro.#1389

Open
drgrice1 wants to merge 1 commit intoopenwebwork:developfrom
drgrice1:plots-custom-ticks
Open

Make it possible to set custom tick positions and labels with the plots.pl macro.#1389
drgrice1 wants to merge 1 commit intoopenwebwork:developfrom
drgrice1:plots-custom-ticks

Conversation

@drgrice1
Copy link
Member

To set custom tick positions use the tick_positions axis option. Set that to a reference to an array containing the positions on the axis that ticks are desired. For example, tick_positions => [ 2, 5, 9 ] will place ticks at positions 2, 5, and 9 on the axis. Note that when this option is used the tick_delta, tick_scale, and tick_distance options are not used. So only the given tick positions will appear in the graph.

To set custom tick labels use the tick_labels option. Note that this is not a new option, but now it accepts a new type of value. Previously this was purely boolean (0 or 1), and it only determined if tick labels would be shown or not. Now it can take a value that is a reference to a hash. The keys of the hash are tick positions, and the values are the labels to be placed at those positons. Note that formatting of the label must be done by the auther, and the tick_label_format option is ignored for any label provided in this hash. If a major tick is not listed in the hash, then the position will be used for the label and it will be formatted according to the tick_label_format option.

This is intended to replace what is done in #1374 and is a more flexible approach than what is done there. In that pull request the capability for custom tick labels only is added, and it is extremely restrictive in what it can do. Only positive tick labels can be customized, and it requires that the problem author label all major ticks (there is no fallback and a tick is labeled "undefined" if one is missing).

Here is a rather rudimentary example of using this new feature:

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'plots.pl', 'PGcourse.pl');

$plot = Plot(
    xmin            => -2,
    xmax            => 12,
    xtick_distance  => 2,
    xminor          => 1,
    xtick_positions => [ 2, 4, 6 ],
    xtick_labels    => { 2 => '\(a\)', 6 => '\(b\)' },
    ymin            => -2,
    ymax            => 12,
    ytick_distance  => 2,
    yminor          => 1,
);

BEGIN_PGML
[@ $plot->image_type('Tikz'); @]*[!TikZ Image!]{$plot}

[@ $plot->image_type('JSXGraph'); @]*[!JSXGraph Image!]{$plot}
END_PGML

ENDDOCUMENT();

…ots.pl` macro.

To set custom tick positions use the `tick_positions` axis option.  Set
that to a reference to an array containing the positions on the axis
that ticks are desired.  For example, `tick_positions => [ 2, 5, 9 ]`
will place ticks at positions 2, 5, and 9 on the axis.  Note that when
this option is used the `tick_delta`, `tick_scale`, and `tick_distance`
options are not used. So only the given tick positions will appear in
the graph.

To set custom tick labels use the `tick_labels` option.  Note that this
is not a new option, but now it accepts a new type of value.  Previously
this was purely boolean (0 or 1), and it only determined if tick labels
would be shown or not.  Now it can take a value that is a reference to a
hash.  The keys of the hash are tick positions, and the values are the
labels to be placed at those positons. Note that formatting of the label
must be done by the auther, and the `tick_label_format` option is
ignored for any label provided in this hash. If a major tick is not
listed in the hash, then the position will be used for the label and it
will be formatted according to the `tick_label_format` option.

This is intended to replace what is done in openwebwork#1374 and is a more flexible
approach than what is done there.  In that pull request the capability
for custom tick labels only is added, and it is extremely restrictive in
what it can do.  Only positive tick labels can be customized, and it
requires that the problem author label all major ticks (there is no
fallback and a tick is labeled "undefined" if one is missing).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant