This question already has answers here:
How to annotate horizontal bar plots with count and percent
(1 answer)
How to display the value of the bar on each bar with pyplot.barh()
(11 answers)
Horizontal stacked bar plot and add labels to each section
(3 answers)
how to add labels to a horizontal bar chart in matplotlib?
(1 answer)
Closed last year.
What can I add to this code to display Bar Graph Numbers?
plt.barh(regionTotal['WHO Region'],regionTotal['Confirmed'])
plt.title('Region Total Confirmed Cases')
plt.xlabel('Region')
plt.ylabel('Confirmed Cases')
plt.show()
Related
This question already has answers here:
How to plot and annotate a grouped bar chart
(1 answer)
Labeling a Bar Graph Created from a Grouped Pandas DataFrame where there's a NaN Category
(2 answers)
Plot groupby percentage dataframe
(2 answers)
How to annotate grouped bar plot with percent by hue/legend group
(1 answer)
Closed 11 days ago.
Is is possible to add bar values to a pandas groupby plot?
df.groupby("Responded Year-Month")["Net New Record"].value_counts().unstack(level=1).plot.bar(
stacked=True,
title="Responses by Month & Net New Record",
ylabel="Responses",
xlabel="Month",
rot=0,
color=nnr_colors)
I checked the docs and could not find any reference of values in the bars both the df.plot.bar docs and the df.plot docs.
As an example, it is very easy to accomplish something similar with a pie plot using autopct:
df.groupby("Channel")["Responded"].sum().plot.pie(
autopct='%1.0f%%',
title="Responses by Channel"
)
This question already has answers here:
Trying to add color gradients to Matplotlib chart
(1 answer)
Python: Barplot colored according to a third variable
(1 answer)
Changing color scale in seaborn bar plot
(5 answers)
Closed 2 months ago.
I have monthly rain data from a list, where values are on the Y-axis and months on the X-axis.
This is my color palette:
sns.color_palette("crest", as_cmap=True)
This is my code to barplot the data:
plt.figure(figsize=(8,4), tight_layout=True)
colors = sns.color_palette("crest")
plt.bar(bocas_rain['Date'], bocas_rain['Pr'], color=colors)
plt.xlabel('Months')
plt.ylabel('Rain in mm')
plt.title('Rain in Bocas')
plt.show()
The result I am getting is this:
How can I make the highest values of my data match the dark blue colors from the palette?
This question already has answers here:
How to add value labels on a bar chart
(7 answers)
Stacked Bar Chart with Centered Labels
(2 answers)
How to annotate each segment of a stacked bar chart
(1 answer)
Horizontal stacked bar plot and add labels to each section
(3 answers)
Closed 11 months ago.
in the below code, I'm trying to plot stacked bar chart of % of stoke events against the gender variable.
dfgender=df.groupby('gender')['stroke'].value_counts(normalize=True).unstack().fillna(0)
ax=dfgender.plot.bar(stacked=True,colormap='tab10',figsize=(8, 6))
plt.legend(loc="upper right", ncol=1, prop={'size': 8})
plt.title('Gender vs Stroke')
plt.xlabel("Gender")
plt.ylabel("Proportion")
for p in ax.patches:
ax.annotate(round(p.get_height(),2), (p.get_x()+p.get_width()/2, p.get_height()),ha='center',va='center',xytext=(10, 0), textcoords='offset points')
plt.show()
But as you can see, the placement of the bar labels is incorrect. 1 should be 5% and 0 should be 95%. I want the figures to be represented in percentages and be positioned in the center of the bars. Can somebody help me please?
This question already has answers here:
How to set the y-axis limit
(8 answers)
How to automatically set the y-axis limits after limiting the x-axis
(1 answer)
Closed 1 year ago.
I have a graph that has values between 0-40 on the x-axis and 0-20,000 on the y-axis. If I am plotting the graph, this is what I see,
Is it possible to plot the graph only till the points in the axis where data entries fall?
I think you can put limits till where the data could be shown using:
x limit as matplotlib.pyplot.xlim(0, 40) and y limit as matplotlib.pyplot.ylim(0,20000)
This question already has answers here:
No outlines on bins of Matplotlib histograms or Seaborn distplots
(3 answers)
Closed 5 years ago.
df3['a'].plot.hist(color='blue',xlim=(0,1))
I want to know how can it show the line in the histogram figure.
Make the top figure showed as bottom figure. Thank you!
Pass the edgecolor argument to hist.
df3['a'].plot.hist(color='blue',
edgecolor='black',
xlim=(0,1))
Demo
df = pd.DataFrame(dict(vals=np.random.normal(size=100)))
df.plot.hist(edgecolor='black')