gpt4 book ai didi

matplotlib - 为 fiddle 图中的每个 fiddle 设置颜色

转载 作者:行者123 更新时间:2023-12-01 15:48:05 27 4
gpt4 key购买 nike

我试过 violin在 Seaborn 中为每个 fiddle 绘制不同的颜色:

sns.violinplot(x='type', y='den', data=mydf, ax=axes[0], color=['red','blue','yellow'])

但是我得到了:

ValueError: to_rgb: Invalid rgb arg "('red', 'blue', 'yellow')" could not convert string to float: red

最佳答案

我认为你应该使用 palette关键词:

color : matplotlib color, optional

Color for all of the elements, or seed for light_palette() when using hue nesting.

palette : seaborn color palette or dict, optional

Colors to use for the different levels of the hue variable. Should be something that can be interpreted by color_palette(), or a dictionary mapping hue levels to matplotlib colors.

import seaborn as sb
import numpy as np

data = np.random.random([100,4])

sb.violinplot(data=data, palette=['r','g','b','m'])
enter image description here

关于matplotlib - 为 fiddle 图中的每个 fiddle 设置颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34058188/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com