我想更改由 seaborn 创建的联合图中每个直方图的颜色。
我设法使用 margin_kws 更改了两个图的颜色,但是如何为每个直方图设置颜色?(例如红色和绿色直方图)
我的联合图的一个最小例子:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
x, y = np.random.multivariate_normal([2, 3], [[0.3, 0], [0, 0.5]], 1000).T
with sns.axes_style("white"):
g = sns.jointplot(x=x, y=y, kind="hex", stat_func=None, marginal_kws={'color': 'green'})
plt.show()
Run Code Online (Sandbox Code Playgroud)
iayork 关于直接使用轴对象的回答很好,尽管另一种选择是在绘图后更改条形图的颜色:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="white", color_codes=True)
x, y = np.random.multivariate_normal([2, 3], [[0.3, 0], [0, 0.5]], 1000).T
g = sns.jointplot(x=x, y=y, kind="hex", stat_func=None, marginal_kws={'color': 'green'})
plt.setp(g.ax_marg_y.patches, color="r")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4063 次 |
| 最近记录: |