【发布时间】:2019-12-31 18:41:33
【问题描述】:
我是 Python 的初学者,我正在使用 Matplotlib 和 Pandas 创建堆积面积图(例如 https://python-graph-gallery.com/251-stacked-area-chart-with-seaborn-style/)。不幸的是,它不起作用。我有以下包含数据的文件:
现在我需要存储每一列的值,为此我使用以下命令:
ts_1 = wind_data.Building_1;
ts_2 = wind_data.Building_2;
ts_3 = wind_data.Building_3;
ts_4 = wind_data.Building_4;
ts_5 = wind_data.Building_5
y= [ts_1, ts_2, ts_3, ts_4, ts_5];
如果我现在在上面示例链接的命令中使用它:
# library
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Data
x=range(1,6)
# Plot
plt.stackplot(x,y, labels=['A','B','C'])
plt.legend(loc='upper left')
plt.show()
我收到一条错误消息。我认为问题在于,当我读取变量 ts_1 中的单个列时,我并没有单独获得值,我还获得了索引,正如您在这张图片中看到的那样:
如果我只能将值存储在没有索引的列的变量中,我希望我可以创建堆栈图。我该怎么办?
编辑:jupyter 尝试合并 YOLO 的 cmets 的屏幕截图:
这里是样本数据集:
Building_1 Building_2 Building_3 Building_4 Building_5
7.04 7.04 7.04 7.04 7.04
6.36 6.36 6.36 6.36 6.36
6.4 6.4 6.4 6.4 6.4
6.1 6.1 6.1 6.1 6.1
5.88 5.88 5.88 5.88 5.88
6.18 6.18 6.18 6.18 6.18
6.16 6.16 6.16 6.16 6.16
5.82 5.82 5.82 5.82 5.82
5.28 5.28 5.28 5.28 5.28
4.82 4.82 4.82 4.82 4.82
4.18 4.18 4.18 4.18 4.18
4.02 4.02 4.02 4.02 4.02
4.08 4.08 4.08 4.08 4.08
4.24 4.24 4.24 4.24 4.24
6.24 6.24 6.24 6.24 6.24
8.44 8.44 8.44 8.44 8.44
8.72 8.72 8.72 8.72 8.72
8.06 8.06 8.06 8.06 8.06
7.16 7.16 7.16 7.16 7.16
6.52 6.52 6.52 6.52 6.52
7.16 7.16 7.16 7.16 7.16
7.88 7.88 7.88 7.88 7.88
8.44 8.44 8.44 8.44 8.44
8.56 8.56 8.56 8.56 8.56
【问题讨论】:
-
首先,看起来
y是一个对象列表,而不是整数-其次,我相信您需要编辑数据以制作面积图-您在使用什么@ 987654336@ 值? -
感谢您的回答 Datanovice。如何将 y 更改为整数列表?数据本身适用于面积图。我可以用 Excel 轻松做到这一点。我仍然认为问题在于,数据变量 ts_1, ts_2 ...additinally 包含索引
标签: python pandas matplotlib seaborn