Seaborn - change bar color according to x name instead of hue?

若如初见. 提交于 2020-03-19 17:00:33

问题


For example:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
sns.set_style('darkgrid')
fig, ax = plt.subplots()

a = pd.DataFrame({'Program': ['A', 'A', 'B', 'B', 'Total', 'Total'],
                  'Scenario': ['X', 'Y', 'X', 'Y', 'X', 'Y'],
                  'Duration': [4, 3, 5, 4, 9, 7]})

g = sns.barplot(data=a, x='Scenario', y='Duration',
                hue='Program', ci=None)

I want x=X and x=Y have different color, but same color for each hue(A, B, Total ...) . ( There may be more Scenario than two ) . How do I change bar color according to x name instead of hue ?

来源:https://stackoverflow.com/questions/60631698/seaborn-change-bar-color-according-to-x-name-instead-of-hue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!