文档中似乎没有在边缘图中显示JointGridJointPlotyticks示例。如何将yticks添加到下面seabornJointGrid绘图中的边缘绘图?

import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset('tips')
g = sns.JointGrid(x='total_bill', y='tip', data=tips)
g = g.plot_joint(plt.scatter, color='#334f6d')
g = g.plot_marginals(sns.distplot, color='#418470')

python - 将ytick添加到Seaborn JointGrid的边缘-LMLPHP
我知道yticks是从g.ax_marg_x.get_yticks()中得到的,但是将它们设置为
g.ax_marg_x.set_yticks(g.ax_marg_x.get_yticks())

似乎什么都没做,也没做其他简单的尝试,比如g.ax_marg_x.yaxis.set_visible(True)

最佳答案

这绘制了一些东西,但是我不确定如何解释这些结果(或者它们是如何计算的;正确的结果看起来不像密度)。

    import matplotlib.pyplot as plt
    import seaborn as sns

    tips = sns.load_dataset('tips')

    g = sns.JointGrid(x='total_bill', y='tip', data=tips)
    g = g.plot_joint(plt.scatter, color='#334f6d')
    g = g.plot_marginals(sns.distplot, color='#418470', )

    plt.setp(g.ax_marg_x.get_yticklabels(), visible=True)
    plt.setp(g.ax_marg_y.get_xticklabels(), visible=True)

    plt.show()

python - 将ytick添加到Seaborn JointGrid的边缘-LMLPHP
逆向工程的相关部分是在Seabn的来源@ Seabnn/AxISGRID.Py(link):
# LINE 1623 #
# Set up the subplot grid
f = plt.figure(figsize=(size, size))
gs = plt.GridSpec(ratio + 1, ratio + 1)

ax_joint = f.add_subplot(gs[1:, :-1])
ax_marg_x = f.add_subplot(gs[0, :-1], sharex=ax_joint)
ax_marg_y = f.add_subplot(gs[1:, -1], sharey=ax_joint)

self.fig = f
self.ax_joint = ax_joint
self.ax_marg_x = ax_marg_x
self.ax_marg_y = ax_marg_y

# Turn off tick visibility for the measure axis on the marginal plots
plt.setp(ax_marg_x.get_xticklabels(), visible=False)
plt.setp(ax_marg_y.get_yticklabels(), visible=False)

# Turn off the ticks on the density axis for the marginal plots
plt.setp(ax_marg_x.yaxis.get_majorticklines(), visible=False)
plt.setp(ax_marg_x.yaxis.get_minorticklines(), visible=False)
plt.setp(ax_marg_y.xaxis.get_majorticklines(), visible=False)
plt.setp(ax_marg_y.xaxis.get_minorticklines(), visible=False)
plt.setp(ax_marg_x.get_yticklabels(), visible=False)
plt.setp(ax_marg_y.get_xticklabels(), visible=False)
ax_marg_x.yaxis.grid(False)
ax_marg_y.xaxis.grid(False)

10-06 07:14