|
import pandas as pd |
|
import plotly.express as px |
|
import plotly.graph_objects as go |
|
from plotly.subplots import make_subplots |
|
|
|
|
|
|
|
def create_lac_count_per_controller_subplots( |
|
df: pd.DataFrame, |
|
controller_column: str, |
|
lac_column: str, |
|
count_column: str, |
|
fig_title: str, |
|
): |
|
|
|
unique_controllers = df[controller_column].unique() |
|
|
|
|
|
rows_needed = (len(unique_controllers) + 3) // 4 |
|
|
|
|
|
fig = make_subplots( |
|
rows=rows_needed, |
|
cols=4, |
|
shared_xaxes=False, |
|
subplot_titles=unique_controllers, |
|
) |
|
|
|
|
|
subplot_position = 1 |
|
|
|
|
|
for controller in unique_controllers: |
|
|
|
controller_data = df[df[controller_column] == controller] |
|
|
|
|
|
row = (subplot_position - 1) // 4 + 1 |
|
col = (subplot_position - 1) % 4 + 1 |
|
|
|
|
|
fig.add_trace( |
|
go.Bar( |
|
x=controller_data[lac_column], |
|
y=controller_data[count_column], |
|
name=controller, |
|
text=controller_data[count_column], |
|
), |
|
row=row, |
|
col=col, |
|
) |
|
|
|
|
|
subplot_position += 1 |
|
|
|
|
|
fig.update_layout( |
|
height=300 * rows_needed, |
|
title_text=fig_title, |
|
showlegend=False, |
|
) |
|
|
|
|
|
|
|
|
|
return fig |
|
|
|
|
|
def create_bar_chart(df: pd.DataFrame, title: str = "Chart Title") -> px.bar: |
|
""" |
|
Create a bar chart using Plotly Express with the first column as x and the second column as y. |
|
|
|
Args: |
|
df (pd.DataFrame): Input DataFrame |
|
|
|
Returns: |
|
fig (px.bar): Bar chart figure |
|
""" |
|
fig = px.bar( |
|
df, |
|
x=df.columns[0], |
|
y=df.columns[1], |
|
text_auto=True, |
|
title=title, |
|
height=300, |
|
width=600, |
|
) |
|
fig.update_xaxes(tickvals=df[df.columns[0]].unique()) |
|
return fig |
|
|