0

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

user6074035
  • 107
  • 1
  • 9
  • 2
    [Does this](https://stackoverflow.com/a/49820775/8881141) answer your question? – Mr. T Oct 25 '20 at 15:36
  • Hi - thanks for your reply. No - I tried it but it doesn't. – user6074035 Oct 25 '20 at 15:55
  • 2
    Why not? What is the problem? Can you reproduce what the thread achieved when labelling horizontal bars? Obviously, we cannot reproduce your problems because you did not provide a [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example) and you do not describe why exactly this approach fails. – Mr. T Oct 25 '20 at 16:09
  • 1
    The solution linked by @Mr.T works for me using the [standard `seaborn` example](https://seaborn.pydata.org/generated/seaborn.barplot.html). If you have tried it and it doesn't work, maybe add the error/improper graph to your output – Tom Oct 25 '20 at 16:16
  • 1
    Guys - my sincerest apologies. I accidentally had copied his original post instead of the update that he posted. Thank you for your help on this. My bad. – user6074035 Oct 25 '20 at 16:21
  • Glad the problem is solved. Maybe it is not even your fault. Somebody "improved" the linked code - but introduced two mistakes. I corrected them there, so maybe you copied the code before I reverted these mistakes. Peace. – Mr. T Oct 25 '20 at 17:02
  • Thanks for your help Mr. T and Tom. Ah - that might explain it. I have the learner plates very much on regarding plotting in Python. Have a nice evening! :) – user6074035 Oct 25 '20 at 17:08

0 Answers0