【发布时间】:2021-05-18 21:01:35
【问题描述】:
我想将 pandas 数据框绘制为子图。
我读了这篇文章:How can I plot separate Pandas DataFrames as subplots?
这是我的最小示例,就像帖子中接受的答案一样,我使用了 ax 关键字:
import pandas as pd
from matplotlib.pyplot import plot, show, subplots
import numpy as np
# Definition of the dataframe
df = pd.DataFrame({'Pressure': {0: 1, 1: 2, 2: 4}, 'Volume': {0: 2, 1: 4, 2: 8}, 'Temperature': {0: 3, 1: 6, 2: 12}})
# Plot
fig,axes = subplots(2,1)
df.plot(x='Temperature', y=['Volume'], marker = 'o',ax=axes[0,0])
df.plot(x='Temperature', y=['Pressure'], marker = 'o',ax=axes[1,0])
show()
很遗憾,索引有问题:
df.plot(x='Temperature', y=['Volume'], marker = 'o',ax=axes[0,0])
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
拜托,你能帮帮我吗?
【问题讨论】:
-
ax=axes[0]和ax=axes[1] -
解决了。感谢您的快速回答
标签: python pandas matplotlib