python - 如何在 matplotlib 中针对特定事件时间绘制类别
问题描述
假设您有 python 字典,它描述了在特定活动期间不同时间发生的“事件”。
activity = {
"start_time":"2018-09-05 06:30:53.242",
"end_time":"2018-09-09 09:30:53.242",
"eventType1":[
{
"event_pos":123,
"event_time":"2018-09-05 06:50:53.242",
"message":"blah"
},
{
"event_pos":125,
"event_time":"2018-09-05 07:50:53.242",
"message":"type1 event blah"
}
],
"eventType2":[
{
"event_pos":18,
"event_time":"2018-09-05 06:40:58.242",
"message":"type2 event1"
},
{
"event_pos":700,
"event_time":"2018-09-05 08:59:58.242",
"message":"type2 event2"
}
]
}
我的意图是在图表和/或表格中可视化这一点。最初我将此转换为一个表,前两行是开始和结束,事件实例、消息和时间作为后续行。
问题是事件可以重复,并且因为它们可以重复消息被重复(以毫秒为频率)。因此,后续事件列表可以非常迅速地增长,并且重复消息仅相隔几毫秒。这使得表格变得丑陋、难以阅读。
同时我所做的是通过消息获取事件的唯一实例,并显示每个事件消息的发生次数。这会清理一切,但这些事件发生的位置的视觉效果也很有用。
我的目标:
根据类别创建事件时间线。
- 将 ay 轴设为 [eventType1、eventType2、eventType3 等...]
- 将 x 轴作为活动持续时间的日期时间
- 水平标记每个事件的属性(可能将消息水平放置在标记上,尽管我觉得这也会很混乱)
我试过的:
关注这篇文章——> Matplotlib 时间线
但是我无法将类别(eventTypes)作为y轴,将python日期时间作为x轴。我转换为 matplotlib 日期时间字符串,但经常出现以下问题:
ValueError: x and y must have same first dimension, but have shapes (20,) and (2,)
问题:
- 当事件具有元数据(如消息和事件位置)时,如何在 matplotlib 中针对特定事件时间绘制类别
- 有没有更好的方法来可视化这种类型的数据?我愿意接受建议。
解决方案
推荐阅读
- html - 如何在柔性显示中居中图像?
- amazon-web-services - 即使在添加 ICMP 入站规则后也无法 PING EC2 实例
- python - 使用 sqlalchemy 从 Python 连接 MySQL,mysql+mysqldb 适用于 Windows+Ubuntu 但不适用于 RHEL
- php - sitemap_index.xml 正在重定向到 404 页面
- swift - Xcode 问题 AppDelegate 与 Firebase - 'NSPersistentCloudKitContainer'
- contiki-process - 如何在节点之间共享数据
- linux - 如何处理一行bash命令中的多个引号?
- scala - Spark / Scala - RDD填充最后一个非空值
- sql - 想要在使用聚合函数时添加第三列,不属于 group by
- html - Django 并排显示 2 个表格