Skip to content

Commit

Permalink
BoxPlots are now notched.
Browse files Browse the repository at this point in the history
  • Loading branch information
adocquin committed May 16, 2023
1 parent eaff49f commit e42c224
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions coolpandas/plot/boxplot.py
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

0 comments on commit e42c224

Please sign in to comment.