qewton.visualization.plots package¶
Module contents¶
Plots¶
Plot classes describe what is drawn: they bind references into their input to channels and evaluate to renderer-neutral Results, one per drawn copy. They never draw; a renderer’s artists draw the Results (see the visualization README).
Plot interface (base.py)¶
Plot is the base of every family. A Figure uses only this interface:
evaluate(), train_scales(axes), dim (number of positions; 0 for a
plot that lays out its own axes), controls, selectors,
channels_of(selector), color_scales (with a colorbar of the figure),
active_color_scales, scales (all to reset before training),
n_copies, scaled_channels, point_encoding, margin (beside the
drawn ranges; 0 for a plot ending at its domain), axis_title(channel),
axis_ticks(channel), color_title and color_ticks(scale) (of a
scale in every state).
Families¶
DataPlot(data/): data plus itsDataConfiguration. A type declareschannels,requiredchannels,resultsper domain (structure and topological dimension), the numbers of positionsdims, whether positions must come from the domain, and whether colors are mapped through a ColorScale; it implementsbuild(positions, color, features, visible), leaving out the points the mask hides.supports(domain, n_positions)answers from these declarations. Types:HeatmapPlot,SurfacePlot,LinePlot,ScatterPlot,BarPlot,VectorPlot,ImagePlot.TablePlot(table/): a table of named columns (a dict or a DataFrame); text and boolean columns are categorical. Channels take column names or Selectors of them; controls reference a column and draw the rows of one of its values; log columns are drawn by their log10 with ticks labeled by values. Types:TableScatter,TableHeatMap,ParallelCoordinatesPlot.GeometryPlot(geometry/): a geometry without data: points, curves, surfaces with edges, volumes by their boundary.GraphPlot(graph/): a computation graph as a node-link diagram, laid out byGraphLayout.
Results (result.py)¶
Result |
Drawn as |
Produced by |
|---|---|---|
|
colored cells of a rectilinear grid |
|
|
triangles, flat in 2D or a surface in 3D |
|
|
segments through points |
|
|
a marker per point |
|
|
a bar per point |
|
|
an arrow per point |
|
|
colors on a uniform grid |
|
|
a line per row through one axis per column |
|
|
node cards, ports, edges, clusters |
|
Every Result carries its legend entry, the index of its categorical
color, its color scale and title, and its opacity; legend_entry tells
whether a legend tells it apart (a label and one color of the theme).
color_channel.py holds the color scales of a color binding, shared by
data and table plots.
See DECISIONS.md for design decisions.
Subpackages¶
- qewton.visualization.plots.data package
- Module contents
- Submodules
- qewton.visualization.plots.data.bar module
- qewton.visualization.plots.data.base module
drawable_geometry()grid_values()controlled_axes()split_products()Bindingvisible_cells()n_components()DataPlotDataPlot.channelsDataPlot.requiredDataPlot.resultsDataPlot.dimsDataPlot.domain_positionsDataPlot.color_mappedDataPlot.domainDataPlot.result_classDataPlot.n_positionsDataPlot.bindingsDataPlot.color_scaleDataPlot.opacityDataPlot.channelsDataPlot.requiredDataPlot.resultsDataPlot.dimsDataPlot.domain_positionsDataPlot.color_mappedDataPlot.result_type()DataPlot.draws()DataPlot.supports()DataPlot.n_copiesDataPlot.n_positionsDataPlot.dimDataPlot.selectorsDataPlot.color_scaleDataPlot.color_scalesDataPlot.active_color_scalesDataPlot.bindingsDataPlot.scaled_channelsDataPlot.color_titleDataPlot.channels_of()DataPlot.axis_title()DataPlot.train_scales()DataPlot.evaluate()DataPlot.build()DataPlot.domain_columnsDataPlot.feature_values()
- qewton.visualization.plots.data.heatmap module
- qewton.visualization.plots.data.image module
- qewton.visualization.plots.data.line module
- qewton.visualization.plots.data.scatter module
- qewton.visualization.plots.data.surface module
- qewton.visualization.plots.data.vector module
- qewton.visualization.plots.geometry package
- qewton.visualization.plots.graph package
- qewton.visualization.plots.table package
- Module contents
- Submodules
- qewton.visualization.plots.table.base module
TableColumntable_columns()TablePlotTablePlot.columnsTablePlot.n_rowsTablePlot.log_columnsTablePlot.color_scaleTablePlot.current()TablePlot.drawn_values()TablePlot.column_ticks()TablePlot.positionsTablePlot.selectorsTablePlot.n_copiesTablePlot.color_scaleTablePlot.color_scalesTablePlot.active_color_scalesTablePlot.color_titleTablePlot.color_ticks()TablePlot.channels_of()TablePlot.axis_title()TablePlot.axis_ticks()TablePlot.train_scales()TablePlot.evaluate()TablePlot.color_values()TablePlot.build()
- qewton.visualization.plots.table.heatmap module
- qewton.visualization.plots.table.parallel_coordinates module
- qewton.visualization.plots.table.scatter module
Submodules¶
qewton.visualization.plots.base module¶
Base class Plot shared by every plot family.
- class qewton.visualization.plots.base.PointEncoding(*values)[source]¶
Bases:
EnumHow a plot shows values at the points of its domain. Two plots of one encoding on one domain hide each other; plots of different ones read well together, e.g. arrows over a heatmap.
- COLOR¶
By color, e.g. a heatmap, a surface, colored points of a domain or a filled geometry.
- ARROW¶
By arrows.
- COLOR = 1¶
- ARROW = 2¶
- class qewton.visualization.plots.base.Plot(title: str | None = None, label: str | None = None, controls: tuple[ControlAxis, ...] | list[ControlAxis] = ())[source]¶
Bases:
objectAnything drawn into an Overlay.
A plot evaluates, in the current states of its controls, to one Result per drawn copy (
evaluate()); the number of copies does not change with the states.- Parameters:
title – Heading of the plot’s cell.
label – Legend entry; None derives it from the plotted quantity.
controls – Control axes reducing dimensions of the plot’s input.
- point_encoding¶
How the plot shows values at the points of its domain; None if it shows them by position (e.g. a line graph or points in value space) or not at all. An Overlay draws plots encoding by color first. A class attribute, or a property where it depends on the plot.
- Type:
PointEncoding or None
- title¶
Heading of the plot’s cell.
- Type:
str or None
- label¶
The explicit legend entry.
- Type:
str or None
- controls¶
The control axes.
- Type:
list of ControlAxis
- color_scales¶
The color scales the Figure draws colorbars of, trained over all states.
- Type:
list of ColorScale
- active_color_scales¶
Those of color_scales shown in the current states (e.g. of the chosen Selector candidate).
- Type:
list of ColorScale
- scales¶
Every scale of the plot besides the position axes, e.g. its color scales (also those without a colorbar of the Figure) and a VectorScale; the Figure resets them before training.
- Type:
list of Scale
- color_index¶
Index of the first categorical color of the plot; set by the Figure so plots and their copies get distinct colors.
- Type:
int
- margin¶
Fraction of the span of the position axes added on both sides of their drawn range, so no mark is clipped; 0 for plots ending at their domain (e.g. a heatmap). A class attribute, or a property where it depends on the plot.
- Type:
float
- dim¶
Number of position components drawn: 2 or 3, or 0 for a plot that lays out its own axes (e.g. parallel coordinates).
- Type:
int
- n_copies¶
Number of Results
evaluate()returns.- Type:
int
- scaled_channels¶
Position channels drawn to one scale, e.g. the coordinates of a geometry, so it is not distorted; empty if none.
- Type:
tuple of str
- color_title¶
Name of what is bound to the color channel in the current states; None if nothing named is.
- Type:
str or None
Notes
Subclasses implement dim and
evaluate(), and may override selectors, color_scales, active_color_scales, scales, margin, n_copies, scaled_channels, color_title,color_ticks(),axis_title(),axis_ticks(),channels_of()andtrain_scales().- point_encoding: PointEncoding | None = None¶
- margin: float = 0.04¶
- property dim: int¶
- property color_scales: list[ColorScale]¶
- property active_color_scales: list[ColorScale]¶
- property n_copies: int¶
- property scaled_channels: tuple[str, ...]¶
- property color_title: str | None¶
- color_ticks(scale: ColorScale) tuple[list[float], list[str]] | None[source]¶
The ticks the plot gives the colorbar of one of its scales, in its transformed values, in every state (also while another scale of the plot is shown), e.g. the categories of a categorical color.
- Parameters:
scale – One of color_scales.
- Returns:
- Positions and labels; None for the scale’s own
ticks.
- Return type:
tuple or None
- axis_title(channel: str) str | None[source]¶
The title the plot gives a position axis.
- Parameters:
channel –
"x","y"or"z".- Returns:
- The name of what is bound to channel; None if
nothing named is.
- Return type:
str or None
- channels_of(selector: Selector) tuple[str, ...][source]¶
The channels a Selector of the plot fills.
- Parameters:
selector – One of selectors.
- Returns:
E.g.
("color",).- Return type:
tuple of str
- axis_ticks(channel: str) tuple[list[float], list[str]] | None[source]¶
The ticks the plot gives a position axis in the current states, e.g. the categories of a categorical column.
- Parameters:
channel –
"x","y"or"z".- Returns:
- Tick positions and their labels; None for
automatic ticks.
- Return type:
tuple or None
qewton.visualization.plots.color_channel module¶
The color scales of a color channel, shared by every plot family.
- qewton.visualization.plots.color_channel.candidate_scales(color, color_scale: ~qewton.visualization.scales.ColorScale | list[~qewton.visualization.scales.ColorScale] | None, new_scale: ~collections.abc.Callable[[object], ~qewton.visualization.scales.ColorScale] = <function <lambda>>) list[ColorScale][source]¶
One ColorScale per candidate of a color binding.
- Parameters:
color – The color reference, a Selector of references, or None.
color_scale – One ColorScale shared by every candidate, a list with one per candidate, or None for a new one per candidate.
new_scale – Makes the new scale of a candidate.
- Returns:
- One per candidate; empty without a color
binding.
- Return type:
list of ColorScale
- Raises:
ValueError – If color_scale is a list that does not give one scale per candidate.
- qewton.visualization.plots.color_channel.unique(scales: list[ColorScale]) list[ColorScale][source]¶
Each scale once, in order.
- Parameters:
scales – Scales, possibly repeated.
- Returns:
The distinct instances.
- Return type:
list of ColorScale
qewton.visualization.plots.result module¶
Renderer-neutral results returned by Plot.evaluate().
A Result is one state of one drawn primitive, including how it is drawn;
a renderer draws it with the artist for its class. The layout classes
(NodeLayout and the like) are parts of a
GraphLayoutResult.
- class qewton.visualization.plots.result.Result(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0)[source]¶
Bases:
objectOne state of one drawn primitive.
Positions have one column per position channel (x, y, z); values are the values of the color channel, one per element.
- Parameters:
label – Legend entry, or None for no entry.
color_index – Index of the categorical color of every element (one per drawn copy of the figure) if no color channel is bound; the renderer’s theme gives the color.
color_scale – Maps values to colors if a color channel is bound, else None.
color_title – Title of the colorbar.
opacity – Opacity of every element.
- legend_entry¶
Whether a legend tells it apart: it has a label and one color of the theme, not colors of its values (their colorbar tells those apart) or of its data (an image).
- Type:
bool
- label: str | None = None¶
- color_index: int = 0¶
- color_scale: ColorScale | None = None¶
- color_title: str | None = None¶
- opacity: float = 1.0¶
- property legend_entry: bool¶
- class qewton.visualization.plots.result.HeatmapResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, x: ndarray, y: ndarray, values: ndarray)[source]¶
Bases:
ResultValues on a rectilinear 2D grid, drawn as colored cells.
- Parameters:
x – Coordinates along x, shape
(nx,).y – Coordinates along y, shape
(ny,).values – Shape
(ny, nx).
- x: ndarray¶
- y: ndarray¶
- values: ndarray¶
- class qewton.visualization.plots.result.SurfaceResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, positions: ndarray, cells: ndarray, values: ndarray | None = None, show_edges: bool = False)[source]¶
Bases:
ResultFilled triangles, flat in 2D or a surface in 3D.
- Parameters:
positions – Shape
(n_points, dim).cells – Triangles as point indices, shape
(n_cells, 3).values – One value per point, or None for a uniform color.
show_edges – Whether the cell edges are drawn.
- positions: ndarray¶
- cells: ndarray¶
- values: ndarray | None = None¶
- show_edges: bool = False¶
- class qewton.visualization.plots.result.LineResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, positions: ndarray, segments: ndarray, values: ndarray | None = None, width: float | None = None, dash: str | None = None)[source]¶
Bases:
ResultA line through points, colored along its length if values is set.
- Parameters:
positions – Shape
(n_points, dim).segments – Point index pairs to join, shape
(n_segments, 2).values – One value per point, or None for a uniform color.
width – Line width, or None for the theme’s.
dash – Dash pattern, e.g.
"dash", or None for a solid line.
- positions: ndarray¶
- segments: ndarray¶
- values: ndarray | None = None¶
- width: float | None = None¶
- dash: str | None = None¶
- class qewton.visualization.plots.result.MarkerResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, positions: ndarray, values: ndarray | None = None, size: float | None = None, symbol: str | None = None)[source]¶
Bases:
ResultA marker per point.
- Parameters:
positions – Shape
(n_points, dim).values – One value per point, or None for a uniform color.
size – Marker size, or None for the theme’s.
symbol – Marker symbol, or None for the default.
- positions: ndarray¶
- values: ndarray | None = None¶
- size: float | None = None¶
- symbol: str | None = None¶
- class qewton.visualization.plots.result.BarResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, positions: ndarray, values: ndarray | None = None)[source]¶
Bases:
ResultA bar per point, from 0 to its height.
- Parameters:
positions – Shape
(n_points, 2): the position along x and the height.values – One value per bar, or None for a uniform color.
- positions: ndarray¶
- values: ndarray | None = None¶
- class qewton.visualization.plots.result.ImageResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, x: ndarray, y: ndarray, colors: ndarray)[source]¶
Bases:
ResultColors on a rectilinear 2D grid with uniform spacing.
- Parameters:
x – Coordinates along x, shape
(nx,).y – Coordinates along y, shape
(ny,).colors – RGB or RGBA components in [0, 1], shape
(ny, nx, 3)or(ny, nx, 4).
- x: ndarray¶
- y: ndarray¶
- colors: ndarray¶
- property legend_entry: bool¶
- class qewton.visualization.plots.result.ArrowResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, positions: ndarray, vectors: ndarray, values: ndarray | None = None)[source]¶
Bases:
ResultAn arrow per point.
- Parameters:
positions – Tails of the arrows, shape
(n_points, dim).vectors – The arrows in data units, shape
(n_points, dim).values – One value per arrow, or None for a uniform color.
- positions: ndarray¶
- vectors: ndarray¶
- values: ndarray | None = None¶
- class qewton.visualization.plots.result.ParallelDimension(title: str, values: ndarray, range: tuple[float, float], ticks: tuple[list[float], list[str]] | None = None)[source]¶
Bases:
objectOne axis of a parallel coordinates plot.
- Parameters:
title – Axis title.
values – One value per drawn row, in drawn values (e.g. log10 of a log column, codes of a categorical one).
range – Range of the axis, in drawn values.
ticks – Tick positions and labels, or None for automatic ticks.
- title: str¶
- values: ndarray¶
- range: tuple[float, float]¶
- ticks: tuple[list[float], list[str]] | None = None¶
- class qewton.visualization.plots.result.ParallelCoordinatesResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, dimensions: list[ParallelDimension], values: ndarray | None = None)[source]¶
Bases:
ResultA line per row through one vertical axis per column.
- Parameters:
dimensions – The axes, in order.
values – One value per row, or None for a uniform color.
- dimensions: list[ParallelDimension]¶
- values: ndarray | None = None¶
- class qewton.visualization.plots.result.NodeCategory(*values)[source]¶
Bases:
EnumWhat a node of a computation graph is, for its colors; the value names its colors in the theme (
Theme.node_color_by_type).- DATA¶
A data source, e.g. a data loader or sampler.
- MODEL¶
A model, algorithm or any other node.
- CONSTRAINT¶
A loss or residual.
- DATA = 'datanode'¶
- MODEL = 'graphnode'¶
- CONSTRAINT = 'constraint'¶
- class qewton.visualization.plots.result.PortLayout(name: str, x: float, y: float, is_input: bool = True, show_label: bool = True)[source]¶
Bases:
objectOne port’s anchor point in a graph layout.
A leaf node’s port sits on its node box’s edge; an expanded composite’s own port sits directly on its
ClusterBoxboundary. Input ports are on the left, output ports on the right.- Parameters:
name – Port name.
x – Anchor x position.
y – Anchor y position.
is_input – Whether this is an input port; tells the artist on which side the label is placed.
show_label – Whether the port name is drawn. False for ports of a leaf node with only one port; always True for a composite’s boundary ports.
- name: str¶
- x: float¶
- y: float¶
- is_input: bool = True¶
- show_label: bool = True¶
- class qewton.visualization.plots.result.NodeLayout(label: str, kind: str, category: NodeCategory, x: float, y: float, width: float, height: float, input_ports: list[PortLayout], output_ports: list[PortLayout], hover: str = '')[source]¶
Bases:
objectOne drawn node box in a graph layout.
Used for leaf nodes and collapsed composites; an expanded composite is drawn as a
ClusterBoxinstead.- Parameters:
label – Node title.
kind – Class name of the node, shown in hover text.
category – What the node is, for its colors.
x – Center x of the box.
y – Center y of the box.
width – Width of the box.
height – Height of the box.
input_ports – The node’s ports on its left edge.
output_ports – The node’s ports on its right edge.
hover – Extra hover text.
- label: str¶
- kind: str¶
- category: NodeCategory¶
- x: float¶
- y: float¶
- width: float¶
- height: float¶
- input_ports: list[PortLayout]¶
- output_ports: list[PortLayout]¶
- hover: str = ''¶
- class qewton.visualization.plots.result.ClusterBox(label: str, category: NodeCategory, x0: float, y0: float, x1: float, y1: float, input_ports: list[PortLayout], output_ports: list[PortLayout])[source]¶
Bases:
objectThe card drawn around an expanded composite node’s contents.
Sized to contain the inner nodes and edges, with the composite’s own ports on its left and right boundary and its title in a corner.
- Parameters:
label – Cluster title.
category – What the composite is, as for a collapsed
NodeLayout.x0 – X coordinate of the first corner of the rectangle.
y0 – Y coordinate of the first corner of the rectangle.
x1 – X coordinate of the opposite corner of the rectangle.
y1 – Y coordinate of the opposite corner of the rectangle.
input_ports – The composite’s own ports on the left boundary.
output_ports – The composite’s own ports on the right boundary.
- x¶
Center x of the rectangle.
- Type:
float
- y¶
Center y of the rectangle.
- Type:
float
- width¶
Width of the rectangle.
- Type:
float
- height¶
Height of the rectangle.
- Type:
float
- label: str¶
- category: NodeCategory¶
- x0: float¶
- y0: float¶
- x1: float¶
- y1: float¶
- input_ports: list[PortLayout]¶
- output_ports: list[PortLayout]¶
- property x: float¶
- property y: float¶
- property width: float¶
- property height: float¶
- class qewton.visualization.plots.result.EdgeLayout(points: list[tuple[float, float]], label: str = '')[source]¶
Bases:
objectOne drawn edge between two ports, as a polyline.
- Parameters:
points – Polyline points from the source port to the target port.
label – Edge label (the source port’s data configuration axes), or empty.
- points: list[tuple[float, float]]¶
- label: str = ''¶
- class qewton.visualization.plots.result.GraphLayoutResult(*, label: str | None = None, color_index: int = 0, color_scale: ColorScale | None = None, color_title: str | None = None, opacity: float = 1.0, nodes: list[NodeLayout], ports: list[PortLayout], edges: list[EdgeLayout], clusters: list[ClusterBox], show_port_names: bool = False, show_configs: bool = False)[source]¶
Bases:
ResultRenderer-agnostic layout of a graph, the result of a
GraphPlot.All entries are already positioned in one global frame, including the contents of expanded composites, so the lists are flat. Node colors come from
categoryvia the theme.- Parameters:
nodes – Every drawn node box.
ports – Every port, both those of leaf nodes and the boundary ports of expanded composites.
edges – Every drawn edge.
clusters – The outline of every expanded composite.
show_port_names – Whether the ports of multi-port nodes are named next to the node title.
show_configs – Whether every edge is labeled with the axes of its matched data configuration; otherwise they are shown on hover.
See also
- nodes: list[NodeLayout]¶
- ports: list[PortLayout]¶
- edges: list[EdgeLayout]¶
- clusters: list[ClusterBox]¶
- show_port_names: bool = False¶
- show_configs: bool = False¶