I have a plot with 6 subplots with very similar data. I only want one legend and I would like to place it such that it overlaps two subplots, but it seems matplotlib prevents this. If I move the legend a bit up it changes the format of the subplots such that it doesn't overlap another plot. So my question would be: how to replace the legend without affecting the general make up of the subplots/how to allow overlapping?
I have tried both with loc
and bbox_to_anchor
but both reformat the subplots (i.e. changes axes)
Used syntax: ax[1,1].legend(["line1",..,"lineN"],loc=(0.5,0.5)
and the same but loc replaced with bbob_to_anchor
EDIT: I have just found this answer but it doesn't work for me I think because I'm not defining the labels inside the plot call. What I tried based on that answer was:
handles,labels = ax[1,1].get_legend_handles_labels()
fig.legend(handles, ["line0",..,"lineN"], loc=(0.5,0.5))
But that gives me an empty legend. Just a little small square
EDIT2: A bit more clarification to my exact situation:
f, ax = plt.subplots(3,2, figsize=(10,8), sharex=True, sharey=True)
x = np.linspace(0,100,100)
y = np.random.rand(100,3)
ax[0,0].plot(x,y)
ax[0,1].plot(x,y)
ax[1,0].plot(x,y)
ax[1,1].plot(x,y)
ax[2,0].plot(x,y)
ax[2,1].plot(x,y)
//One single legend for the three lines represented in y. It should overlap part of subplot 0,1 and 1,1