scripts: plot[mpl].py: Merge legend labels if they would be identical
This tweaks how we build legends in plot.py and plotmpl.py to merge
legend labels if they would end up identical (same label, same color,
same format, char, linechar, etc).
Identical labels are confusing anyways, so we might as well minimize the
size of the legend when this happens.
---
Though the real motivation for this is to simplify legend labels that
span multiple subplots. Before, you had to awkwardly glob out subplot
labels you didn't want repeated in the legend:
./scripts/plot.py test.csv \
-L3,readed=lfs3 \
-L3,progged= \
-L3,erased= \
-L2,readed=lfs2 \
-L2,progged= \
-L2,erased=
But now you can specify them willy-nilly, and in the final legend any
redundant labels will be automatically merged:
./scripts/plot.py test.csv \
-L3=lfs3 \
-L2=lfs2
This commit is contained in:
+4
-1
@@ -1531,7 +1531,10 @@ def main_(ring, csv_paths, *,
|
||||
if name in datalabels_
|
||||
else ','.join(name))
|
||||
|
||||
if label:
|
||||
# append and merge identical labels
|
||||
if not label:
|
||||
continue
|
||||
if (label, datacolors_[name]) not in legend_:
|
||||
legend_.append((label, datacolors_[name]))
|
||||
legend_width = max(legend_width, len(label)+1)
|
||||
|
||||
|
||||
+18
-6
@@ -1334,14 +1334,26 @@ def main(csv_paths, output, *,
|
||||
legend[l] = h
|
||||
# sort in dataset order
|
||||
legend_ = []
|
||||
legend__ = set()
|
||||
for i, name in enumerate(datasets_.keys()):
|
||||
if name in datalabels_ and not datalabels_[name]:
|
||||
continue
|
||||
|
||||
name_ = ','.join(name)
|
||||
if name_ in legend:
|
||||
if name in datalabels_:
|
||||
if datalabels_[name]:
|
||||
legend_.append((datalabels_[name], legend[name_]))
|
||||
else:
|
||||
legend_.append((name_, legend[name_]))
|
||||
if name_ not in legend:
|
||||
continue
|
||||
|
||||
if name in datalabels_:
|
||||
label = datalabels_[name]
|
||||
else:
|
||||
label = name_
|
||||
|
||||
# append and merge identical labels
|
||||
if not label:
|
||||
continue
|
||||
if (label, datacolors_[name], dataformats_[name]) not in legend__:
|
||||
legend_.append((label, legend[name_]))
|
||||
legend__.add((label, datacolors_[name], dataformats_[name]))
|
||||
legend = legend_
|
||||
|
||||
if legend_right:
|
||||
|
||||
Reference in New Issue
Block a user