简体   繁体   English

熊猫中的相对数据可视化

[英]Relative data visualization in pandas

I have some data as follows: 我有一些数据,如下所示:

+---------+-------+---------+----------------+
| Machine | Event | Outcome | Duration Total |
+---------+-------+---------+----------------+
| a       |     1 | FAIL    |           1127 |
| a       |     2 | FAIL    |          56099 |
| a       |     2 | PASS    |          15213 |
| a       |     3 | FAIL    |          13891 |
| a       |     3 | PASS    |          13934 |
| a       |     4 | FAIL    |           6844 |
| a       |     5 | FAIL    |           6449 |
| b       |     1 | FAIL    |          21331 |
| b       |     2 | FAIL    |          30362 |
| b       |     3 | FAIL    |          12194 |
| b       |     3 | PASS    |           7390 |
| b       |     4 | FAIL    |          35472 |
| b       |     4 | PASS    |           7731 |
| b       |     5 | FAIL    |           7654 |
| c       |     1 | FAIL    |          16833 |
| c       |     1 | PASS    |          21337 |
| c       |     2 | FAIL    |            440 |
| c       |     2 | PASS    |          14320 |
| c       |     3 | FAIL    |           5281 |
+---------+-------+---------+----------------+

I'm trying to make a categorical scatter plot of total duration of each event and each machine. 我正在尝试绘制每个事件和每台机器的总持续时间的分类散点图。 Or any other visualization to analyze them relatively. 或任何其他可视化工具来对其进行相对分析。

What would be a good choice and how to go about it? 什么是一个好的选择,以及如何去做?

import matplotlib.pyplot as plt
import seaborn as sns

sns.catplot(x = 'Event', y = 'Duration', hue = 'Machine', col = 'Outcome', data = df)

Give this a try, its two scatter plots. 试试看,它的两个散点图。 X axis is the event, y axis is Duration, color of the dots is based on the machine, and there is two graphs, one for fail and next to it is another for pass. X轴是事件,y轴是持续时间,点的颜色基于机器,并且有两个图形,一个图形表示失败,另一个图形表示通过。 "df" is your dataframe. “ df”是您的数据框。 You can remove col = 'Outcome' to have both Fail and Pass on the same graph. 您可以删除col = 'Outcome'以在同一图表上同时显示Fail和Pass。

EDIT: 编辑:

fig, ax = plt.subplots(figsize = (10,10))
g = sns.scatterplot(x = 'Event', y = 'Duration', hue = 'Machine', data = df[df['Outcome'] == 'PASS'], ax = ax)
g = sns.scatterplot(x = 'Event', y = 'Duration', hue = 'Machine', data = df[df['Outcome'] == 'FAIL'], ax = ax, 
                    style = 'Machine', markers = ['x', 'x', 'x'])

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, ['Machine - Pass', 'a' ,'b', 'c', 'Machine - Fail', 'a','b','c'])

plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM