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 ...
rcpi's user avatar
  • 51
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....
Chris Ze Third's user avatar
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. ...
VERBOSE's user avatar
  • 1,105
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 ...
melatonin15's user avatar
  • 2,209
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", ...
Gaslight Deceive Subvert's user avatar
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 ...
Loes Vandenbroucke's user avatar
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 ...
JuanMuñoz's user avatar
1 vote
1 answer
45 views

How to add legend of plotted line in a box plot?

I have plotted a set of data in a boxplot, and I have added a line in the plot. I want to have the labels of the median and mean in the legend, and I have got it. However, I'm also trying to add the ...
lolloa's user avatar
  • 27
0 votes
0 answers
22 views

Line2D multiple colors in legend [duplicate]

I want to create a custom legend. Here, in the example, I create two lines. But for this line, which now is blue, I would like it to be in multiple colors: blue, green, and red. Here is a minimum ...
blahblah's user avatar
0 votes
0 answers
13 views

Matplotlib not changing legend labels for a plot in python package pyAT

So I am attempting to use a python interface of Accelerator Toolbox (pyAT: link here) to simulate the path of a few particles through an energy spectrometer. From this interface, I've utilized a ...
tfs563's user avatar
  • 1
0 votes
0 answers
33 views

Inserting legend in a Matplotlib/Geopandas Map

I've created a incidence map for a city, but now i need to manipulate the legend ( decrease its size, put it bellow the map/graph, insert labels). i've used a json file to plot the territory. Here's ...
gongmaodu's user avatar
1 vote
1 answer
61 views

How to make pyplot Hatches look pretty in the legend

I have a problem and struggle to find a solution, or phrase the question for a search engine. I have many python plots where i use hatches to show exclusions from constraints (so some hatches are not ...
TheMaker845's user avatar
1 vote
1 answer
64 views

Why doesn't sns.barplot legend show all values?

I have the following graph. Why does the last graph legend not contain all labels? It should contain these values: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 21] Code: # select only this year ...
John Doe's user avatar
  • 319
1 vote
1 answer
42 views

Legend for boxplot graph layers

I've made this boxplot graph # Tamanho do gráfico em polegadas plt.figure(figsize=(11, 6)) # Gráfico ax = sns.boxplot(x="CÓD. ESTAÇÃO", y ="FERRO", data=df_FERRO, linewidth=1.0, ...
gongmaodu's user avatar
1 vote
0 answers
57 views

Multiple columns of df show as 1 single label in legend and show how many columns are representing on matplotlib

I have a dataframe that contains temperature of 3 meteorological networks and each ones contains a certain meteorological stations, so the columns 0 to 34 are stations of 'REDMET' meteorological ...
Ferchiz4200's user avatar
0 votes
1 answer
76 views

How can I plot multiple legends for multiple geopandas plot layers?

I want two show both legends for both of my plot layers but it shows only just one legend. How can I fix this? import geopandas from shapely.geometry import Point from shapely.geometry import Polygon ...
Norbi's user avatar
  • 103
0 votes
1 answer
32 views

Do gca().lines and legend.get_lines() return the lines in the same order?

Do gca().lines and legend.get_lines() return the lines in the same corresponding order? If not, is there a way to get corresponding legend lines from gca().lines?
Tims's user avatar
  • 641
1 vote
1 answer
181 views

How to make a legend with line and markers with different fillstyles?

I am unsure of how to reproduce the following lines/marker combination in matplotlib: Note that the legend has both the line and the marker correctly. The best I could find in the matplotlib ...
Idieh's user avatar
  • 63
-1 votes
1 answer
112 views

Cannot Rotate Legend Horizontally in GeoPandas

