pytools.viz.matrix.MatrixMatplotStyle#
- class pytools.viz.matrix.MatrixMatplotStyle(*, ax=None, colors=None, font_family=None, colormap_normalize=None, colorbar_major_formatter=None, colorbar_minor_formatter=None, cell_format=None, nan_substitute=None)[source]#
Matplot style for matrices.
Numerical values of matrix cells are rendered as colors from a color map, with a color bar attached as a legend.
Matrix cells will be annotated with their values if a cell format is specified. Cell formats can be defined in different ways:
a new-style Python format string, e.g.,
{:.3g}
a function accepting the value to be formatted as its only positional argument, e.g.,
lambda x: f"{x * 100:.3g}%"
a
Formatter
instance
- Bases
- Metaclasses
- Parameters
ax (
Optional
[Axes
]) – optional axes object to draw on; create a new figure if not specifiedcolors (
Optional
[MatplotColorScheme
]) – the color scheme to be used by this drawing style (default:FacetLightColorScheme
)font_family (
Union
[str
,Iterable
[str
],None
]) – name of one or more fonts to use for all text, in descending order of preference; defaults to a monospaced font if undefined, or if none of the given fonts is availablecolormap_normalize (
Optional
[Normalize
]) – theNormalize
object that maps values to color indices; unless otherwise specified, use a plainNormalize
object with linear autoscalingcolorbar_major_formatter (
Optional
[Formatter
]) – major tick formatter for the color bar (optional)colorbar_minor_formatter (
Optional
[Formatter
]) – minor tick formatter for the color bar (optional; requires that also a major formatter is specified)cell_format (
Union
[str
,Formatter
,Callable
[Any
,str
],None
]) – format for annotating each matrix cell with its value if sufficient space is available (optional – do not annotate cells if omitted); if no colorbar major formatter is specified, use the cell format also as the colorbar major formatternan_substitute (
Optional
[float
]) – value to look up in the colormap for undefined matrix cells (default: 0.0)
Method summary
Apply this style's color scheme to the given
Axes
.Get the color(s) associated with the given value(s), based on the color map and normalization defined for this style.
Draw the matrix.
Finalize the matrix plot.
Get the name of the default style associated with this style class.
Get a mapping of names to default instances of this style class.
Initialize the matrix plot.
Attribute summary
The matplotlib
Axes
object on which to draw.Formatter for annotating each matrix cell with its value; if
None
, no cells are annotated.colorbar
The colorbar associated with this style; set when
ColorbarMatplotStyle.start_drawing()
is called.The color scheme used by this style.
The value to look up in the colormap for undefined matrix cells.
Definitions
- apply_color_scheme(ax)#
Apply this style’s color scheme to the given
Axes
.Style implementations can use this to apply the color scheme to sub-axes. Does not need to be applied to main axes, as this is already done in method
start_drawing()
.
- color_for_value(z)#
Get the color(s) associated with the given value(s), based on the color map and normalization defined for this style.
- draw_matrix(data, *, names, weights)[source]#
Draw the matrix.
- Parameters
data (
ndarray
[Any
,dtype
[Any
]]) – the values of the matrix cells, as a 2d arraynames (
tuple
[Optional
[ndarray
[Any
,dtype
[Any
]]],Optional
[ndarray
[Any
,dtype
[Any
]]]]) – the names of the rows and columnsweights (
tuple
[Optional
[ndarray
[Any
,dtype
[float64
]]],Optional
[ndarray
[Any
,dtype
[float64
]]]]) – the weights of the rows and columns
- Return type
- finalize_drawing(name_labels=None, weight_label=None, **kwargs)#
Finalize the matrix plot.
- classmethod get_default_style_name()#
Get the name of the default style associated with this style class.
The default style is obtained by instantiating this style class without parameters.
Common examples for default style names are matplot and text.
- Return type
- Returns
the name of the default style
- classmethod get_named_styles()#
Get a mapping of names to default instances of this style class.
- Return type
- Returns
a dictionary mapping of names to default instances of this style class
- get_renderer()#
Get the renderer used by this style’s
Axes
object (seeax
).- Return type
- Returns
the renderer
- start_drawing(*, title, name_labels=(None, None), weight_label=None, **kwargs)[source]#
Initialize the matrix plot.
- property ax: matplotlib.axes.Axes#
The matplotlib
Axes
object on which to draw.- Return type
- cell_formatter: Optional[matplotlib.ticker.Formatter] = None#
Formatter for annotating each matrix cell with its value; if
None
, no cells are annotated.
- property colors: pytools.viz.T_ColorScheme#
The color scheme used by this style.
- Return type
TypeVar
(T_ColorScheme
, bound=ColorScheme
)