-
-
Notifications
You must be signed in to change notification settings - Fork 659
Description
This ticket implements new show options flip_x
and flip_y
for flipping the direction of axes in 2d graphics. This was previously suggested in #18463 comment:12.
Currently, something similar can be achieved by setting limits such that xmin > xmax
.
sage: plot(x).show(xmin=1, xmax=-1)
This works because it is supported by matplotlib, but it is fragile and does not seem to be documented anywhere in Sage, apart from some implementation comments in sage.plot.graphics
. The implementation of matrix_plot
also relies on this, as by default matrices are plotted with the vertical axis directed downward. This leads to subtle issues like the following.
sage: p = matrix_plot(identity_matrix(5))
sage: p.get_minmax_data()
{ xmin:-0.5, ymin:4.5, ymax:-0.5, xmax:4.5 }
sage: p2 = p + point((2, 2), zorder=1)
sage: p2.get_minmax_data()
{ xmin:-0.5, ymin:1.0, ymax:3.0, xmax:4.5 }
Here, the bounding box of p
has ymin > ymax
which does not get taken into account when adding plots. As a consequence, p2
does not show the entire matrix.
As a solution that is hopefully more robust, this ticket adds flip_x
/flip_y
options that are documented to the user. For example:
sage: plot(x, -1, 1, flip_x=True)
From now on, the minmax data should always have min <= max
, though for backward compatibility this is not enforced. When summing plots, flipped axes take precedence.
In matrix_plot
, the now redundant option origin='upper'
/origin='lower'
is deprecated and replaced by flip_y
.
Moreover, this ticket fixes an issue with plots of sparse matrices for which the data was incorrectly flipped:
sage: matrix_plot(identity_matrix(5, sparse=True), origin='lower')
See #18463 and #18612 for some related discussions.
Component: graphics
Keywords: matplotlib
Author: Markus Wageringel
Branch/Commit: 6553689
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/27891