Plotting¶
morphui.uix.visualization.plotting
¶
MorphPlotWidget(*args, **kwargs)
¶
Bases: MorphIdentificationBehavior, MorphThemeBehavior, MorphSurfaceLayerBehavior, Widget
Kivy Widget to show a matplotlib figure in kivy. The figure is rendered internally in an AGG backend then the rgb data is obtained and blitted into a kivy texture.
This widget uses only the essential MorphUI behaviors for lightweight operation: - MorphIdentificationBehavior: For widget identification and identity-based styling - MorphThemeBehavior: For theme integration and color binding - MorphSurfaceLayerBehavior: For background color, borders, and radius styling
This focused approach provides theming and styling capabilities while avoiding unnecessary behaviors like interaction layers, content layers, or auto-sizing.
| ATTRIBUTE | DESCRIPTION |
|---|---|
figure |
The top level container for all the plot elements.
TYPE:
|
surface_color |
Background color for the plot. Defaults to white (1.0, 1.0, 1.0, 1.0). Can be customized for different themes or transparent overlays.
TYPE:
|
figure = ObjectProperty(None)
class-attribute
instance-attribute
¶
The matplotlib figure object as the top level container for all
the plot elements. If this property changes, a new FigureCanvas is
created, see method on_figure (callback).
figure_canvas = ObjectProperty(None)
class-attribute
instance-attribute
¶
Canvas to render the plots into. Is set in method on_figure
(callback).
texture = ObjectProperty(None)
class-attribute
instance-attribute
¶
Texture to blit the figure into.
rubberband_pos = VariableListProperty([0, 0], length=2)
class-attribute
instance-attribute
¶
Position of the rubberband when using the zoom tool.
This property stores the [x, y] coordinates of the top-left corner of the rubberband rectangle during zoom operations. The coordinates are in widget space.
:attr:rubberband_pos is a
:class:~kivy.properties.VariableListProperty and defaults to
[0, 0].
rubberband_size = VariableListProperty([0, 0], length=2)
class-attribute
instance-attribute
¶
Size of the rubberband when using the zoom tool.
This property stores the [width, height] dimensions of the rubberband rectangle during zoom operations. Values of 0 indicate no rubberband is currently displayed.
:attr:rubberband_size is a
:class:~kivy.properties.VariableListProperty and defaults to
[0, 0].
rubberband_corners = ListProperty([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
class-attribute
instance-attribute
¶
Corner points of the rubberband when using the zoom tool.
This property stores a flat list of [x, y] coordinates representing the corners of the rubberband rectangle in order: top-left, top-right, bottom-right, bottom-left, and back to top-left to close the path. Used for drawing the rubberband border as a line.
:attr:rubberband_corners is a
:class:~kivy.properties.ListProperty and defaults to
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0].
rubberband_threshold = dp(20)
class-attribute
instance-attribute
¶
Threshold at which it will switch between axis-wise zoom or rectangle zoom
rubberband_color = ColorProperty([0, 0, 0, 0.2])
class-attribute
instance-attribute
¶
Color of the rubberband area when using the zoom tool.
The color should be provided as a list of RGBA values between 0 and
1. Example: [0, 0, 0, 0.2] for semi-transparent black.
:attr:rubberband_color is a
:class:~kivy.properties.ColorProperty and defaults to
[0, 0, 0, 0.2].
rubberband_edge_color = ColorProperty([0, 0, 0, 0.6])
class-attribute
instance-attribute
¶
Color of the rubberband edges when using the zoom tool.
The color should be provided as a list of RGBA values between 0 and
1. Example: [0, 0, 0, 0.6] for semi-transparent black.
:attr:rubberband_edge_color is a
:class:~kivy.properties.ColorProperty and defaults to
[0, 0, 0, 0.6].
toolbar = ObjectProperty(None)
class-attribute
instance-attribute
¶
Toolbar widget to display the toolbar.
This property holds a reference to the toolbar widget associated with this plot widget. It is used to coordinate interactions between the plot and the toolbar.
is_pressed = False
class-attribute
instance-attribute
¶
Flag to distinguish whether the mouse is moved with the key pressed or not.
inaxes = None
class-attribute
instance-attribute
¶
Current axis on which the mouse is hovering, is automatically
set in on_mouse_pos callback
show_info = BooleanProperty(False)
class-attribute
instance-attribute
¶
Flag to show the info label
default_config = dict(normal_surface_color=(1.0, 1.0, 1.0, 1.0), size_hint=(None, None))
class-attribute
instance-attribute
¶
Default configuration for the plot widget.
rubberband_drawn
property
¶
True if a rubberband is drawn (read-only)
window_to_figure_canvas(x, y)
¶
Convert window coordinates to figure canvas coordinates.
This method transforms the given (x, y) coordinates from window space to figure canvas space.
touch_to_figure_canvas(touch)
¶
Convert touch coordinates to figure canvas coordinates.
This method transforms the given touch event's (x, y) coordinates from window space to figure canvas space.
figure_canvas_to_widget(x, y)
¶
Convert figure canvas coordinates to widget coordinates.
This method transforms the given (x, y) coordinates from figure canvas space to widget space.
on_touch_down(touch)
¶
Callback function, called on mouse button press or touch event.
on_touch_move(touch)
¶
Callback function, called on mouse movement event while mouse button pressed or touch.
on_touch_up(touch)
¶
Callback function, called on mouse button release or touch up event.
on_mouse_move(window, mouse_pos)
¶
Callback function, called on mouse movement event
on_figure(caller, figure)
¶
Callback function, called when figure attribute changes.
data_to_axes(points)
¶
Transform points from the data coordinate system to the axes coordinate system. Given points should be an array with shape (N, 2) or a single point as a tuple containing 2 floats
display_to_data(points)
¶
Transform points from the display coordinate system to the data coordinate system. Given points should be an array with shape (N, 2) or a single point as a tuple containing 2 floats.
data_to_display(points)
¶
Transform points from the data coordinate system to the display coordinate system. Given points should be an array with shape (N, 2) or a single point as a tuple containing 2 floats.
display_to_axes(points)
¶
Transform points from the display coordinate system to the data coordinate system. Given points should be an array with shape (N, 2) or a single point as a tuple containing 2 floats.
draw_rubberband(touch, x0, y0, x1, y1)
¶
Draw a rectangle rubberband to indicate zoom limits.
| PARAMETER | DESCRIPTION |
|---|---|
touch
|
Touch event
TYPE:
|
x0
|
x coordonnate init
TYPE:
|
x1
|
y coordonnate of move touch
TYPE:
|
y0
|
y coordonnate init
TYPE:
|
y1
|
x coordonnate of move touch
TYPE:
|
remove_rubberband()
¶
Remove rubberband if is drawn.
on_show_info(caller, show_info)
¶
Callback function, called when show_info attribute changes.
Clear toolbar label if show_info is False.
clear_toolbar_info()
¶
Clear text of toolbar label if available
adjust_toolbar_info_pos(pos, center_x=True)
¶
Adjust position of toolbar label if available
This method repositions the toolbar's info label to the given position. It is typically called during mouse movement events to keep the info label near the cursor.
| PARAMETER | DESCRIPTION |
|---|---|
pos
|
The position (x, y) to align the info label to.
TYPE:
|
center_x
|
Whether to center the label horizontally at the given x position. Defaults to True.
TYPE:
|
Notes
If the toolbar or info label is not available, the method exits without making any changes.