Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas plot with errorbar: style does not apply

Tags:

python

pandas

I have Pandas (version 0.14.1) DataFrame object like this

import pandas as pd

df = pd.DataFrame(zip([1,   2,   3,   4,   5],
                      [0.1, 0.3, 0.1, 0.2, 0.4]),
                  columns=['y', 'dy'])

It returns

    y   dy
0   1   0.1
1   2   0.3
2   3   0.1
3   4   0.2
4   5   0.4

where the first column is value and the second is error.

First case: I want to make a plot for y-values

df['y'].plot(style="ro-")

First case

Second case: I want to add a vertical errorbars dy for y-values

df['y'].plot(style="ro-", yerr=df['dy'])

Second case

So, If I add yerr or xerr parameter to plot method, It ignores style.

Is it Pandas feature or bug?

like image 958
dinya Avatar asked Sep 07 '14 12:09

dinya


1 Answers

As TomAugspurger pointed out, it is a known issue. However, it has an easy workaround in most cases: use fmt keyword instead of style keyword to specify shortcut style options.

import pandas as pd

df = pd.DataFrame(zip([1,   2,   3,   4,   5],
                      [0.1, 0.3, 0.1, 0.2, 0.4]),
                  columns=['y', 'dy'])

df['y'].plot(fmt='ro-', yerr=df['dy'], grid='on')

correctly styled figure

like image 58
Sergey Antopolskiy Avatar answered Oct 18 '22 08:10

Sergey Antopolskiy