Colorbar not shown in multiple Seaborn Jointplot

别说谁变了你拦得住时间么 提交于 2020-02-07 01:59:12

问题


As suggested in the answer of question, it's possible to plot multiple Seanborn Jointplot by SeabornFig2Grid.

However, the colorbars aren't shown:

import matplotlib.pyplot as plt
import seaborn as sns;
sns.set(style="white", color_codes=True)

import seabornfig2grid as sfg
import matplotlib.gridspec as gridspec

iris = sns.load_dataset("iris")

g1 = sns.jointplot("sepal_width", "petal_length", data=iris,
                  kind="kde", space=0, color="g",
                  cbar=True, cbar_kws={"label": 'Normalized Densities'},
                  )

g2 = sns.jointplot("sepal_width", "petal_length", data=iris,
                  kind="kde", space=0, color="g",
                  cbar=True, cbar_kws={"label": 'Normalized Densities'},
                  )

fig = plt.figure(figsize=(13,8))
gs = gridspec.GridSpec(1, 2)

mg0 = sfg.SeabornFig2Grid(g1, fig, gs[0])
mg1 = sfg.SeabornFig2Grid(g2, fig, gs[1])

gs.tight_layout(fig)

Update/Solution

Here's my solution:

mg0 = sfg.SeabornFig2Grid(g1, fig, gs[0])
mg1 = sfg.SeabornFig2Grid(g2, fig, gs[1])

mappable0 = g1.fig.axes[0].collections[0]
mappable1 = g2.fig.axes[0].collections[0]

gs.tight_layout(fig)
fig.colorbar(mappable0, ax=mg0.fig.axes[0])
fig.colorbar(mappable1, ax=mg1.fig.axes[3])

来源:https://stackoverflow.com/questions/59966497/colorbar-not-shown-in-multiple-seaborn-jointplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!