首页 > 解决方案 > Adding total values to seaborn plot python

问题描述

I have a Seaborn plot in Python to map the total values for a response to a survey. I am happy to post more of the code if needed but the plot is just using 2 columns from a Pandas Dataframe - country and total - and plotting these.

# Initialize the matplotlib figure
f, ax = plt.subplots(figsize=(10, 6))

# Plot the total by country 
sns.set_color_codes("colorblind")
sns.barplot(x="Total", y=top_10_countries.index, data = top_10_countries, label="Total")

# Add a legend and informative axis label
ax.legend(ncol=2, loc="lower right", frameon=True)
ax.set(ylabel="", xlabel="Respondents by country")

What I want to do is add on the end of each of the countries what the actual total is, i.e. on the end of the bar for the USA, I want to add 820, add 180 on UK, and so on.

Is this possible?

Below is the plot I have at the moment: enter image description here

标签: pythonplotseaborn

解决方案


推荐阅读