I can't seem to find a solution. I have a legend that's custom (using solution found here) and I'm trying to put multiple entries on one line rather than have each new entry under the previous one. How does one do?
red_patch = mpatches.Patch(color='red', label='The red data')
blue_patch = mpatches.Patch(color='blue', label='The blue data')
plt.legend(handles=[red_patch, blue_patch])
I'd like to have "(red marker) The red data, (blue marker) The blue data, etc..." all in one line on top. It'd be nice to have it start a new line too when there are more entries than can fit on the plot. So just like normal text I guess.
Matplotlib set legend outside plot In Matplotlib, to set a legend outside of a plot you have to use the legend() method and pass the bbox_to_anchor attribute to it. We use the bbox_to_anchor=(x,y) attribute. Here x and y specify the coordinates of the legend.
Add an axes to the current figure as a subplot arrangement. Make a box and whisker plot using boxplot() method with different facecolors. To place the legend, use legend() method with two boxplots, bp1 and bp2, and ordered label for legend elements. To display the figure, use show() method.
If you want to have n
columns in the legend, you can use
plt.legend(ncol=n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With