Commit 95264092 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch 'twin-legend' into 'master'

In a plot, assume a Figure can contain multiple Axes

See merge request !102
parents e4ff9fae f0071cea
Pipeline #50002 passed with stages
in 7 minutes and 22 seconds
......@@ -598,7 +598,7 @@ class PlotBase(MeasureBase):
mpl.ylabel(self._y_label)
mpl.grid(True, color=self._grid_color)
if self._disp_legend:
mpl.legend(loc=self._legend_loc)
self.plot_legends()
self._set_axis()
mpl.xticks(rotation=self._x_rotation)
self._pdf_page.savefig(fig)
......@@ -609,6 +609,31 @@ class PlotBase(MeasureBase):
):
self._pdf_page.close()
def plot_legends(self):
"""Print legend on current plot"""
if not self._disp_legend:
return
lines = []
labels = []
for ax in mpl.gcf().get_axes():
ali, ala = ax.get_legend_handles_labels()
# avoid duplicates in legend
for li, la in zip(ali, ala):
if la not in labels:
lines.append(li)
labels.append(la)
# create legend on the top or bottom axis
leg = mpl.legend(
lines,
labels,
loc=self._legend_loc,
ncol=1,
)
return leg
# common protected functions
def _label(self, base, idx):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment