2016-08-23 121 views
2

JointGridJointPlot的文档中似乎没有任何示例,它们显示yticks位于边缘地块中。如何将yticks添加到seabornJointGrid下面的图中的边际图中?在Seaborn JointGrid中为边缘添加yticks

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') 

enter image description here

我知道什么是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)

回答

4

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

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() 

​​

相关部分进行反向工程是seaborn的源@ seaborn/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) 
+1

特别感谢指点我到正确的位置在资源。 – lanery