The plotlib submodule
Functional Analysis
Purpose
A Matplotlib wrapper that encapsulates figure/graph/widget creation into a composable object hierarchy, eliminating boilerplate and providing a consistent API for all plots in fluidsolve.
Class Hierarchy & Relationships
PlotFigure
├── PlotGraph (1..n, registered via addGraph)
│ ├── PlotCurve (1..n, addCurve)
│ ├── PlotLine (0..n, addVline / addHline)
│ ├── PlotAnnotation (0..n, addAnnotation)
│ ├── PlotAxis (0..4: x1, y1, x2, y2)
│ ├── PlotGrid (0..1)
│ └── PlotLegend (0..1)
├── PlotButton (0..n, widget panel, addButton)
└── PlotSlider (0..n, widget panel, addSlider)
All child objects hold a weakref back to their parent to avoid reference cycles.
Classes
Class |
Role |
|---|---|
|
Top-level container. Manages |
|
Wraps a single |
|
One data series: |
|
Static horizontal or vertical reference line ( |
|
Configures one of four axis positions ( |
|
Batch text annotations over lists of (x, y, label) triples. Supports alternating offsets ( |
|
Delegates to |
|
Delegates to |
|
Matplotlib |
|
Matplotlib |
Key Design Patterns
Two-phase construction: objects are configured first, then
show()is called lazily (once) byprepareShow(). A_prepareflag prevents double-building.Validated kwargs: all
__init__parameters go throughflsa.GetArgs/flsa.vFunvalidators (type checks, range checks, defaults, coercions).``extra`` dict escape hatch: every class accepts an
extra={}kwarg that is merged into the underlying matplotlib call, allowing full pass-through of any matplotlib option without needing to expose it explicitly.Update modes:
update()redraws data and re-applies axes/grid;updateData()updates data in-place only — faster for interactive refresh.Widget panel: buttons and sliders live in a second
plt.figure(separate from the graph figure), embedded side-by-side in the same Tk window. The widget panel is created when either buttons or sliders are registered.
Matplotlib wrapper utilities for engineering plots.
This module provides reusable plotting infrastructure used by fluidsolve, including figure/grid management, axis helpers, and optional interactive widgets (sliders/buttons) for parameter exploration.
Scope:
generic plotting primitives and containers,
consistent figure sizing/layout setup,
Tk-backed embedding and toolbar support,
helper integration points for higher-level domain plots.
Design intent:
centralize matplotlib boilerplate in one place,
keep plot creation consistent across examples and tools,
provide a stable base for domain modules such as
plotext.
Typical usage:
fig = PlotFigure(title='Q-H overview', nr=1, nc=1, toolbar=True)
graph = PlotGraph(fig, r=0, c=0)
curve = PlotCurve(graph, x=[0, 1, 2], y=[10, 8, 4])
fig.show()
By separating plotting infrastructure from hydraulic semantics, this module keeps UI/figure concerns maintainable and reusable.
Reference inspiration: https://medium.com/@basubinayak05/python-data-visualization-day-1-71334ff5044e
- class fluidsolve.plotlib.PlotFigure(**kwargs: int)[source]
Bases:
objectMatplotlib figure container.
- Parameters:
dpi (int, optional) – Screen resolution (dots per inch).
h (int, optional) – Figure height in pixels.
w (int, optional) – Figure width in pixels.
hw (int, optional) – Widget area height in pixels.
nr (int, optional) – Number of graph rows.
nc (int, optional) – Number of graph columns.
nrw (int, optional) – Number of widget rows.
ncw (int, optional) – Number of widget columns.
facecolor (str, optional) – Background color.
title (str, optional) – Figure title.
toolbar (bool, optional) – Show the navigation toolbar.
constrained_layout (bool, optional) – Use matplotlib constrained layout. Default True.
extra (dict, optional) – Extra kwargs passed to plt.figure.
- property h: int
Figure height in pixels.
- property w: int
Figure width in pixels.
- property hw: int
Widget area height in pixels.
- property nr: int
Number of graph rows.
- property nc: int
Number of graph columns.
- property nrw: int
Number of widget rows.
- property ncw: int
Number of widget columns.
- property figure: Any
Underlying matplotlib Figure object.
- property gridspec: Any
Underlying GridSpec object.
- property figure_widgets: Any
Matplotlib Figure used for widget controls.
- property gridspec_widgets: Any
GridSpec used for widget controls.
- property buttons: dict
List of registered PlotButton objects.
- property sliders: dict
List of registered PlotSlider objects.
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- addGraph(graph: PlotGraph) int[source]
Register a graph and return its index.
- Parameters:
graph (PlotGraph) – Graph to register.
- Returns:
Index of the registered graph.
- Return type:
int
- addButton(button: PlotButton) int[source]
Register a button and return its index.
- Parameters:
button (PlotButton) – Button to register.
- Returns:
Index of the registered button.
- Return type:
int
- addSlider(slider: PlotSlider) int[source]
Register a slider and return its index.
- Parameters:
slider (PlotSlider) – Slider to register.
- Returns:
Index of the registered slider.
- Return type:
int
- class fluidsolve.plotlib.PlotGraph(figure: PlotFigure, **kwargs: int)[source]
Bases:
objectMatplotlib axes container.
- Parameters:
figure (PlotFigure) – Parent figure.
r (int | str) – Row index or slice in the GridSpec.
c (int | str) – Column index or slice in the GridSpec.
polar (bool, optional) – Use polar projection.
title (str, optional) – Axes title.
facecolor (str, optional) – Axes background color.
edgecolor (str, optional) – Axes edge color.
extra (dict, optional) – Extra kwargs passed to add_subplot.
- __init__(figure: PlotFigure, **kwargs: int) None[source]
- property axes: Any
Underlying matplotlib Axes object.
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- addCurve(curve: PlotCurve) int[source]
Register a curve and return its index.
- Parameters:
curve (PlotCurve) – Curve to register.
- Returns:
Index of the registered curve.
- Return type:
int
- addVline(line: PlotLine) int[source]
Register a vertical line and return its index.
- Parameters:
line (PlotLine) – Line to register.
- Returns:
Index of the registered line.
- Return type:
int
- addHline(line: PlotLine) int[source]
Register a horizontal line and return its index.
- Parameters:
line (PlotLine) – Line to register.
- Returns:
Index of the registered line.
- Return type:
int
- addAnnotation(annotation: PlotAnnotation) int[source]
Register an annotation and return its index.
- Parameters:
annotation (PlotAnnotation) – Annotation to register.
- Returns:
Index of the registered annotation.
- Return type:
int
- class fluidsolve.plotlib.PlotCurve(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectA single data series on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
type (str, optional) – Plot type; one of
line,scatter, orbar.x (list, optional) – X data.
y (list, optional) – Y data.
label (str, optional) – Legend label.
color (str, optional) – Line or marker color.
alpha (float, optional) – Opacity.
linestyle (str, optional) – Line style.
marker (str, optional) – Marker style.
extra (dict, optional) – Extra kwargs passed to the plot call.
- property x: list
x data.
- Returns:
x data.
- Return type:
list
- property y: list
y data.
- Returns:
y data.
- Return type:
list
- property curve: Any
curve object.
- Returns:
curve object.
- Return type:
Any
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- class fluidsolve.plotlib.PlotLine(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectHorizontal or vertical reference line on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
typev (bool) – True for vertical, False for horizontal.
v (float, optional) – Position of the line.
x (float, optional) – Relative start position (0-1).
y (float, optional) – Relative end position (0-1).
label (str, optional) – Legend label.
color (str, optional) – Line color.
alpha (float, optional) – Opacity.
linestyle (str, optional) – Line style.
extra (dict, optional) – Extra kwargs for the line call.
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- class fluidsolve.plotlib.PlotAxis(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectConfigures axis properties on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
type (str) – Axis type:
x1,y1,x2, ory2. Set by PlotGraph.share (object, optional) – Axis to share scale with.
vmin (int | float, optional) – Minimum axis value.
vmax (int | float, optional) – Maximum axis value.
vstep (int | float, optional) – Major tick step.
vmstep (int | float, optional) – Minor tick step.
axison (bool, optional) – Whether the axis is visible.
axiscolor (str, optional) – Axis line color.
labeltxt (str, optional) – Axis label text.
labelcolor (str, optional) – Axis label color.
labelfmt (str, optional) – Tick label format string.
extra (dict, optional) – Extra kwargs for axis configuration.
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- property axes: Any
Return the matplotlib Axes configured for this axis object.
- class fluidsolve.plotlib.PlotAnnotation(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectConfigures annotation properties on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
label (list, optional) – Annotation text labels.
x (list, optional) – X positions.
y (list, optional) – Y positions.
textcoords (str, optional) – Coordinate system for text offset.
xoffset (int | float, optional) – Horizontal text offset.
yoffset (int | float, optional) – Vertical text offset.
xtoggle (int | float, optional) – Alternating horizontal shift.
ytoggle (int | float, optional) – Alternating vertical shift.
fontsize (int, optional) – Text font size.
color (str, optional) – Text color.
bbox (dict, optional) – Bounding box properties.
arrow (dict, optional) – Arrow properties.
halignment (str, optional) – Horizontal alignment.
valignment (str, optional) – Vertical alignment.
extra (dict, optional) – Extra kwargs passed to annotate.
- property x: list
x data.
- Returns:
x data.
- Return type:
list
- property y: list
y data.
- Returns:
y data.
- Return type:
list
- property label: list
label data.
- Returns:
label data.
- Return type:
list
- setExtra(key: str, **values: Any) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- class fluidsolve.plotlib.PlotGrid(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectConfigures grid properties on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
axis (str, optional) – Which axis to apply the grid to:
x,y, orboth.color (str, optional) – Grid line color.
linestyle (str, optional) – Grid line style.
linewidth (int | float, optional) – Grid line width.
extra (dict, optional) – Extra kwargs passed to ax.grid.
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- class fluidsolve.plotlib.PlotLegend(graph: PlotGraph, **kwargs: int)[source]
Bases:
objectConfigures a legend on a PlotGraph.
- Parameters:
graph (PlotGraph) – Parent graph.
loc (str, optional) – Legend location (e.g.
best,upper right). Defaultbest.title (str, optional) – Legend title.
fontsize (int, optional) – Font size for legend entries.
title_fontsize (int, optional) – Font size for the legend title.
frameon (bool, optional) – Whether to draw the legend frame. Default True.
ncols (int, optional) – Number of columns. Default 1.
extra (dict, optional) – Extra kwargs passed to ax.legend.
- class fluidsolve.plotlib.PlotButton(fig: PlotFigure, **kwargs: int)[source]
Bases:
objectMatplotlib button widget.
- Parameters:
fig (PlotFigure) – Parent figure.
r (int | str) – Row index or slice in the widget GridSpec.
c (int | str) – Column index or slice in the widget GridSpec.
label (str, optional) – Button label text.
color (str, optional) – Button background color.
hovercolor (str, optional) – Button hover color.
fun (Callable) – Callback executed when the button is clicked.
extra (dict, optional) – Extra kwargs passed to the Button constructor.
- __init__(fig: PlotFigure, **kwargs: int) None[source]
- property widget: Any
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.
- class fluidsolve.plotlib.PlotSlider(fig: PlotFigure, **kwargs: int)[source]
Bases:
objectMatplotlib slider widget.
- Parameters:
fig (PlotFigure) – Parent figure.
r (int | str) – Row index or slice in the widget GridSpec.
c (int | str) – Column index or slice in the widget GridSpec.
label (str, optional) – Slider label text.
color (str, optional) – Slider color.
hovercolor (str, optional) – Slider hover color.
vmin (int | float) – Minimum slider value.
vmax (int | float) – Maximum slider value.
vstep (int | float, optional) – Slider step size.
vinit (int | float, optional) – Initial slider value.
fun (Callable) – Callback executed on slider change.
extra (dict, optional) – Extra kwargs passed to the Slider constructor.
- __init__(fig: PlotFigure, **kwargs: int) None[source]
- property widget: Any
- setExtra(key: str, **kwargs: int) None[source]
- Updates extra configuration values for a given key.
This method merges the provided keyword arguments into the existing dictionary stored under self._extra[key].
- Parameters:
key (str) – The key under which to store extra configuration values. Must be one of the allowed values.
**values (Any) – Arbitrary keyword arguments to merge into the extra configuration dictionary.