Skip to content

Commit c4f2dd7

Browse files
fix: auc indicator layout (MAIF#81)
* fix: auc indicator layout * feat: change main github action install method * chore: remove requirements.dev.txt
1 parent e8e3c58 commit c4f2dd7

File tree

5 files changed

+28
-60
lines changed

5 files changed

+28
-60
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: |
2121
python -m pip install --upgrade pip
2222
pip install build flake8 pytest
23-
if [ -f requirements.dev.txt ]; then pip install -r requirements.dev.txt; fi
23+
pip install .[test]
2424
2525
- name: Lint with flake8
2626
run: |

eurybia/core/smartplotter.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -710,27 +710,24 @@ def generate_indicator(
710710
fig_value: float,
711711
min_gauge: float = 0.5,
712712
max_gauge: float = 1,
713-
height: float | None = 300,
714-
width: float | None = 500,
715-
title: str | None = "Metric",
716-
) -> plotly.graph_objs._figure.Figure:
717-
"""Displays an indicator in a colorbar
718-
719-
Parameters
720-
----------
721-
fig_value: float
722-
Value to display on figure
723-
min_gauge: float, (default: 0.5)
724-
range min in gauge display
725-
max_gauge: float, (default: 1)
726-
range max in gauge display
727-
height: str, optional
728-
Height of the plot
729-
width: str, optional
730-
Width of the plot
731-
title: str, optional
732-
Plot title
713+
height: float = 300,
714+
width: float = 500,
715+
title: str = "Metric",
716+
image: bool = False,
717+
) -> plotly.graph_objs._figure.Figure | bytes:
718+
"""Generate an indicator gauge with a colorbar.
733719
720+
Args:
721+
fig_value (float): Value to display on the gauge.
722+
min_gauge (float, optional): Minimum value of the gauge range. Defaults to 0.5.
723+
max_gauge (float, optional): Maximum value of the gauge range. Defaults to 1.
724+
height (float, optional): Height of the plot. Defaults to 300.
725+
width (float, optional): Width of the plot. Defaults to 500.
726+
title (str, optional): Title of the plot. Defaults to "Metric".
727+
image (bool, optional): If True, returns an image instead of a Plotly Figure. Defaults to False.
728+
729+
Returns:
730+
plotly.graph_objs._figure.Figure | bytes: The generated figure or image.
734731
"""
735732
color = sns.blend_palette(["green", "yellow", "orange", "red"], 100)
736733
color = color.as_hex()
@@ -764,4 +761,4 @@ def generate_indicator(
764761
width=width,
765762
)
766763

767-
return fig
764+
return fig.to_image() if image else fig

eurybia/report/generation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def _get_index_panel(
5252
raise RuntimeError("AUC should have been set.")
5353
# AUC
5454
auc_block = dr.smartdrift.plot.generate_indicator(
55-
fig_value=dr.smartdrift.auc, height=280, width=500, title="Datadrift classifier AUC"
55+
fig_value=dr.smartdrift.auc, height=280, width=500, title="Datadrift classifier AUC", image=True
5656
)
57-
auc_indicator = pn.pane.Plotly(auc_block)
57+
auc_indicator = pn.pane.PNG(auc_block)
5858

5959
# Jensen-Shannon
6060
if dr.smartdrift.deployed_model is not None:
@@ -68,8 +68,9 @@ def _get_index_panel(
6868
title="Jensen Shannon Datadrift",
6969
min_gauge=0,
7070
max_gauge=0.2,
71+
image=True,
7172
)
72-
js_indicator = pn.pane.Plotly(JS_block)
73+
js_indicator = pn.pane.PNG(JS_block)
7374
indicators = pn.Row(auc_indicator, js_indicator)
7475

7576
else:
@@ -218,9 +219,9 @@ def _get_data_drift_panel(dr: DriftReport) -> pn.Column:
218219
raise RuntimeError("AUC should have been set.")
219220

220221
auc = dr.smartdrift.plot.generate_indicator(
221-
fig_value=dr.smartdrift.auc, height=300, width=500, title="Datadrift classifier AUC"
222+
fig_value=dr.smartdrift.auc, height=300, width=500, title="Datadrift classifier AUC", image=True
222223
)
223-
blocks += [pn.pane.Plotly(auc)]
224+
blocks += [pn.pane.PNG(auc)]
224225

225226
blocks += [
226227
pn.pane.Markdown("## Importance of features in data drift"),
@@ -279,8 +280,9 @@ def _get_data_drift_panel(dr: DriftReport) -> pn.Column:
279280
title="Jensen Shannon Datadrift",
280281
min_gauge=0,
281282
max_gauge=0.2,
283+
image=True,
282284
)
283-
blocks += [pn.pane.Plotly(js_fig)]
285+
blocks += [pn.pane.PNG(js_fig)]
284286

285287
contribution_figures, contribution_labels = dr.display_model_contribution()
286288

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"seaborn>=0.10.1",
3333
"shapash>=2.0.0",
3434
"plotly",
35+
"kaleido>=0.2.1,<1.0.0",
3536
]
3637

3738
[project.optional-dependencies] # Optional

requirements.dev.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)