在seaborn中,色调为组设置不同的颜色。我可以设置吗alpha
取决于组中的JointGrid
?或者甚至在单个数据点上?
sns.set_theme()
jg = sns.JointGrid(data=df_sns, x='x', y='y', hue='hue')
jg.plot_joint(sns.scatterplot)
jg.plot_marginals(sns.histplot, kde=False)
jg.set_axis_labels(xlabel='x', ylabel='y')
jg.fig.tight_layout()
(更新:使用to_rgba()
正如评论中所建议的。)
你可以创建一个palette
其中包含带有 alpha 的颜色。创建此类颜色的一个简单方法是使用十六进制格式:'#RRGGBBAA'
。或者您可以将任何 matplotlib 颜色转换为 rgb 并添加 alpha,如示例代码所示:
import matplotlib.pyplot as plt
from matplotlib.colors import to_rgba
import seaborn as sns
iris = sns.load_dataset("iris")
g = sns.JointGrid(data=iris, x='sepal_length', y='sepal_width', hue='species')
color_dict = {'setosa': to_rgba('cornflowerblue', 1),
'versicolor': to_rgba('crimson', 0.7),
'virginica': to_rgba('turquoise', 0.4)}
g.plot_joint(sns.scatterplot, palette=color_dict)
g.plot_marginals(sns.histplot, kde=False, palette=color_dict, multiple='stack')
plt.tight_layout()
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)