motan_graph: Fix legend when using matplotlib twinx

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-08-23 21:04:25 -04:00
parent 7aa2c11b3a
commit d759b4e532
1 changed files with 7 additions and 2 deletions

View File

@ -53,8 +53,13 @@ def plot_motion(amanager, graphs):
pparams = {'label': label['label'], 'alpha': 0.8} pparams = {'label': label['label'], 'alpha': 0.8}
pparams.update(plot_params) pparams.update(plot_params)
ax.plot(times, datasets[dataset], **pparams) ax.plot(times, datasets[dataset], **pparams)
ax.legend(loc='best', prop=fontP) if twin_ax is not None:
ax.grid(True) li1, la1 = graph_ax.get_legend_handles_labels()
li2, la2 = twin_ax.get_legend_handles_labels()
twin_ax.legend(li1 + li2, la1 + la2, loc='best', prop=fontP)
else:
graph_ax.legend(loc='best', prop=fontP)
graph_ax.grid(True)
rows[-1].set_xlabel('Time (s)') rows[-1].set_xlabel('Time (s)')
return fig return fig