Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas DataFrame step plot: where="post"

I am wondering how I can pass matplotlibs where="post" into a pandas plot.

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(36, 3))
df.plot(drawstyle="steps", linewidth=2)

# this doesn't work
df.plot(drawstyle="steps", where='post')

Does anyone know how to realize this?

Thanks in advance!

like image 610
Cord Kaldemeyer Avatar asked Jan 28 '16 16:01

Cord Kaldemeyer


2 Answers

You just need to specify drawstyle="steps-post":

df = pd.DataFrame(np.random.randn(36, 3))
df.plot(drawstyle="steps", linewidth=2)
df.plot(drawstyle="steps-post", linewidth=2)

Compare the result:

enter image description here

enter image description here

like image 51
CT Zhu Avatar answered Nov 04 '22 20:11

CT Zhu


Why not just use a matplotlib plot? Click here for an example.

from matplotlib import pyplot as plt
plt.step(range(len(df.index)),df[0],where='post')
plt.step(range(len(df.index)),df[1],where='post')
plt.step(range(len(df.index)),df[2],where='post')

enter image description here

like image 32
Charlie Haley Avatar answered Nov 04 '22 19:11

Charlie Haley