Menu

#728 Nonlinear axes

Version 6
closed-accepted
None
5
2025-07-21
2016-04-01
No

This patch set adds support for nonlinear axes.
It uses the linked-axis mechanism of forward and reverse mappings introduced
in the "set link {axis} via f(x) inverse g(x)" command with the major
difference that it links a non-linear visible axis with a hidden axis that is
always linear.

One motivation is to eventually replace the current implementation of
logscale axes with something that is both more general and less expensive.
The effect of the existing command

  set logscale x

can be achieved by the new command

  set nonlinear x via log10(x) inverse 10**x

Demos here:

http://skuld.bmsc.washington.edu/~merritt/gnuplot/#nonlinear

A major advantage over the existing logscale implementation is that
coordinates are not transformed on input. The current logscale
code stores the log of the true coordinate, which then requires that
every single reference to that coordinate throughout the core gnuplot
code is mediated by macros AXIS_DO_LOG, AXIS_UNDO_LOG, AXIS_LOG_VALUE,
etc. Every time the coordinate is needed we check whether it was
stored as the log, unlog it if so, do whatever it was we wanted,
then reapply the log for comparison with other stored values.
By contrast the new nonlinear axis code simply stores the original
coordinate value. The nonlinear mapping (log in this case) is only
needed when we map it to a position on the output terminal canvas.

The log()/exp() transform is an example of a nonlinear axis mapping,
but the new code is happy to accept other transforms as well.
This defines a probability plot axis:

    set nonlinear x via norm(x) inverse invnorm(x)

See demo "probably_tux.dem".

Another non-obvious example is creation of a "broken axis" plot.
This is a recurring feature request. In this case the hidden linear
axis spanning the full range [min:max] is mapped onto a visible axis
that shows only the first part and the last part of the range (see demo).

Notes:

The "set nonlinear x" command itself is sufficient to create a
log-scaled x axis. For backwards compatibility with the existing
behaviour, there is a second command "set xtics log" that reuses the
old tic-placement code.

This version of the patch set only reserves space for hidden axes
shadowing the x and y axes. Extending it to handle the other visible
axes (x2 y2 z cb) should be trivial.

The pieces are already in place to construct log-scaled or broken
axis plots, as shown by the demos. Once any bugs are shaken out,
I envision wrapping these in simple commands for easier use.

For example, the command "set log" will continue to do what is has
always done but will use the new code rather than all those
LOG/DE_LOG macros underneath.

The manual definition of mappings and axis markings for a broken axis
can be automated by introducing some new command analogous to the way
"set multiplot layout ..." automates manipulation of the scale and
offset parameters.

1 Attachments

Discussion

  • Ethan Merritt

    Ethan Merritt - 2016-04-19

    Updated to handle the polar axis "r".
    WIth this update, all 2D axes are supported.

     
  • Ethan Merritt

    Ethan Merritt - 2016-04-23

    Nearly complete now. There is support for both 2D and 3D axes (x y x2 y2 z r cb).
    My plan is to add this infrastructure to CVS with a configuration option, then start working on higher-level features that use it. For example
    1) replace the existing "set log" operation with an implicit call to "set nonlinear"
    2) new set of of commands to make it easier to define and indicate a broken (discontinuous) axis
    3) export of nonlinear axes to external interactive terminals (canvas, svg)

     
  • Ethan Merritt

    Ethan Merritt - 2016-06-09
    • status: open --> pending-accepted
     
  • Ethan Merritt

    Ethan Merritt - 2016-06-13
    • status: pending-accepted --> closed-accepted
     

Log in to post a comment.