Jer*_* M. 3 python plot matplotlib pandas seaborn
我有一个如下所示的数据集:
{'prediction': {5: 'c1',
4: 'c1',
3: 'c1',
2: 'c1',
0: 'c1',
1: 'c1',
7: 'c1',
6: 'c1'},
'variable': {5: 'ft1',
4: 'ft2',
3: 'ft3',
2: 'ft4',
0: 'ft5',
1: 'ft6',
7: 'ft7',
6: 'ft8'},
'value': {5: 0.020915912763961077,
4: 0.020388363414781133,
3: 0.007204373035913109,
2: 0.0035298765062560817,
0: -0.002049702058734183,
1: -0.004283512505036808,
7: -0.01882610282871816,
6: -0.022324439779323434}}
Run Code Online (Sandbox Code Playgroud)
我正在尝试制作一个可行的条形图,如下所示:
sns.barplot(data=x, x='value', y='variable',
hue='prediction', orient="h")
Run Code Online (Sandbox Code Playgroud)
但是,我希望条形是红色的。以下:
sns.barplot(data=x, x='value', y='variable',
hue='prediction', color='red', orient="h")
Run Code Online (Sandbox Code Playgroud)
为什么会变成灰色?我也尝试过多种其他颜色,但结果相同。如何将条形变为橙色?
使用seaborn v0.11.1
尝试使用facecolor:
sns.barplot(data=x, x='value', y='variable',
hue='prediction', orient="h", facecolor='red')
Run Code Online (Sandbox Code Playgroud)
输出:
color用于所有元素或渐变调色板的种子,而edgecolor( ec) 和facecolor( fc) 指定单独的元素。
ec并fc优先于hue、 和color。colorwith hue,根据渐变为条形着色,但由于'prediction'只有一个值,因此渐变从灰色开始。sns.barplot(data=x, x='value', y='variable',
hue='prediction', orient="h", facecolor='red')
Run Code Online (Sandbox Code Playgroud)
请注意,dodge=False用于防止条形图沿分类轴移动,这种情况在使用 时会发生hue。
| 归档时间: |
|
| 查看次数: |
2036 次 |
| 最近记录: |