I am trying to plot California counties and color them by their FIPS code. The sample code from the GeoPandas website is: chicago.plot( column="POP2010", legend=True, ...
ZacharyST's user avatar
  • 676
0 votes
1 answer
58 views

Multiple column legends in Matplotlib

I created a single stacked horizontal bar chart which illustrates the values in a (normalized) series using: data = df['state'].value_counts(normalize=True).to_frame() data.T.plot.barh(stacked=True, ...
vonbecker's user avatar
2 votes
1 answer
60 views

Seaborn heatmap legend disturb the plots order with subplots

I have 2 dataframes like this: df1 = pd.DataFrame(np.random.randint(0,50,size=(5,5)), columns=list('ABCDE')) df2 = pd.DataFrame(np.random.randint(0,50,size=(5,5)), columns=list('FGHIJ')) I want to ...
Yash's user avatar
  • 337
1 vote
1 answer
200 views

Combine catplot legend with other legends in seaborn

I want to combine multiple plot legends with a catplot legend and place the single result in the upper right. I also want to replace the labels on both. Examples - {"avg tip":"average&...
ciaran haines's user avatar
3 votes
1 answer
129 views

Custom legend for the plot with lines changing colour

I want to plot two error bars plots with lines changing colour, one going from pink to blue, and another from blue to pink. I did not find a way to do this with plt.errorbar(), but managed to find a ...
Lidiia's user avatar
  • 33
1 vote
1 answer
231 views

Legend for contourf in matplotlib [duplicate]

Is there a way put a legend for a contourf plot in matplotlib? In matlab it's possible to put one like the example picture shown below. I am aware of both these questions posted previously: How do you ...
albo's user avatar
  • 33
0 votes
2 answers
217 views

How to reverse order of legend for horizontal stacked bar chart in seaborn?

I have the following code that generates a horizontal stacked bar chart in python, using seaborn. sns.set_style('white') ax = sns.histplot( data=temp, y='tmp', weights='Weight', hue=field, ...
LostinSpatialAnalysis's user avatar
1 vote
2 answers
61 views

matplotlib scatter plot legend not dependent on the colour of the point

I want to make my legend to the scatter plot not dependent on the colour of the point. The simple example is below: import matplotlib.pyplot as plt import numpy as np import pandas as pd fake_data = ...
Wiktoria's user avatar
1 vote
1 answer
82 views

Choosing elements for a legend in Python

I am using py.plot to display the upper and lower bounds of confidence intervals (shaded in between). I would like to label each pair of bounds with the item they are measuring. However, Python seems ...
josephbags's user avatar
0 votes
1 answer
226 views

Legend in matplotlib jumps around with minimal change to bbox_to_anchor parameters

I have this issue in matplotlib that drives me crazy. I want to position the legend within the plot to be in a certain position, for example, in this case, in the top left corner (matching the corner ...
My Work's user avatar
  • 2,408
0 votes
0 answers
7 views

How can I include two categories of label (colour coded and shapes) in a single legend for a single dataset using a matplotlib scatterplot?

I have a dataset, texts, that I want to display using a scatterplot. The texts represented in this dataset have different authors, and are written in different languages. I want to represent the ...
AdeDoyle's user avatar
  • 395
2 votes
1 answer
172 views

How to have a combined legend for colors and marker types

I frequently generate complex plots and strive to simplify the legends. In this particular instance, I am plotting data categorized by multiple models and temperature bands. I want to include two ...
Shekaib Musa's user avatar
0 votes
0 answers
32 views

How to add tags for a data point in an image [duplicate]

With the following code, I plot a graph as follows: import matplotlib.pyplot as plt # Sample data gflops_a = [72.3, 74.5, 79.6, 82.5] model_a_ACC = [9.3, 9.7, 11.2, 14.2] gflops_b = [73.95, 75.2, ...
MFalam's user avatar
  • 15
0 votes
0 answers
69 views

Manually add Errorbar to Legend (ErrorbarContainer)

I would like to add a manual legend to a matplotlib plot of this nature: While I managed to add the horizontal bars to my legend, I am stuck with the creation of the horizontal error bars. I based my ...
Wasserwaage's user avatar
1 vote
2 answers
288 views

How to create a single figure legend for GeoAxes subplots

I have looked at the many other questions on here to try and solve this but for whatever reason I cannot. Each solution seems to give me the same error, or returns nothing at all. I have a list of six ...
redleesy's user avatar
0 votes
1 answer
62 views

Modify legend color of a matplotlib plot created by gluonts

I'm using gluonts and plotting a forecast (code from DeepVaR notebook). The code is the following: def plot_prob_forecasts(ts_entry, forecast_entry, asset_name, plot_length=20): ...
Andrea Dalseno's user avatar
0 votes
1 answer
89 views

Remove style entries from seaborn lineplot legend [duplicate]

I have a pandas dataframe with name, date, strenght, protocol columns. I am plotting a seaborn lineplot with date column as x; strenght column as y; protocol column as hue; name column as style. I ...
Jacopo Busatto's user avatar
0 votes
0 answers
35 views

Add legend to scatter plot to differentiate colours, when there are multiple data types?

How do we add a scatter plot legend which signifies the different colors on python chart? i.e. how do we turn chart 1 into chart 2 Chart with data types has legend missing Chart without data types ...
user2461546's user avatar
0 votes
1 answer
77 views

creating a scatter legend size with range 0-100 no matter what the range of the data

I am having trouble with creating a matplotlib scatter plot with a legend showing the size diameter of points. The problem is with the scatter_plot.legend_elements function. The problem is I want to ...
aindap's user avatar
  • 71
0 votes
1 answer
285 views

How to customize the color scatterplot legend handle [duplicate]

I have a seaborn scatterplot with datapoints distinguished by (1) color and (2) marker. This is the minimal code that generates the plot: d = {'x': [1, 2, 3, 4], 'y': [2,4,6,8], 'Set': ["Set 1&...
innakigc's user avatar
-1 votes
2 answers
1k views

How to put legend outside the plot for a for 2 column plot definition? [duplicate]

I am trying to plot the legend outside a 2 columns 5 rows, but in this MWE 2 rows example in matplotlib. Turns out the legend to "lower center" puts the space between the two plots as well, ...
theprogressor's user avatar
0 votes
0 answers
80 views

How to enable Legend picking with a scatter plot

The following example from the matplotlib doc shows how to make a legend "pickable", such that you can toggle the lines visibility by clicking on their legend: import numpy as np import ...
mocquin's user avatar
  • 464
1 vote
1 answer
228 views

How to customize the handles and labels for a legend

I am trying to customize the ax from matplotlib plot. Here I am using a surpyval package to fit the data and then plot it. The plot method in surpyval package does not accept arguments other than the ...
A.E's user avatar
  • 1,013
-1 votes
1 answer
41 views

How can I give different labels? [duplicate]

I'm comparing the solutions of differential equations using two methods of solving: the analytical and numerical solutions. I would like to label to solid lines with 'Analitical Solution', the dotted ...
Nattan José's user avatar
1 vote
0 answers
89 views

Customizing heatmap colorbar and adding legend

On my heatmap using Matplotlib to display different scores of animals across different days, X-axis represents days, Y-axis animal ID's, and the value in each cell signifies score. Time points with no ...
Rakshith Kumar's user avatar
0 votes
2 answers
305 views

How to add legend when using twinx

I am trying to plot 2 values with same x axis values (time) but different y axis values. I am trying to add legend to the plot, however, I keep getting 2 legends for the same variable instead of one ...
Nouredin Modl's user avatar
0 votes
1 answer
258 views

Duplicated labels in the legend of Seaborn histplot

I am trying to generate a combined histplot with two datasets together with the following codes _,bins = np.histogram([150, 600], bins=30) alpha = 0.4 fig, ax = plt.subplots(1,1) sns.histplot(df1['...
zzrrhhh's user avatar
  • 11
0 votes
0 answers
35 views

Pyoncoprint (matplotlib) legend not showing disappeared ty[es

I'm using such a marker from the example file of the package PyOncoprint: rom matplotlib.patches import Polygon, Rectangle mutation_markers = { "Amplification": dict( marker=&...
Zhihan Zhang's user avatar
0 votes
1 answer
29 views

custom legend function for matplotlib chart

Right now when I have dual y-axis and I want to have one legend box for both of my labels I do the following: fig, ax = plt.subplots(1,2) ax0=ax[0].twinx() line1=ax[0].plot([1, 2, 3], [4, 5, 6], 'b', ...
user20856754's user avatar
0 votes
1 answer
20 views

No colours in legend when using zero handlelength with colours from a colourmap

I'm trying to plot multiple lines, using the colours from the viridis colourmap. I want to set the handlelength=0 in the legend, and when I do, the legend is now totally blank. If I don't mess around ...
Steven Thomas's user avatar
0 votes
2 answers
247 views

Legend in a specific format

I am plotting a graph with a legend using the following command: K = [1e3,1e4] plt.plot(x[:len(y1)], y1, 'o', label=f'Simulation ($K_L$={K[i]:0e})') which produces the following graph: But I want ...
KeplerNick123's user avatar
0 votes
1 answer
53 views

Can anyone advise on how to apply custom ordering of a legend for pywaffle?

I understand that pywaffle accepts parameters of matplotlib.pyplot.legend in a dict. I'm not really across how to apply these parameters to generate a legend with a custom order of categories. Can ...
epidemiologistseekshelp's user avatar

15 30 50 per page
1
2 3 4 5
21