Skip to content

Commit

Permalink
src/sage/matrix/operation_table.py: Fix more modularization violation…
Browse files Browse the repository at this point in the history
…s, add/update docstrings
  • Loading branch information
mkoeppe committed Feb 17, 2023
1 parent 8cbdf85 commit d368b6e
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions src/sage/matrix/operation_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,45 +948,37 @@ def matrix_of_variables(self):
for i in range(self._n) for j in range(self._n)]
return MS(entries)

# documentation hack
# makes the cmap default argument look nice in the docs
# by copying the gist_rainbow object and overriding __repr__
gist_rainbow_copy=copy(gist_rainbow)
class ReprOverrideLinearSegmentedColormap(gist_rainbow_copy.__class__):
def __repr__(self):
return "gist_rainbow"
gist_rainbow_copy.__class__=ReprOverrideLinearSegmentedColormap


def color_table(self, element_names=True, cmap=gist_rainbow_copy, **options):
def color_table(self, element_names=True, cmap=None, **options):
r"""
Returns a graphic image as a square grid where entries are color coded.
Return a graphic image as a square grid where entries are color coded.
INPUT:
- ``element_names`` - (default : ``True``) Whether to display text with element names on the image
- ``cmap`` - (default : ``gist_rainbow``) colour map for plot, see matplotlib.cm
- ``cmap`` - (default: :obj:`matplotlib.cm.gist_rainbow`) color map for plot, see :mod:`matplotlib.cm`
- ``**options`` - passed on to matrix_plot call
- ``**options`` - passed on to :func:`~sage.plot.matrix_plot.matrix_plot`
EXAMPLES::
sage: from sage.matrix.operation_table import OperationTable
sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul)
sage: OTa.color_table()
sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # optional - sage.plot, sage.groups
sage: OTa.color_table() # optional - sage.plot, sage.groups
Graphics object consisting of 37 graphics primitives
.. PLOT::
from sage.matrix.operation_table import OperationTable
OTa = OperationTable(SymmetricGroup(3), operation=operator.mul)
sphinx_plot(OTa.color_table(), figsize=(3.0,3.0))
sphinx_plot(OTa.color_table(), figsize=(3.0, 3.0))
"""
from matplotlib.cm import gist_rainbow, Greys
from sage.plot.matrix_plot import matrix_plot
from sage.plot.text import text

if cmap is None:
from matplotlib.cm import gist_rainbow as cmap

# Base matrix plot object, without text
plot = matrix_plot(Matrix(self._table), cmap=cmap,
frame=False, **options)
Expand Down Expand Up @@ -1019,6 +1011,29 @@ def color_table(self, element_names=True, cmap=gist_rainbow_copy, **options):
return plot

def gray_table(self, **options):
r"""
Return a graphic image as a square grid where entries are displayed in grayscale.
INPUT:
- ``element_names`` - (default: ``True``) Whether to display text with element names on the image
- ``**options`` - passed on to :func:`~sage.plot.matrix_plot.matrix_plot`
EXAMPLES::
sage: from sage.matrix.operation_table import OperationTable
sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # optional - sage.plot, sage.groups
sage: OTa.gray_table() # optional - sage.plot, sage.groups
Graphics object consisting of 37 graphics primitives
.. PLOT::
from sage.matrix.operation_table import OperationTable
OTa = OperationTable(SymmetricGroup(3), operation=operator.mul)
sphinx_plot(OTa.gray_table(), figsize=(3.0, 3.0))
"""
from matplotlib.cm import Greys
return self.color_table(cmap=Greys, **options)

def _ascii_table(self):
Expand Down

0 comments on commit d368b6e

Please sign in to comment.