[英]Seaborn jointplot color histogram
我想根據我的調色板為我的直方圖着色。 這是我用來做這個的代碼,這是我嘗試在這里找到的答案時收到的錯誤。
g = sns.jointplot(data=emb_df, x='f0', y='y', kind="hist", hue='klabels', palette='tab10', marginal_kws={'hist_kws': {'palette': 'tab10'}})
plt.show()
UserWarning: The marginal plotting function has changed to `histplot`, which does not accept the following argument(s): hist_kws.
我也試過這個:
plt.setp(g.ax_marg_y.patches, color='grey')
但這並沒有根據我的 'klabels' 參數為我的直方圖着色,只是一個平坦的灰色。
默認情況下,邊緣圖使用具有相應色調的相同調色板着色。 所以,你可以在沒有marginal_kws=
情況下運行它。 histplot
marginal_kws=
直接進入histplot
; 而不是marginal_kws={'hist_kws': {'palette': 'tab10'}}
,正確的用法是marginal_kws={'palette': 'tab10'}
。 如果你想要堆疊條形,你可以嘗試marginal_kws={'multiple': 'stack'})
如果您希望邊緣圖更大,可以更改ratio=
參數。 默認值為5
,這意味着中心圖是邊緣圖的 5 倍。
下面是一個例子:
from matplotlib import pyplot as plt
import seaborn as sns
iris = sns.load_dataset('iris')
g = sns.jointplot(data=iris, x='petal_length', y='sepal_length', kind="hist", hue='species', palette='tab10',
ratio=2, marginal_kws={'multiple': 'stack'})
sns.move_legend(g.ax_joint, loc='upper left') # optionally move the legend; seaborn >= 0.11.2 needed
plt.show()
要將這些圖並排作為子圖,您可以使用x=
和y=
填充(2D 直方圖)、僅指定x=
(水平直方圖)或僅指定y=
(垂直)調用底層sns.histplot
直方圖)。
from matplotlib import pyplot as plt
import seaborn as sns
iris = sns.load_dataset('iris')
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(15, 4))
sns.histplot(data=iris, x='petal_length', y='sepal_length', hue='species', palette='tab10', legend=False, ax=ax1)
sns.histplot(data=iris, x='petal_length', hue='species', palette='tab10', multiple='stack', legend=False, ax=ax2)
sns.histplot(data=iris, y='sepal_length', hue='species', palette='tab10', multiple='stack', ax=ax3)
sns.move_legend(ax3, bbox_to_anchor=[1.01, 1.01], loc='upper left')
plt.tight_layout()
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.