MESQUAL Plotly Util figure_utils¶
figure_utils
¶
Utility functions for styling and modifying Plotly figures.
This module provides convenience functions for common figure modifications such as title formatting, annotation styling, axis configuration, and adding interactive controls to Plotly figures.
set_title
¶
set_title(fig: Figure, title: str)
Set a centered, bold title for the figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object to modify. |
required |
title
|
str
|
Title text to display. |
required |
Example:
>>> set_title(fig, "Sales Performance Dashboard")
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
11 12 13 14 15 16 17 18 19 20 21 22 23 | |
remove_category_in_annotations
¶
remove_category_in_annotations(fig: Figure)
Remove category names from subplot annotations, keeping only values.
Modifies annotation text to show only the part after '=' for cleaner subplot labels (e.g., 'sex=Male' becomes 'Male').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object with annotations to modify. |
required |
Example:
>>> remove_category_in_annotations(fig) # 'smoker=Yes' → 'Yes'
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
make_annotations_bold
¶
make_annotations_bold(fig: Figure)
Apply bold formatting to all figure annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object with annotations to modify. |
required |
Example:
>>> make_annotations_bold(fig) # Makes all subplot labels bold
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
42 43 44 45 46 47 48 49 50 51 52 | |
unmatch_xaxes
¶
unmatch_xaxes(fig: Figure)
Remove x-axis matching across subplots.
Allows each subplot to have independent x-axis ranges and scaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object to modify. |
required |
Example:
>>> unmatch_xaxes(fig) # Each subplot can have different x-ranges
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
unmatch_yaxes
¶
unmatch_yaxes(fig: Figure)
Remove y-axis matching across subplots.
Allows each subplot to have independent y-axis ranges and scaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object to modify. |
required |
Example:
>>> unmatch_yaxes(fig) # Each subplot can have different y-ranges
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 | |
reverse_legend_traceorder
¶
reverse_legend_traceorder(fig: Figure)
Reverse the order of legend entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object to modify. |
required |
Example:
>>> reverse_legend_traceorder(fig) # Last trace appears first in legend
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
85 86 87 88 89 90 91 92 93 94 95 | |
add_datetime_rangeslider
¶
add_datetime_rangeslider(fig: Figure)
Add an interactive datetime range slider and selector to the figure.
Adds a range slider below the plot and time period selector buttons for easy navigation of time series data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Plotly figure object to modify. |
required |
Returns:
| Type | Description |
|---|---|
|
Modified figure object with range controls. |
Example:
>>> fig = add_datetime_rangeslider(fig)
>>> fig.show() # Now includes 1d, 1w, 1m, 6m, YTD, 1y buttons
Source code in submodules/mesqual/mesqual/utils/plotly_utils/figure_utils.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |