diff --git a/clearml/binding/matplotlib_bind.py b/clearml/binding/matplotlib_bind.py index 06e52564..55c859bf 100644 --- a/clearml/binding/matplotlib_bind.py +++ b/clearml/binding/matplotlib_bind.py @@ -408,6 +408,22 @@ class PatchedMatplotlib: plotly_renderer.plotly_fig['layout'][_yaxis].pop('type', None) except Exception: pass + + # try to bring back legend + # noinspection PyBroadException + try: + if plotly_renderer.plotly_fig.get('layout', {}).get('showlegend') and \ + plotly_renderer.plotly_fig.get('data'): + # the legend names is the upper half of the data points: + lines_ = plotly_renderer.plotly_fig['data'] + half_mark = len(lines_)//2 + if len(lines_) % 2 == 0 and \ + all(l for l in lines_[half_mark:] if not l.get('x') and not l.get('y')): + for i, line in enumerate(lines_[:half_mark]): + line['name'] = lines_[i+half_mark].get('name') + except Exception: + pass + return deepcopy(plotly_renderer.plotly_fig) plotly_dict = our_mpl_to_plotly(mpl_fig) diff --git a/clearml/utilities/plotlympl/mpltools.py b/clearml/utilities/plotlympl/mpltools.py index d3d69825..2e66968d 100644 --- a/clearml/utilities/plotlympl/mpltools.py +++ b/clearml/utilities/plotlympl/mpltools.py @@ -156,6 +156,7 @@ def merge_color_and_opacity(color, opacity): if opacity is None: return "rgb {}".format(rgb_tup) + opacity = int(opacity*255.) if opacity <= 1.0 else int(opacity) rgba_tup = rgb_tup + (opacity,) return "rgba {}".format(rgba_tup)