mirror of
https://github.com/clearml/clearml
synced 2025-01-31 17:17:00 +00:00
Fix Matplotlib automagic export legend not showing series names (issue #337)
This commit is contained in:
parent
4832de5a65
commit
22d795f68f
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user