Skip to content
Advertisement

Adjusting global legend (labels) of a plot with subplots (which currently overlaps with the plot) – matplotlib, python

I am trying to add a global legend to a plot, the code below does that but the legend then overlaps with the given plot (I’ll add the plot below). Is there a way to adjust the legends? The other StackOverflow answers are focused on a single plot and are not working with subplots (or maybe I am doing something wrong).

Edit: Right now both the graphs are overlapping and hence the red one isn’t visible.

JavaScript

The plot

Advertisement

Answer

Suggest you put the legend outside the figure:

JavaScript

and then save the figure with plt.savefig("plot.png", bbox_inches='tight') to allow the figure to expand to encompass the legend.

There are other things you can do, but I think this is the simplest…

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement