通过向plot
的y
参数提供列名列表,可以一次绘制多个列.
df.plot(x="X", y=["A", "B", "C"], kind="bar")
这将生成一个图形,其中条形图彼此相邻.
为了使它们重叠,需要多次调用plot
,并将要绘制的轴作为参数ax
提供给绘图.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
y = np.random.rand(10,4)
y[:,0]= np.arange(10)
df = pd.DataFrame(y, columns=["X", "A", "B", "C"])
ax = df.plot(x="X", y="A", kind="bar")
df.plot(x="X", y="B", kind="bar", ax=ax, color="C2")
df.plot(x="X", y="C", kind="bar", ax=ax, color="C3")
plt.show()