log-log plot with seaborn jointgrid

前端 未结 1 2018
逝去的感伤
逝去的感伤 2021-02-04 04:44

I\'m trying to create a loglog plot with a KDE and histogram associated with each axis using a seaborn JointGrid object. This gets me pretty close, but the histogram bins do not

1条回答
  •  死守一世寂寞
    2021-02-04 05:18

    For log histograms I find generally useful to set your own bins with np.logspace().

    mybins=np.logspace(0,np.log(100),100)
    

    Then just set bins= in _marginals

    data = sns.load_dataset('tips')
    g = sns.JointGrid('total_bill', 'tip', data,xlim=[1,100],ylim=[0.01,100])
    g.plot_marginals(sns.distplot, hist=True, kde=True, color='blue',bins=mybins)
    g.plot_joint(plt.scatter, color='black', edgecolor='black')
    ax = g.ax_joint
    ax.set_xscale('log')
    ax.set_yscale('log')
    g.ax_marg_x.set_xscale('log')
    g.ax_marg_y.set_yscale('log')
    

    enter image description here

    0 讨论(0)
提交回复
热议问题