Skip to main content

All Questions

Tagged with
1 vote
1 answer
29 views

How do I make one legend for all subplots in a sns.histplot without duplicate labels?

I have a dataframe that I'm plotting using sns.histplot to make ~9 subplots. I do not want the figure to have 9 legends. I'd like 1 legend for the entire figure, since most of the legends are ...
519 votes
9 answers
999k views

How to change legend fontsize with matplotlib.pyplot

Simple question here: I'm trying to get the size of my legend using matplotlib.pyplot to be smaller (i.e., the text to be smaller). The code I'm using goes something like this: plot.figure() plot....
7 votes
1 answer
4k views

Replace Matplotlib legend's labels with image

I would like to use image instead of labels in the legend. For example, I draw 2 lines and show a legend : import matplotlib.pyplot as plt plt.plot([1,2],label="first_image") plt.plot([2,1],label="...
1 vote
0 answers
39 views

Text shifted in legend because of LaTeX formatting in matplotlib

For some reason in my subplot, the legend of the second ax is cropped at the bottom inside of the legend box. It seems the index causes the text to shift a bit. The legend box itself is perfectly fine....
1 vote
0 answers
34 views

How to add a FancyBbox as a legend?

As per the title, I'm trying to add a list of fancy bboxes to a legend : https://matplotlib.org/stable/gallery/shapes_and_collections/fancybox_demo.html. I tried the code below but there is a problem. ...
118 votes
6 answers
126k views

Show only certain items in legend

I currently am plotting a stacked bar graph of a large amount of taxonomic data, and only wish to show significant species in the legend (out of ~500 I wish to show ~25). Is there a simple way to do ...
0 votes
0 answers
37 views

Putting Legend completely outside the plot in right center

I am trying to create a plot where the legend will be in the right center but completely outside the plot. I am following this answer https://stackoverflow.com/a/75453792/3587282 and using Matplotlib ...
3 votes
2 answers
163 views

How to reposition Figure legends into subfigures

I am new to this, trying to plot 2 subfigures horizontal with sample data using Matplotlib and Seaborn library in Jupyter Notebook, the 2 sub-charts come out alright, but the 2 legends overlap each ...
7 votes
2 answers
2k views

How can I customize the legend with Seaborn 0.12 objects?

The new Seaborn objects (v 0.12) are great but I struggle to deal with legend customization. Especially when using matplotlib to define subplots. My code: f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, ...
0 votes
1 answer
51 views

Seaborn catplot legend's background color and border

MWE from matplotlib import pyplot as plt import seaborn as sb df = sb.load_dataset("titanic") g = sb.catplot( data=df, x="who", y="survived", hue="class", ...
1660 votes
18 answers
1.9m views

How to put the legend outside the plot

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets ...
0 votes
2 answers
36 views

2 legends on graph matplotlib [duplicate]

I want to plot a number of curves for different models. I have curves for different structures. The structures need to have the same color and the different models a different linestyle. I then want 2 ...
109 votes
4 answers
182k views

How to place two different legends on the same graph

I have a plot where different colors are used for different parameters, and where different line styles are used for different algorithms. The goal is to compare the results of the different ...
0 votes
0 answers
33 views

Plotting problems in python script vs jupyter notebook

I am encountering issues with my plotting code when running it as a Python script in PyCharm. The plots overlap, and the legends are not displayed, which does not happen when I run the same code in a ...
329 votes
11 answers
443k views

Remove the legend on a matplotlib figure

To add a legend to a matplotlib plot, one simply runs legend(). How to remove a legend from a plot? (The closest I came to this is to run legend([]) in order to empty the legend from data. But that ...

15 30 50 per page
1
2 3 4 5
69