Pandas DataFrame步骤图:where =“post”

时间:2022-01-18 05:38:12

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

我想知道我怎么能把matplotlibs =“post”传递给熊猫情节。

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!

提前致谢!

2 个解决方案

#1


14  

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

你只需要指定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:

比较结果:

Pandas DataFrame步骤图:where =“post”

Pandas DataFrame步骤图:where =“post”

#2


0  

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

为什么不使用matplotlib图?点击这里查看示例。

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')

Pandas DataFrame步骤图:where =“post”

#1


14  

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

你只需要指定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:

比较结果:

Pandas DataFrame步骤图:where =“post”

Pandas DataFrame步骤图:where =“post”

#2


0  

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

为什么不使用matplotlib图?点击这里查看示例。

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')

Pandas DataFrame步骤图:where =“post”