python - Matplotlib:如何在 matplotlib 上使用列作为数据分割?
问题描述
我有一个关于 matplotlib 的问题。
我有一张这样的桌子。
data = pd.Dataframe(alldata)
print(data)
index | id | type | date | value |
---------------------------------------
0 | 1 | apples | 01-01-15| 100.00|
0 | 1 | apples | 01-01-16| 100.10|
0 | 1 | apples | 01-01-17| 100.15|
0 | 2 | bananas | 01-01-15| 100.00|
0 | 2 | bananas | 01-01-16| 100.05|
0 | 2 | bananas | 01-01-17| 100.06|
0 | 3 | grapes | 01-01-15| 100.00|
0 | 3 | grapes | 01-01-16| 100.20|
0 | 3 | grapes | 01-01-17| 100.40|
我的意图是在 x = 日期和 y = 值上绘制折线图,而是只创建一条线。我想创建 3 条线,使用“类型”作为参数,将一条线与另一条线进行比较。
我试图划分我的数据,如下所示:
x = data['data']
y1 = data['value'][data.type == 'apples']
y2 = data['value'][data.type == 'bananas']
并创建一个情节,如..
plt.plot(x,y1)
plt.plot(x,y2)
但它没有奏效。
如何在 matplotlib 上对特定参数使用数据分割?
多谢!
解决方案
推荐阅读
- ansible - 我们如何提示一些标签?
- rx-java - 使用 Vert.x 和 RxJava 读取行
- numpy - 使用 keras 和预训练的 pspnet50 进行图像分割
- firebase - 使用 Google Domains 托管 Firebase:mydomain.com 有效,www.mydomain.com 无效
- graphviz - 两个子图中的相同节点
- php - 代码问题不起作用,不确定我的语法是否关闭或我遗漏了什么
- python - AttributeError:“函数”对象在 Pytest Mock 中没有属性
- css - 悬停时转换比例按钮(引导程序)
- mysql - 方法 Illuminate\Database\Eloquent\Collection::paginate 不存在。”
- ios - 是否可以在 UICollectionViewCell 中设置 Swift UI 视图?