Python Matplotlib:I不';我不知道我是否';我用正确的方法绘图
当我需要在y轴上绘制2个系列时,我不知道这是否是最好的方法。它适用于线,但不适用于线+条。如果我设置了Python Matplotlib:I不';我不知道我是否';我用正确的方法绘图,python,matplotlib,Python,Matplotlib,当我需要在y轴上绘制2个系列时,我不知道这是否是最好的方法。它适用于线,但不适用于线+条。如果我设置了y2kind='bar',这个序列就会消失索引SM是我的数据帧。代码如下: x = indexesM.index.to_timestamp() y0 = indexesM['cdi t12m'] y1 = indexesM['ipca t12m'] y2 = indexesM['br real yield t12m'] fig, ax = plt.subplots() ax.plot(x, y0
y2
kind='bar'
,这个序列就会消失<代码>索引SM是我的数据帧。代码如下:
x = indexesM.index.to_timestamp()
y0 = indexesM['cdi t12m']
y1 = indexesM['ipca t12m']
y2 = indexesM['br real yield t12m']
fig, ax = plt.subplots()
ax.plot(x, y0, label='CDI')
ax.plot(x, y1, label='IPCA')
ax.plot(x, y2, label='Juro real')
plt.show()
我通过定制来自官方网站的一个示例创建了一个复合图。它使用
ax.bar()
您应该查看plt.bar
import matplotlib.pyplot as plt
data = {'apple': 10, 'orange': 15, 'lemon': 5, 'lime': 20}
names = list(data.keys())
values = list(data.values())
fig, ax = plt.subplots(figsize=(9, 3))
ax.bar(names, values, color='g')
ax.scatter(names, values, color='r', s=30)
ax.plot(names, values, color='b', lw=2)
ax.set_title('Categorical Plotting')
plt.show()