python - 如何在 Seaborn barplot Python 中根据名称为单个条着色
问题描述
我有以下数据框产生以下情节:
# Import pandas library
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# initialize data
data = [['tom', 10,1,'a'], ['matt', 15,5,'a'], ['Nick', 14,1,'a']]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'Attempts','Score','Category'])
print(df.head(3))
Name Attempts Score Category
0 tom 10 1 a
1 matt 15 5 a
2 Nick 14 1 a
# Initialize the matplotlib figure
sns.set()
sns.set_context("paper")
sns.axes_style({'axes.spines.left': True})
f, ax = plt.subplots(nrows=3,figsize=(8.27,11.7))
# Plot
sns.set_color_codes("muted")
sns.barplot(x="Attempts", y='Name', data=df,
label="Total", color="b", ax=ax[0])
sns.scatterplot(x='Score',y='Name',data=df,zorder=10,color='k',edgecolor='k',ax=ax[0],legend=False)
ax[0].set_title("title")
plt.show()
我想以Nick
不同的颜色(例如红色)突出显示条。是否有捷径可寻?
解决方案
推荐阅读
- javascript - Angular - 拒绝应用 Cropperjs 的样式和脚本
- azure-devops - 我得到 ##[error]No code coverage results were found to publish。尝试在 Azure DevOps 中发布我的 create-react-app 代码覆盖率时
- r - 使用离散化后分类变量级别的标签
- javascript - 在不触发 dispatch() 的情况下更新 state props - React Redux
- python - 将一年中的某一天转换为日期时间
- angular - TypeScript - 变量分配上的 SetTimeOut 错误
- c# - 检查数组是否包含相同的元素(顺序不重要)c#
- android - 如何在没有查询的情况下在 URL 中传递数据
- reactjs - 在 React 中处理 Child 中的父函数调用
- stm32f4 - STM32F4 上的通用选项字节