Pandas DataFrame step step: where = "post"

I am wondering how I can pass matplotlibs where = "post" to the pandas chart.

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 implement this?

Thanks in advance!

+4
source share
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

+11
source

Why not just use the matplotlib chart? 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

0
source

Source: https://habr.com/ru/post/1626403/


All Articles