Skip to content

Commit aed87b5

Browse files
committed
analysis: Allow optional annotation of plot_tradeoff graphs
Allow to annotate the points of plot_tradeoff graphs (which use peeling_trajectory DataFrames) with id labels. This makes it easy to quickly identify points on the tradeoff graphs which look interesting. Works best with large graphs (using "fig.set_size_inches").
1 parent 6f4a4ae commit aed87b5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

ema_workbench/analysis/logistic_regression.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,20 +254,21 @@ def update(self, model, selected):
254254
new_row, ignore_index=True, sort=True
255255
)
256256

257-
def show_tradeoff(self, cmap=mpl.cm.viridis): # @UndefinedVariable
257+
def show_tradeoff(self, cmap=mpl.cm.viridis, annotated=False): # @UndefinedVariable
258258
"""Visualize the trade off between coverage and density. Color
259259
is used to denote the number of restricted dimensions.
260260
261261
Parameters
262262
----------
263263
cmap : valid matplotlib colormap
264+
annotated : bool, optional. Shows point labels if True.
264265
265266
Returns
266267
-------
267268
a Figure instance
268269
269270
"""
270-
return sdutil.plot_tradeoff(self.peeling_trajectory, cmap=cmap)
271+
return sdutil.plot_tradeoff(self.peeling_trajectory, cmap=cmap, annotated=annotated)
271272

272273
# @UndefinedVariable
273274
def show_threshold_tradeoff(self, i, cmap=mpl.cm.viridis_r, step=0.1):

ema_workbench/analysis/prim.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,21 @@ def show_ppt(self):
805805
"""show the peeling and pasting trajectory in a figure"""
806806
return sdutil.plot_ppt(self.peeling_trajectory)
807807

808-
def show_tradeoff(self, cmap=mpl.cm.viridis): # @UndefinedVariable
808+
def show_tradeoff(self, cmap=mpl.cm.viridis, annotated=False): # @UndefinedVariable
809809
"""Visualize the trade off between coverage and density. Color
810810
is used to denote the number of restricted dimensions.
811811
812812
Parameters
813813
----------
814814
cmap : valid matplotlib colormap
815+
annotated : bool, optional. Shows point labels if True.
815816
816817
Returns
817818
-------
818819
a Figure instance
819820
820821
"""
821-
return sdutil.plot_tradeoff(self.peeling_trajectory, cmap=cmap)
822+
return sdutil.plot_tradeoff(self.peeling_trajectory, cmap=cmap, annotated=annotated)
822823

823824
def show_pairs_scatter(self, i=None, dims=None, cdf=False):
824825
"""Make a pair wise scatter plot of all the restricted

ema_workbench/analysis/scenario_discovery_util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,14 @@ def plot_ppt(peeling_trajectory):
648648
return fig
649649

650650

651-
def plot_tradeoff(peeling_trajectory, cmap=mpl.cm.viridis): # @UndefinedVariable
651+
def plot_tradeoff(peeling_trajectory, cmap=mpl.cm.viridis, annotated=False): # @UndefinedVariable
652652
"""Visualize the trade off between coverage and density. Color
653653
is used to denote the number of restricted dimensions.
654654
655655
Parameters
656656
----------
657657
cmap : valid matplotlib colormap
658+
annotated : bool, optional. Shows point labels if True.
658659
659660
Returns
660661
-------
@@ -681,6 +682,10 @@ def plot_tradeoff(peeling_trajectory, cmap=mpl.cm.viridis): # @UndefinedVariabl
681682
ax.set_ylim(bottom=0, top=1.2)
682683
ax.set_xlim(left=0, right=1.2)
683684

685+
if annotated:
686+
for idx, row in peeling_trajectory.iterrows():
687+
ax.annotate(row['id'], (row['coverage'], row['density']))
688+
684689
ticklocs = np.arange(0, max(peeling_trajectory["res_dim"]) + 1, step=1)
685690
cb = fig.colorbar(p, spacing="uniform", ticks=ticklocs, drawedges=True)
686691
cb.set_label("nr. of restricted dimensions")

0 commit comments

Comments
 (0)