0

I am trying a quite simple exercise: plotting some data with y-errorbars using python/seaborn. The data is stored in a pandas.DataFrame looking like this (note: lateron I will use "xname" for "limitcount":

DataFrame content

The code looks as follows:

sns.set_context('paper')
sns.set_style('ticks')
sns.pointplot(data=pands_dataframe, x='xname', y='mean')
plt.errorbar(x='xname', y='mean', yerr='variance', data=pands_dataframe)
plt.show()

This results in the following - I see two plots, the one with error bars is to the left (error bars are very small):

Example plot

What am I doing wrong?

WolfiG
  • 1,059
  • 14
  • 31
  • 2
    Welcome to Stack Overflow! Please take a moment to read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask). You need to provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) that includes a toy dataset (refer to [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples)) – Diziet Asahi Oct 01 '20 at 13:04
  • Your variances seem to be very small. You could try to exaggerate them as `yerr=pands_dataframe['variance']*10` – JohanC Oct 01 '20 at 14:47
  • Take note of the text in [the docstring](https://seaborn.pydata.org/generated/seaborn.pointplot.html): "This function always treats one of the variables as categorical and draws data at ordinal positions (0, 1, … n) on the relevant axis, even when the data has a numeric or date type." – mwaskom Oct 01 '20 at 21:34

1 Answers1

0

For plt, you need to pass the actual data to x and y, do instead of

plt.errorbar(x='xname', y='mean', yerr='variance', data=pands_dataframe)

You want to do:

plt.errorbar(x=pands_dataframe['xname'], 
             y=pands_dataframe['mean'], 
             yerr=pands_dataframe['variance'])
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74