-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Box plot module.""" | ||
import pandas as pd | ||
import plotly.express as px | ||
import plotly.graph_objects as go | ||
|
||
from .style import custom_template, format_title | ||
|
||
|
||
def boxplot( | ||
data_frame: pd.DataFrame, | ||
x_axis: str, | ||
y_axis: str, | ||
title: str, | ||
subtitle: str | None = None, | ||
**kwargs, | ||
) -> go.Figure: | ||
"""Create a box plot. | ||
Args: | ||
data_frame (pd.DataFrame): DataFrame to plot. | ||
x_axis (str): Column to use as x axis. | ||
y_axis (str): Column to use as y axis. | ||
title (str): Title of the plot. | ||
subtitle (str, optional): Subtitle of the plot. Defaults to None. | ||
**kwargs: Keyword arguments to pass to plotly.express.box. | ||
Returns: | ||
go.Figure: Box plot figure. | ||
""" | ||
if "color" not in kwargs: | ||
kwargs["color"] = x_axis | ||
fig = px.box( | ||
data_frame, | ||
x=x_axis, | ||
y=y_axis, | ||
notched=True, | ||
title=format_title(title, subtitle=subtitle), | ||
template=custom_template, | ||
width=800, | ||
height=400, | ||
**kwargs, | ||
) | ||
if kwargs.get("color") == x_axis: | ||
fig.layout.update(showlegend=False) | ||
return fig |