Skip to main content

All Questions

Tagged with
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
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
38 views

Custom colored lines in matplotlib but legend won't update

I am trying to plot lines out of a pandas dataframe, a pivot table of my data. There's 12 lines, one for each month of the year, and I don't want any duplicate colors. So I decided to set the colors ...
user21551428's user avatar
0 votes
1 answer
293 views

Legend doesn't show up in Plotly Express line subplots

There are several answers for showing the legend if you're using plotly.graph_objs. I'm only using plotly_express though, and can't get the legend to show up when using several subplots. I have the ...
Jakob's user avatar
  • 843
0 votes
2 answers
149 views

How can I insert png symbol into web map legend with folium-python 3

This code is part of other big code that generate a web map with folium module: legend_html = ''' <div style="position: fixed; bottom: 40px; left: 50px; width: 100px; height: 110px;...
newGIS's user avatar
  • 618
0 votes
1 answer
175 views

Adjust spacing between 2 markers of same line displayed in the legend of matplotlib plot

I am plotting 2 markers of the same line using the following code and I want to adjust the spacing between two markers in the legend. Code : ref. import matplotlib.pyplot as plt from matplotlib....
Natasha's user avatar
  • 1,431
0 votes
1 answer
60 views

Unable to visualize legend correctly in matplotlib

I am trying to visualize this graph with a lineplot, but the legend is not working correctly as you can see in the image below. The problems are three: two rectangles appear in the second and fourth ...
Francis's user avatar
1 vote
1 answer
5k views

How to change the size of legend box in Plotly?

It is my code below: import plotly.graph_objects as go fig = go.Figure() for i in range(100): fig.add_trace(go.Scatter( x=[1,2], y=[1,2], name = f'{i}'*20, ...
ChienHua's user avatar
1 vote
0 answers
959 views

Legend in an image generated by OpenCV (Python)

I'm plotting an image with the following code: cv2.imshow('',I) cv2.circle(I,tuple(xy),radius=1,c=(255,0,0),thickness=1) cv2.circle(I,tuple(uv),radius=1,c=(0,0,255),thickness=1) Is it possible to add ...
yonatan's user avatar
  • 133
0 votes
1 answer
608 views

GeoPandas | Legend not showing

Goal: Show legend I've set legend=True and no difference was made. for i in list(range(NUM_SLIDES)): d = {'col1': ['Foo', 'Bar', 'Sue'], 'geometry': [foo[i], bar[i], sue[i]]} gdf = gpd....
DanielBell99's user avatar
  • 1,541
0 votes
0 answers
210 views

How to map colors from multiple matplotlib subplot pie charts to a single figure legend

So I have been trying to get a legend working for a figure with multiple subplots that contain pie charts. The pie charts can contain any number of manufactures from a set list of manufacturers, but ...
Kgrover3's user avatar
2 votes
1 answer
457 views

Need legend to communicate color for plotly graph go.Heatmap

I'm having a bit of trouble trying to figure out how to have the legend indicate color for my plotly graph objects heatmap. The legend only needs to communicate the graph colors and what they mean. ...
IDK's user avatar
  • 161
0 votes
2 answers
701 views

Matplotlib: display legend keys for lines as patches by default

For background, see the legend guide. I want to display legend keys for Line2D objects as Patches (with the same color and label), by default. What is the cleanest way to do this? I tried using ...
user76284's user avatar
  • 1,329
2 votes
1 answer
326 views

Add legend to mplot3d

For the 3D plot given here (thanks to Redox for his elegant solution posted here): how to go about adding the legend? I tried ax.legend() but got the message No artists with labels found to put in ...
Joe's user avatar
  • 367
1 vote
1 answer
1k views

Plotly Custom Legend

I have a plotly plot which looks like this: The Code I am using is below: fig = make_subplots(specs=[[{"secondary_y": True}]]) fig.add_trace(go.Scatter( x = pf['Timestamp'], y = pf['Price_A'...
Imran's user avatar
  • 71
0 votes
0 answers
387 views

Find best coordinates in PIL image for insert rectangular image

I edited this post in order to ask a more clear question. Starting from a figure plot generate by Matplotlib like this : Bitmap data is returned by a function: from PIL import Image from matplotlib ...
F48R1's user avatar
  • 37
0 votes
1 answer
107 views

Removing legend duplicates leaves unmatched colors between the legend and the lines (matplotlib, python)

I have multiple .dat files looking like this: first file and second file . Firstly, I used this code: z_bins = 541 h_bins = 65 for nr in [1,2]: array = [] profile = "file_{}.dat"....
HungryMolecule's user avatar
0 votes
1 answer
553 views

How to plot every label once in matplotlib legend with corresponding color? [duplicate]

How can I only show a name once in the legend with corresponding color instead of index? data = {'x':[0, 1, 2, 3, 4], 'y':[4, 3, 2, 1, 0], 'Name':['Tom', 'Nick', 'Tom', 'Nick', 'Emma']...
JonnDough's user avatar
  • 887
-2 votes
1 answer
136 views

Adding a Legend to Pandas Scatterplot

I am using the Pandas version of Scatter, not Matplotlib. How would I add a legend to this graph based on the colors?
325's user avatar
  • 596
0 votes
1 answer
298 views

Hiding Bokeh glyphs based on categorical data with color_mapper

Currently i found a way of plotting my categorical data by using the color_mapper and the legend_field variable. My data look the following way: df_plot x y category 0 91....
Maxi Trien's user avatar
0 votes
1 answer
3k views

How to set markers with errorbars in different colours?

How to: display symbols in the legend colour markers in the same way as the errorbars (argument color gives an error: ValueError: RGBA sequence should have length 3 or 4 remove connecting lines - get ...
Elena Greg's user avatar
  • 1,125
0 votes
0 answers
118 views

How to add a legend according to colors?

How to add a legend according to colors? I looked at this question, but I got an error about handles. What is wrong, please? import matplotlib.pyplot as plt import pandas as pd fig, ax = plt.subplots(...
Elena Greg's user avatar
  • 1,125
0 votes
0 answers
941 views

Fancybox is not working. What am I doing wrong?

I was following an example from Python Data Science Handbook which is plotting a simple graph. Its supposed to use fancybox on labels but it is not working as per the example. The code is: x = np....
omsinghml's user avatar
1 vote
1 answer
1k views

Plotly - clicking on legend items - how to make an initial setting?

When someone clicks on a legend item, it becomes grey, and the data disappears, for instance, here. It is possible to set that an item from a legend will be grey after opening the .HTML output and ...
Elena Greg's user avatar
  • 1,125
1 vote
0 answers
78 views

Matplotlib legend shows two same colors for a different data

I would like to make a function that generate plots for different dataset. My idea is to make list of bank for the function to generate each bank's credit growth or loan to funding ratio. However, ...
najmaashrawi's user avatar
2 votes
1 answer
724 views

Plotly: group trace in legend and removing horizontal labels

I'm using Plotly to produce a similar graph from https://plotly.com/python/horizontal-bar-charts/, section "Color Palette for Bar Chart". Here's the code, based on the reference link, but ...
user188439's user avatar
-1 votes
1 answer
233 views

Issue with Label in Stacked Bar chart in Matplotlib from a Pandas Dataframe

I have a Dataframe with a column (say 'Col') with values either from this list ['PO101','NI101','NE101']. Count is: PO101 = 30000 NI101 = 5000 NE101 = 3000 I am trying to show how many are which on ...
Veki's user avatar
  • 541
0 votes
1 answer
46 views

Scatter plot legend with respect to colour [Python3]

I have this MWE of six points to plot: import matplotlib.pyplot as plt plt.scatter(1,2,marker= 'o', color='darkred') plt.scatter(3,5,marker= 'o', color='yellowgreen') plt.scatter(11,21,marker= 'o', ...
Siderius's user avatar
  • 194
1 vote
1 answer
169 views

How to add legend with labels of IDs to my code

I have the electricity consumption of 25 houses, and Im doing K-Means clustering on the dataset that holds those houses. After importing the dataset, pre-processing it, and applying K-Means with K=2, ...
Aghyad Skaif's user avatar
0 votes
0 answers
146 views

Remove Inexplicable Black Line In Matplotlib Legend

I am using the following code to generate a legend in a separate file. Unfortunately there is a black line in the middle of the legend that has been generated. In the middle of 'permissions ...
dipl0's user avatar
  • 1,067
0 votes
1 answer
371 views

Prevent Matplotlib Legend from smushing h-padding on vertical subplots?

I have a script where I am plotting several variables in a grid of 5x1. I have noticed that when I have data that makes my legend shorter, the subplots themselves have an acceptable height and ...
dylanjm's user avatar
  • 2,081
0 votes
1 answer
93 views

How to make a legend in a plot?

I am unable to figure out a way to get a legend of my plot. My data is a data frame consisting of 3 columns x, y and z. x and y represent the co-ordinates of a point and z is the label(0,1,2,3) that ...
Akhilesh Sharma's user avatar
0 votes
1 answer
175 views

Error when drawing a legend on a separate plot

I want to plot a legend on a separate frame than the original plot. I can plot the legend from plot commands. But not the legend from fill_between. Here is a sample code #!/usr/bin/env python import ...
Marti's user avatar
  • 69
0 votes
1 answer
628 views

Plotly legends on subplot position

I would like to put legends on subplot position. Is there any solution? It will be great if you can provide any type of suggestions. You can find the code here: https://github.com/sjshtura/EWL-DUE/...
Advut's user avatar
  • 117
1 vote
1 answer
186 views

Displaying row sum in a secondary colorbar while plotting matrix

I'm plotting a matrix using matshow. I have an array sum = np.sum(A, axis=0) I'd like to display the values stored in sum as a secondary legend. import numpy as np import matplotlib.pyplot as plt ...
Natasha's user avatar
  • 1,431
1 vote
0 answers
112 views

Matplotlib Legend and colormaps from panda dataframes

I am trying to plot some graphs with Python. Specifically I am working with dataframes. I would like to know how to do the next couple of things: Adapt the legend of the plots using the correspondant ...
felixpradoh's user avatar
0 votes
0 answers
105 views

How to plot legends for all (only 4) types of value in a 2D array using matplotlib?

I have a 2-D array where each value is either of 0,1,2,3 and I am plotting it like: array = two_d_array #two_d_array is a numpy 2-D array plt.imshow(array) This gives me a plot where each pixel is ...
Sulphur's user avatar
  • 574
2 votes
1 answer
136 views

How to plot the legend of this graph of which there are many functions?

I have a matrix X contains only 1 row that serves as an input. I have a matrix Y of which each row serves as an output of a function. If Y has 5 rows, then we have 5 different functions. I plot all ...
Akira's user avatar
  • 2,780
1 vote
1 answer
284 views

I want to make an automatic legend in seaborn, but it doesn't work

I want to make an automatic legend in seaborn, but it doesn't work. How can I generate the legend automatically? plt.figure(figsize=(15, 10)) sns.pointplot(data=tmp_hs_df, x="Geographic Area", y="...
dahuin's user avatar
  • 77
0 votes
2 answers
1k views

How to change the location of a legend in seaborn countplot? [duplicate]

There is the following code which produces a countplot with seaborn and annotating the precentage: ax = sns.countplot(y=target_column, data=data, hue=target_column) plt.title(f'Distribution of {...
KaliTheGreat's user avatar
0 votes
0 answers
205 views

Subplot legend showing wrong colors [duplicate]

I am a bit surprised by plot legends color assignment. I am plotting values and assigning a color in loop. The code is pasted below. import matplotlib.pyplot as plt angles2plot = [0.5, 1.0, 2....
Vinod Kumar's user avatar
  • 1,562
2 votes
1 answer
3k views

matplotlib legend based only on line style but not color

I am plotting values of two metrics for two different algorithms in different style and colors in a single plot. I use different styles for different algorithms and different colors for different ...
Shew's user avatar
  • 1,606
18 votes
1 answer
29k views

Sharing same legends for subplots in plotly

I've two plots created in the same figure using subplots in plotly. import plotly.graph_objects as go import numpy as np import pandas as pd from plotly.subplots import make_subplots df = pd....
Natasha's user avatar
  • 1,431
2 votes
1 answer
170 views

How to modify scatter-plot figure legend to show different formats for the same types of handles?

I am trying to modify the legend of a figure that contains two overlayed scatter plots. More specifically, I want two legend handles and labels: the first handle will contain multiple points (each ...
user avatar
1 vote
0 answers
94 views

Legend for marker size

I'm trying to but legend for marker size in Sccater plot there is some plot to describe what I want ( See Prediction Cost on the right ) Plot With Legend for marker size I did all what I want ...
Abdulwahabdev's user avatar
0 votes
1 answer
328 views

How to add two different labels to legend for an overlap plot using matplotlib in python?

Okay this might be easy even I search on web but could not get it. Basically i want to add the two different labels to my plot and this is my line of code for that plt.plot(x[:,1],y,'ro',x[:,1],...
Anil Sarode's user avatar
2 votes
3 answers
1k views

Python matplolib legend how to reduce distance between frame left edge and markers

As question suggests, I'm trying to reduce the distance between the left edge of the legend frame and the markers. In figure there is the current plot. I would like to find a way to: keeping the ...
Giuseppe Angora's user avatar
0 votes
1 answer
157 views

Solution for scatter legend of subplots

I have a problem i can´t handle. I tried several things but its not working. Or at least I am to dumb to get the solution idk. T create subplots with a for loop and every time create it with data ...
Hendrx's user avatar
  • 5
10 votes
2 answers
31k views

How to position legends inside a plot in Plotly

I have got this code from Plotly page. I need to make the background transparent and the axis highlighted. And also the legends positioned inside the plot. import plotly.graph_objects as go fig = go....
Leolime's user avatar
  • 317
3 votes
1 answer
4k views

Suppress WARNING:matplotlib.legend:No handles with labels found to put in legend

Sorry if this has been asked before but all the answers I found didn't work for me. I'm looking for a way to suppress this warning. The context is that I wrote a function that creates a lot of plots ...
rhedak's user avatar
  • 409

15 30 50 per page