python-3.x - Python - 基于其他列中的文本绘图
问题描述
我在 DataFrame df1 中有如下数据
time duration status
10:45:00 12 Ok
11:45:00 22 Ok
12:45:00 10 Failed
13:45:00 42 Ok
14:45:00 32 Failed
使用 Matplotlib,我可以使用绘制前两列的图表
df1.plot(y='duration',figsize=(20,10))
plt.show()
现在,当状态为“失败”时,我想在红十字 (X) 中显示该点,而当状态为“正常”时则不显示任何内容
这可以使用matplotlib来实现吗?
解决方案
这是一种方法
fig, ax = plt.subplots()
df1.plot(y='duration',figsize=(8,5), ax=ax)
df1[df1["status"]=="Failed"].plot(marker='x', linestyle='None', color='r', legend=False, markersize=20, ax=ax)
这是另一种方式
fig, ax = plt.subplots()
df1.plot(y='duration',figsize=(8,5), ax=ax)
xvals = np.where(df1["status"]=="Failed")[0]
ax.scatter(xvals, df1[df1["status"]=="Failed"]["duration"].values, marker='x', s=100, c='r')
plt.show()
推荐阅读
- python - 使用 opencv 和 MTCNN 进行人脸检测
- sql - 在 PL/SQL 中删除整列中的第一个字符
- javascript - 如何在 A-frame 中实现 Agora.io 直播
- javascript - 在启用 ES6 模块的情况下从 Node.js 执行 Powershell 脚本
- python - 有没有办法在写入之前告诉在 Azure Data Lake Storage Gen1 中将 Spark Dataframe 保存为 Delta Table 时将创建多少个文件?
- db2 - Db2 v12 z/OS 密码哈希表
- php - 扩展后在php中创建zip文件后出现奇怪的字符
- java - 为什么 compose() 需要显式转换而 andThen() 不需要?
- cuda - CUDA C++ 中的平滑卷积
- c# - NTLM 身份验证始终以 401 结尾