Skip to content

Commit eebb027

Browse files
add heatmap figure #156
1 parent eb8a451 commit eebb027

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

docs/modules/tutorial/pages/configurationfiles/plots.adoc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,36 @@ fig = figures[0].createFigure(model.master_df)
284284
fig.show()
285285
----
286286

287+
- `heatmap`
288+
289+
For this case, we will consider the `elements` (N) as `color_axis` and `performance_variable` for secondary axis (slider).
290+
291+
[%dynamic%open%hide_code,python]
292+
----
293+
figures = FigureFactory.create(Plot(**{
294+
"title": "Absolute performance",
295+
"plot_types": [ "heatmap" ],
296+
"transformation": "performance",
297+
"variables": [ "computation_time","communication_time" ],
298+
"names": ["Time"],
299+
"color_axis":{
300+
"parameter":"elements",
301+
"label":"N"
302+
},
303+
"yaxis":{"label":"Execution time (s)"},
304+
"secondary_axis":{
305+
"parameter":"performance_variable",
306+
"label":"Performance variable"
307+
},
308+
"xaxis":{
309+
"parameter":"nb_tasks.tasks",
310+
"label":"Number of tasks"
311+
}
312+
}))
313+
fig = figures[0].createFigure(model.master_df)
314+
fig.show()
315+
----
316+
287317
- `table`
288318

289319
[%dynamic%open%hide_code,python]
@@ -312,6 +342,7 @@ fig = figures[0].createFigure(model.master_df)
312342
fig.show()
313343
----
314344

345+
315346
== Aggregations
316347

317348
Depending on the dashboard level that we are located at, it might be necessary to aggregate the data on the master dataframe.

src/feelpp/benchmarking/reframe/config/configPlots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def checkAgg(cls, v):
1818

1919
class Plot(BaseModel):
2020
title:str
21-
plot_types:List[Literal["scatter","table","stacked_bar","grouped_bar"]]
21+
plot_types:List[Literal["scatter","table","stacked_bar","grouped_bar","heatmap"]]
2222
transformation:Literal["performance","relative_performance","speedup"]
2323
aggregations:Optional[List[Aggregation]] = None
2424
variables:Optional[List[str]] = None

src/feelpp/benchmarking/report/figureFactory.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,51 @@ def createSimpleFigure(self,df):
282282
"""
283283
return go.Figure(self.createTraces(df))
284284

285+
class HeatmapFigure(Figure):
286+
def __init__(self, plot_config, transformation_strategy):
287+
super().__init__(plot_config, transformation_strategy)
288+
289+
def createTraces(self, df):
290+
""" Creates the Heatmap traces for a given dataframe. Useful for animation creation.
291+
Args:
292+
- df (pd.DataFrame): The dataframe containing the figure data.
293+
Returns: (go.Trace) The Heatmap traces to display in the scatter figure.
294+
"""
295+
return go.Heatmap(
296+
x=df.index.astype(str),
297+
y=df.columns.astype(str),
298+
z=df.T.values,
299+
colorbar = dict(
300+
title = self.config.yaxis.label
301+
)
302+
)
303+
304+
def createMultiindexFigure(self, df):
305+
""" Creates a plotly figure from a multiIndex dataframe
306+
Args:
307+
df (pd.DataFrame). The transformed dataframe (must be multiindex)
308+
Returns:
309+
go.Figure: Heatmap animation where the secondary_ axis corresponds to a specified parameter
310+
"""
311+
return self.createSliderAnimation(df)
312+
313+
def createSimpleFigure(self, df):
314+
""" Creates a plotly figure from a given dataframe
315+
Args:
316+
df (pd.DataFrame). The transformed dataframe
317+
Returns:
318+
go.Figure: Heatmap plot
319+
"""
320+
return go.Figure(self.createTraces(df))
321+
322+
def updateLayout(self, fig):
323+
""" Sets the title, yaxis and legend attributes of the layout"""
324+
fig.update_layout(
325+
title=self.config.title,
326+
xaxis=dict(title=self.config.xaxis.label),
327+
yaxis=dict(title=self.config.color_axis.label)
328+
)
329+
return fig
285330

286331
class FigureFactory:
287332
""" Factory class to dispatch concrete figure elements"""
@@ -305,6 +350,8 @@ def create(plot_config):
305350
figures.append(StackedBarFigure(plot_config,strategy))
306351
elif plot_type == "grouped_bar":
307352
figures.append(GroupedBarFigure(plot_config,strategy))
353+
elif plot_type == "heatmap":
354+
figures.append(HeatmapFigure(plot_config,strategy))
308355
else:
309356
raise NotImplementedError
310357

tests/report/test_figureFactory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from feelpp.benchmarking.report.figureFactory import FigureFactory, ScatterFigure, TableFigure, StackedBarFigure, GroupedBarFigure
1+
from feelpp.benchmarking.report.figureFactory import FigureFactory, ScatterFigure, TableFigure, StackedBarFigure, GroupedBarFigure, HeatmapFigure
22
from test_transformationFactory import PlotConfigMocker
33
import pytest
44

@@ -10,6 +10,7 @@
1010
(["table"],[TableFigure]),
1111
(["stacked_bar"],[StackedBarFigure]),
1212
(["grouped_bar"],[GroupedBarFigure]),
13+
(["heatmap"],[HeatmapFigure]),
1314
(["unkown"],[])
1415
])
1516
def test_figureFactory(types,expected_classes):

0 commit comments

Comments
 (0)