CustomFigure Class#
- class CustomFigure(*args, **kwargs)[source]#
Bases:
FigureCustom Figure class with extended update functionality.
Initialize the CustomFigure.
Parameters#
- argstuple
Positional arguments passed to go.Figure
- kwargsdict
Keyword arguments passed to go.Figure
- __init__(*args, **kwargs)[source]#
Initialize the CustomFigure.
Parameters#
- argstuple
Positional arguments passed to go.Figure
- kwargsdict
Keyword arguments passed to go.Figure
- update(title_text: str | None = None, title_y: float | None = None, height: int | None = None, width: int | None = None, xaxis_title_text: str | None = None, xaxis_showgrid: bool | None = None, xaxis_tickformat: str | None = None, xaxis_tickprefix: str | None = None, xaxis_ticksuffix: str | None = None, xaxis_dtick: float | None = None, xaxis_ticktext: List[str] | None = None, xaxis_tickvals: List[int | float] | None = None, xaxis_range: List[int | float] | None = None, xaxis_domain: List[float] | None = None, yaxis_title_text: str | None = None, yaxis_showgrid: bool | None = None, yaxis_tickformat: str | None = None, yaxis_tickprefix: str | None = None, yaxis_ticksuffix: str | None = None, yaxis_dtick: float | None = None, yaxis_ticktext: List[str] | None = None, yaxis_tickvals: List[int | float] | None = None, yaxis_range: List[int | float] | None = None, yaxis_domain: List[float] | None = None, legend_title_text: str | None = None, legend_position: Literal['top', 'right', 'bottom'] = None, showlegend: bool | None = None, legend_x: float | None = None, legend_y: float | None = None, legend_xanchor: Literal['auto', 'left', 'center', 'right'] = None, legend_yanchor: Literal['auto', 'top', 'middle', 'bottom'] = None, legend_orientation: Literal['v', 'h'] = None, legend_itemsizing: Literal['trace', 'constant'] = None, legend_tracegroupgap: float | None = None, textposition: str | None = None, texttemplate: str | None = None, textfont: Dict[str, int | str] | None = None, hovertemplate: str | None = None, hovermode: Literal['x', 'y', 'closest', 'x unified', False] = None, hoverlabel_align: str | None = None, opacity: float | None = None, bargap: float | None = None, barmode: Literal['group', 'stack', 'overlay'] | None = None, boxmode: Literal['group', 'stack', 'overlay'] | None = None, bargroupgap: float | None = None, margin: Dict[str, int] | None = None, annotations: List[Dict] | None = None, xgap: int | None = None, ygap: int | None = None, template: str | None = None, hoverlabel: Dict[str, int | str] | None = None, coloraxis: Dict | None = None, plot_bgcolor: str | None = None, **kwargs) CustomFigure[source]#
Update the figure with consistent styling settings while maintaining all existing functionality.
This method extends the standard Figure.update() method with additional convenient parameters for common styling tasks.
Parameters#
- title_textOptional[str]
Main chart title displayed at the top of the figure.
Example: title=”Sales Performance 2023”
- title_yOptional[float]
Y postion title
Example: title_y=0.97
- heightOptional[int]:
Figure height in pixels.
Example: height=600
- widthOptional[int]
Figure width in pixels.
Example: width=800
- xaxis_title_textOptional[str]
Label for the x-axis.
Example: xaxis_title_text=”Date”
- xaxis_showgridOptional[bool]
Whether to show grid lines on the x-axis.
Example: xaxis_showgrid=False to hide x-axis grid
- xaxis_tickformatOptional[str]
Format string for x-axis ticks.
Examples:
‘%Y-%m-%d’ for dates
‘.0f’ for integers
- xaxis_tickprefixOptional[str]
Prefix for x-axis tick labels.
Example: xaxis_tickprefix=’ km’
- xaxis_ticksuffixOptional[str]
Suffix for x-axis tick labels.
Example: xaxis_ticksuffix=’ units’
- xaxis_dtick Optional[float]):
Step size between x-axis ticks.
Example: xaxis_dtick=1 for integer steps
- xaxis_ticktextOptional[List[str]]
Custom tick labels for the x-axis.
Example: xaxis_ticktext=[‘Jan’, ‘Feb’, ‘Mar’]
- xaxis_tickvalsOptional[List[Union[int, float]]]
Values where custom tick labels should be placed on the x-axis.
Example: xaxis_tickvals=[0, 1, 2]
- xaxis_range (Optional[List[Union[int, float]]]):
Custom range for the x-axis.
Example: xaxis_range=[0, 100]
- xaxis_domain (Optional[List[float]]):
Domain range for x-axis (0 to 1).
Example: xaxis_domain=[0.1, 0.9]
- yaxis_title_text (Optional[str]):
Label for the y-axis.
Example: yaxis_title_text=”Revenue ($)”
- yaxis_showgrid (Optional[bool]):
Whether to show grid lines on the y-axis.
Example: yaxis_showgrid=True
- yaxis_tickformat (Optional[str]):
Format string for y-axis ticks.
Examples:
‘.2f’ for two decimals
‘$,.0f’ for currency without decimals
- yaxis_tickprefix (Optional[str]):
Prefix for y-axis tick labels.
Example: yaxis_tickprefix=’$’
- yaxis_ticksuffix (Optional[str]):
Suffix for y-axis tick labels.
Example: yaxis_ticksuffix=’%’
- yaxis_dtick (Optional[float]):
Step size between y-axis ticks.
Example: yaxis_dtick=10
- yaxis_ticktext (Optional[List[str]]):
Custom tick labels for the y-axis.
Example: yaxis_ticktext=[‘Low’, ‘Medium’, ‘High’]
- yaxis_tickvals (Optional[List[Union[int, float]]]):
Values where custom tick labels should be placed on the y-axis.
Example: yaxis_tickvals=[0, 50, 100]
- yaxis_range (Optional[List[Union[int, float]]]):
Custom range for the y-axis.
Example: yaxis_range=[0, 100]
- yaxis_domain (Optional[List[float]]):
Domain range for y-axis (0 to 1).
Example: yaxis_domain=[0.1, 0.9]
- legend_position Literal[str]:
The position of the legend (‘top’, ‘right’, ‘bottom’). Default is ‘top’.
Example: legend_position=’top’
- legend_title_text (Optional[str]):
Title displayed above the legend.
Example: legend_title_text=”Product Categories”
- showlegend (Optional[bool]):
Whether to display the legend.
Example: showlegend=False to hide legend
- legend_x (Optional[float]):
Legend x position (0 to 1).
Example: legend_x=1.02
- legend_y (Optional[float]):
Legend y position (0 to 1).
Example: legend_y=1.0
- legend_xanchor (Optional[str]):
Legend x anchor point.
Options: ‘auto’, ‘left’, ‘center’, ‘right’
- legend_yanchor (Optional[str]):
Legend y anchor point.
Options: ‘auto’, ‘top’, ‘middle’, ‘bottom’
- legend_orientation (Optional[str]):
Legend orientation.
Options: ‘v’ (vertical), ‘h’ (horizontal)
- legend_itemsizing (Optional[str]):
Legend item sizing mode.
Options: ‘trace’, ‘constant’
- legend_tracegroupgap (Optional([float])):
Sets the amount of vertical space (in px) between legend groups. Number greater than or equal to 0
- textposition (Optional[str]):
Position of text labels relative to data points.
Options:
‘top’
‘bottom’
‘middle’
‘auto’
‘top center’
‘bottom center’
Example: textposition=’top center’
- texttemplate (Optional[str]):
Template for text displayed on the plot.
Example: texttemplate=’%{y:.1f}%’
- textfont (Optional[Dict[str, Union[int, str]]]):
Font settings for displayed text.
Example: textfont=dict(size=12, color=’red’, family=’Arial’)
- hovertemplate (Optional[str]):
Custom hover tooltip template.
Example: hovertemplate=’Date: %{x}<br>Value: %{y:.2f}$<extra></extra>’
- hovermode (Optional[str]):
Hover interaction mode.
Options:
‘x unified’: single tooltip for all traces at x position
‘x’: separate tooltip for each trace at x position
‘y’: separate tooltip for each trace at y position
‘closest’: tooltip for closest point
False: disable hover tooltips
- hoverlabel_align (Optional[str]):
Hover label text alignment.
Options: ‘left’, ‘right’, ‘auto’
- opacity (Optional[float]):
Opacity for figure elements (0 to 1)
- bargap (Optional[float]):
Gap between bars in bar charts (0 to 1).
Example: bargap=0.3 for 30% gap
- barmode, boxmode (Optional[str]):
Determines the mode of the bars in bar charts.
Options include:
‘group’ (default): Bars are placed next to each other.
‘stack’: Bars are stacked on top of each other.
‘overlay’: Bars are drawn on top of each other.
Example: barmode=’stack’ for stacked bars.
- bargroupgap (Optional[float]):
Gap between bar groups (0 to 1).
Example: bargroupgap=0.2 for 20% gap
- margin (Optional[Dict[str, int]]):
Plot margins in pixels.
Example: margin=dict(l=50, r=50, t=50, b=50)
- annotations (Optional[List[Dict]]):
List of annotation dictionaries to add to the figure.
Example: [dict(text=’Note’, x=0.5, y=0.5, showarrow=False)]
- xgap (Optional[int]):
Horizontal gap for heatmap cells.
- ygap (Optional[int]):
Vertical gap for heatmap cells.
- template (Optional[str]):
Plotly template name for consistent styling.
Options: “plotly”, “plotly_white”, “plotly_dark”, “ggplot2”,
“seaborn”, “simple_white”, “presentation”,
“xgridoff”, “ygridoff”, “non”
- hoverlabel (Optional[Dict[str, Union[int, str]]]):
Hover label configuration.
Example: hoverlabel=dict(bgcolor=’white’, bordercolor=”black”, font_size=12, align=”left”)
- coloraxis (Optional[Dict]):
Settings for the color axis (coloraxis) passed to the update_layout function.
Example of usage:
coloraxis={
‘colorscale’: ‘Viridis’, ‘cmin’: 0, ‘cmax’: 70, ‘colorbar’: {
‘title_text’: ‘Initial Colorbar’, ‘len’: 0.7, ‘thickness’: 20, ‘ticks’: ‘outside’, ‘outlinewidth’: 0
}
}
- plot_bgcolorstr, optional
Sets the background color of the plotting area in-between x and y axes.
- kwargs:
Additional arguments to pass to the standard Figure.update() method
Returns#
- CustomFigure
Interactive Plotly figure object