qewton.visualization.themes package¶
Module contents¶
Themes¶
Colors, fonts and colormaps of Qewton figures.
Theme(base.py): immutable dataclass with all visual settings: figure chrome (background, text, lines, grid), fonts, mark sizes, categorical palette, the colormap for each role, and node card colors and geometry for computation-graph plots. A renderer draws in its theme, e.g.PlotlyRenderer(theme=DARK_THEME).LIGHT_THEME(default,DEFAULT_THEME) andDARK_THEMEare predefined; custom themes override fields, e.g.Theme(font_size_title=16). Sizes are in pixels and colors CSS strings; a renderer converts them.plot_widthandplot_heightgive the box a plot area fits into. The presets use ink for data only: axis lines left and bottom (axis_box=False), no grid or zero line, legends and colorbars without a box (show_grid,show_zero_line,legend_box).cmaps(cmaps.py, alsoqewton.viz.cmaps): colormaps forColorScale(cmap=...):roles
cmaps.sequential,cmaps.diverging,cmaps.cyclic, resolved against the figure’s theme at draw time, andcmaps.categorical, the theme’s palette as one band per category;concrete colormaps such as
cmaps.meadow,cmaps.dusk,cmaps.redblue,cmaps.phaseand single-huecmaps.reds,cmaps.blues, …, the same in every theme;any other value (a colormap name of the renderer, e.g. Plotly’s
"Viridis"or Matplotlib’s"viridis", or a colorscale list) is passed to the renderer unchanged.
Without a cmap, a ColorScale uses the categorical role if it is categorical, else the sequential one.
Theme.resolve_cmap(cmap, steps=)performs this resolution, in equal bands withsteps.palette(palette.py): the raw color values - seven color families with four shades each, chrome tokens per theme, node card colors, the categorical order, and the colorscales built from them.
from qewton.visualization import ColorScale, DARK_THEME, Figure, HeatmapPlot, cmaps
from qewton.visualization.renderers import PlotlyRenderer
# diverging: redblue in the light theme, orangeviolet_paper in the dark one
scale = ColorScale(cmap=cmaps.diverging)
plot = HeatmapPlot(data, config, position=X, color=u, color_scale=scale)
Figure(plot, renderer=PlotlyRenderer(theme=DARK_THEME)).show()
See DECISIONS.md for design decisions.
Submodules¶
qewton.visualization.themes.base module¶
The Theme dataclass holding the visual settings of a Figure.
- class qewton.visualization.themes.base.Theme(background_color: str = '#ffffff', text_color: str = '#14181c', line_color: str = '#14181c', grid_color: str = 'rgba(20, 24, 28, 0.12)', font_family: str = 'Latin Modern Roman, CMU Serif, Georgia, serif', font_size_title: int = 16, font_size_axes: int = 14, font_size_labels: int = 12, plot_width: int = 400, plot_height: int = 320, show_grid: bool = False, show_zero_line: bool = False, show_legend: bool = True, legend_box: bool = False, show_axis_line: bool = True, axis_box: bool = False, marker_size: int = 6, line_width: float = 1.25, opacity_default: float = 0.8, surface_opacity: float = 0.9, wireframe_opacity: float = 0.3, geometry_color: str = '#ebe2d9', vector_color: str = '#14181c', primary_color_palette: list[str] = <factory>, sequential_cmap: QewtonColormap | str | list = cmaps.meadow, diverging_cmap: QewtonColormap | str | list = cmaps.redblue, cyclic_cmap: QewtonColormap | str | list = cmaps.phase, node_color_by_type: dict[str, dict[str, str]]=<factory>, node_color_default: str = '#b6a595', card_corner_radius: float = 0.12, card_port_inner_radius: float = 0.056, card_port_outer_radius: float = 0.096, card_port_ring_radius: float = 0.072, card_depth: float = 0.04, card_line_width: float = 1.0, card_title_font_size: int = 11, card_title_font_family: str = 'Arial, Helvetica, sans-serif', card_edge_formula_size: int = 8, graph_px_per_unit: float = 110.0)[source]¶
Bases:
objectColors, fonts and sizes applied to every plot of a Figure.
A Theme is immutable. Custom themes are created as
Theme(...)with the fields to override;LIGHT_THEMEandDARK_THEMEare the standard ones. All parameters are stored as fields of the same name.- Parameters:
background_color – Figure background color.
text_color – Figure text color.
line_color – Color of non-data lines: borders, edges, wireframes.
grid_color – Color of axis gridlines.
font_family – Font stack for all figure text (Latin Modern by default). For TeX-rendered math, wrap a title or label in
$...$.font_size_title – Font size of the figure title in pixels.
font_size_axes – Font size of axis, cell and colorbar titles in pixels.
font_size_labels – Font size of tick labels and legend entries in pixels.
plot_width – Width of the box a plot area fits into, in pixels.
plot_height – Height of the box a plot area fits into, in pixels.
show_grid – Whether axis gridlines are drawn.
show_zero_line – Whether a line is drawn at 0 on a 2D axis whose range holds it.
show_legend – Whether legends are shown.
legend_box – Whether a legend is framed.
show_axis_line – Whether axis lines with outward ticks are drawn.
axis_box – Whether the axis lines are mirrored to all four sides of the plot area, and colorbars are framed; without, the axis lines are left and bottom only.
marker_size – Default marker size of data marks.
line_width – Default line width of data marks.
opacity_default – Default opacity of data marks.
surface_opacity – Opacity of geometry surfaces.
wireframe_opacity – Opacity of geometry wireframes.
geometry_color – Color of a geometry surface with no data to color by.
vector_color – Color of uncolored arrow fields (MeshVectorPlot, QuiverPlot).
primary_color_palette – Categorical colors, assigned to plots by
color_index.sequential_cmap – The concrete colormap the role
sequentialresolves to: aQewtonColormapor a renderer-native colormap (a Plotly colorscale name or list), never a role. Also used for a ColorScale without a cmap.diverging_cmap – The concrete colormap the role
divergingresolves to (same kinds as sequential_cmap).cyclic_cmap – The concrete colormap the role
cyclicresolves to (same kinds as sequential_cmap).node_color_by_type –
{"fill": ..., "border": ...}color pair per node category of a computation-graph plot:"datanode"(data/input),"graphnode"(model/algorithm, also used for uncategorized nodes) and"constraint"(loss/residual).node_color_default – Fill color used if no category pair applies.
card_corner_radius – Corner radius of node cards, in graph-layout data units (as are the following card sizes).
card_port_inner_radius – Radius of the port dot.
card_port_outer_radius – Radius of the port notch cut into the card edge.
card_port_ring_radius – Radius of the ring around wired outputs and constraint ports.
card_depth – Offset of the 3D bevel.
card_line_width – Card outline width in points.
card_title_font_size – Font size of card titles in points.
card_title_font_family – Font stack of card titles.
card_edge_formula_size – Font size of port labels, in points.
graph_px_per_unit – Pixels per graph-layout data unit by which the labels of ports are kept clear of their notches.
See also
- background_color: str = '#ffffff'¶
- text_color: str = '#14181c'¶
- line_color: str = '#14181c'¶
- grid_color: str = 'rgba(20,24,28,0.12)'¶
- font_family: str = 'Latin Modern Roman, CMU Serif, Georgia, serif'¶
- font_size_title: int = 16¶
- font_size_axes: int = 14¶
- font_size_labels: int = 12¶
- plot_width: int = 400¶
- plot_height: int = 320¶
- show_grid: bool = False¶
- show_zero_line: bool = False¶
- show_legend: bool = True¶
- legend_box: bool = False¶
- show_axis_line: bool = True¶
- axis_box: bool = False¶
- marker_size: int = 6¶
- line_width: float = 1.25¶
- opacity_default: float = 0.8¶
- surface_opacity: float = 0.9¶
- wireframe_opacity: float = 0.3¶
- geometry_color: str = '#ebe2d9'¶
- vector_color: str = '#14181c'¶
- primary_color_palette: list[str]¶
- sequential_cmap: QewtonColormap | str | list = cmaps.meadow¶
- diverging_cmap: QewtonColormap | str | list = cmaps.redblue¶
- cyclic_cmap: QewtonColormap | str | list = cmaps.phase¶
- node_color_by_type: dict[str, dict[str, str]]¶
- node_color_default: str = '#b6a595'¶
- card_corner_radius: float = 0.12¶
- card_port_inner_radius: float = 0.056¶
- card_port_outer_radius: float = 0.096¶
- card_port_ring_radius: float = 0.072¶
- card_depth: float = 0.04¶
- card_line_width: float = 1.0¶
- card_title_font_size: int = 11¶
- card_title_font_family: str = 'Arial, Helvetica, sans-serif'¶
- card_edge_formula_size: int = 8¶
- graph_px_per_unit: float = 110.0¶
- classmethod default()[source]¶
Create the default light, paper-style theme (
LIGHT_THEME).- Returns:
A theme with all default field values.
- Return type:
- classmethod dark()[source]¶
Create the dark theme (
DARK_THEME).- Returns:
A theme with dark chrome and dark-background colormaps.
- Return type:
- resolve_cmap(cmap=None, steps: int | None = None)[source]¶
Resolve a ColorScale’s cmap to a renderer-ready colormap.
- Parameters:
cmap (Colormap | str | list | None) – None or a
ColormapRoleresolves to this theme’s field for that role (None means sequential;cmaps.categoricalmeans the palette). AQewtonColormapbecomes its colorscale list. Anything else, e.g. a renderer’s colormap name or colorscale list, is returned unchanged.steps – Number of equal bands, e.g. one per category: the palette’s first colors (cycling), or a colormap sampled at the band centers. None: the palette in one band per color, a colormap continuous.
- Returns:
- The renderer-native colormap:
[position, color] stops, two per band for bands.
- The renderer-native colormap:
- Return type:
str | list
- Raises:
ValueError – If this theme’s field for the requested role is itself a role.
qewton.visualization.themes.cmaps module¶
Qewton’s colormaps as typed objects.
Available as qewton.viz.cmaps. Two kinds can be passed as
ColorScale(cmap=...):
Roles - sequential, diverging, cyclic, categorical: the colormap of this kind that the current Theme uses; categorical is the Theme’s palette, one color per category in the order plots are colored. They are resolved at draw time against the Figure’s theme (
resolve_cmap()), so switching the theme switches every plot that uses a role.Concrete colormaps - meadow, dusk, redblue, orangeviolet_paper, phase, spectrum and the single-hue reds, oranges, yellows, greens, blues, violets, browns: one fixed colorscale from
palette, independent of the theme. Only these can be a Theme’s*_cmapfield.
A plain string or a colorscale list is not interpreted by Qewton; it is
passed through to the renderer as its own colormap (e.g. Plotly’s
"Viridis").
- class qewton.visualization.themes.cmaps.Colormap[source]¶
Bases:
objectBase class for Qewton’s colormap types.
Notes
Has no behavior of its own. Subclasses define what the colormap resolves to in
resolve_cmap(), which handlesColormapRoleandQewtonColormaponly.
- class qewton.visualization.themes.cmaps.ColormapRole(name: str)[source]¶
Bases:
ColormapA kind of colormap, resolved against the Theme at draw time.
- Parameters:
name –
"sequential","diverging"or"cyclic", resolving to the Theme field<name>_cmap, or"categorical", resolving to itsprimary_color_palette.
- name: str¶
- class qewton.visualization.themes.cmaps.QewtonColormap(name: str, colorscale: tuple[tuple[float, str], ...])[source]¶
Bases:
ColormapOne concrete, immutable colorscale.
- Parameters:
name – Name of the colormap.
colorscale –
(position, "#rrggbb")stops with positions from 0 to 1.
- name: str¶
- colorscale: tuple[tuple[float, str], ...]¶
- classmethod from_stops(name: str, stops) QewtonColormap[source]¶
Create a colormap from a list of stops.
- Parameters:
name – Name of the colormap.
stops (Iterable[tuple[float, str]]) –
(position, color)pairs, e.g.[position, "#rrggbb"]lists as produced inpalette.
- Returns:
The colormap with the stops converted to tuples.
qewton.visualization.themes.palette module¶
Qewton color palette as Plotly-native color values.
Seven color families with four shades each, from A (palest) to D (strongest/darkest):
red A=#fce3de B=#f7a38e C=#f38f7f D=#bc4b4f orange A=#fde7d7 B=#fbc299 C=#f9b381 D=#e76727 yellow A=#fdf0d0 B=#fee1a5 C=#fddb91 D=#eaa52b (data nodes) green A=#e2efe5 B=#aed6be C=#94c9ad D=#3e835a (loss nodes) blue A=#e3ecf3 B=#b7d2e6 C=#99bcdf D=#245691 (model nodes) violet A=#e3dfed B=#a09ec6 C=#8d89ba D=#53548a brown A=#ebe2d9 B=#b6a595 C=#a18e7f D=#826b59
Every colorscale is interpolated in OKLab space between fixed anchors
taken from these families, sampled at 64 stops, in Plotly’s format: a list
of [position, "#rrggbb"] pairs. Besides the families, the module
defines theme-dependent chrome colors (background, ink, border), the node
card colors and the categorical color order.
cmaps wraps the colorscales as typed
colormap objects; Theme uses
the remaining values.