All Questions
15
questions
2
votes
2
answers
71
views
How to consolidate labels in legend
So, the script below requests data from postgres database and draws a diagram.
The requested data is a table with 4 columns (ID, Object, Percentage, Color).
The data:
result = [
(1, 'Apple', 10, '...
-1
votes
1
answer
150
views
Barplot subplot legend python
Hello everyone how can i make legend for 3 different bar color that code with subplot?
Data frame:
This is my code:
fig,axs = plt.subplots(2,3, figsize=(30,20))
axs[0,1].bar(x = df_7_churn_tenure['...
1
vote
1
answer
773
views
How to align a single legend over two seaborn barplots?
I would like to have a single legend that nicely fits on top of both the subplots (doesn't necessarily need to span the entire width of the plots, but needs to be outside the plot). I know you can ...
0
votes
1
answer
1k
views
How to plot a barplot with different hatch and edge color with legends using matplotlib?
I would like to plot a barplot where bars have a different hatch and edge color using Matplotlib with its proper legends. I tried to plot but I couldn't generate proper legends with this code:
import ...
0
votes
0
answers
78
views
Troubles with pyplot.bar legend
I'm having troubles introducing a legend in this chart. Can someone help me? I can plot the chart but everytime I try to apply a legend it doesn't work..
flags=['0','1','2','3','4','5']
...
2
votes
1
answer
2k
views
How do I make a SINGLE legend using subplots? _get_legend_handles_labels is not working
I want to make a single legend with corresponding colors for the models that are in the individual plots on the whole subplot.
My current code is as follows:
from matplotlib.legend import ...
0
votes
1
answer
316
views
Legend position for figures with variable size
My plot function creates horizontal bars per year for data with different size. I have to change the figure size for each set of subplots.
I need to place my two legends on lower center of each figure ...
0
votes
1
answer
4k
views
Plotting bar charts with a colormap legend
Consider the following:
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
y = np.array([1, 4, 3, 2, 7, 11])
colors = cm.hsv(y / float(max(y)))
plot = plt.scatter(y, y, c = ...
0
votes
2
answers
5k
views
How to turn x-axis values into a legend for matplotlib bar graph
I am creating bar graphs for data that comes from series. However the names (x-axis values) are extremely long. If they are rotated 90 degrees it is impossible to read the entire name and get a good ...
1
vote
2
answers
5k
views
add legend seaborn barplot
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
array = np.array([[1,5,9],[3,5,7]])
df = pd.DataFrame(data=array, index=['Positive', 'Negative'])
f, ax =...
0
votes
1
answer
239
views
How to use the mpatches.Patch in matplotlib to add custom labels to a bar plot
I am trying to manually add legends but they are not showing. I would like to use the matplotlib pathes instead of seaborn hue so that I can control my colours and handle the duplicate products.
Dec =...
24
votes
2
answers
84k
views
matplotlib bar plot add legend from categories dataframe column
I try to add the legend which should, according to my example, output:
a red square with the word fruit and
a green square with the word
veggie.
I tried several things (the example below is just 1 ...
1
vote
2
answers
2k
views
Why do matplotlib legend elements have the same colour?
I am doing a bar plot and adding the legends. The code is the following:
import numpy as np
import matplotlib.pyplot as plt
rectArr = list()
fig, ax_arr = plt.subplots(nrows=2, ncols=1, figsize=(8,8),...
2
votes
1
answer
427
views
How to create two legend objects for a single plot instance?
I use the following example code to generate a bar plot.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 5, 5)
y = np.exp(x)
w = x[1] - x[0]
colors = ['blue' if idx % 2 == 0 ...
8
votes
1
answer
13k
views
Pandas stacked bar chart duplicates colors for large legends
I need to create a stacked bar chart with a large number (10 or so) categories. The problem is that Pandas only provides colors for up to 7 different categories. It sets the remaining colors as blue. ...