pythonseabornjointplothistplotjointgrid

Remove Bins from Marginal histplot in Jointplot


I am trying to remove the superposed line of the bins (derived from the hisplot part of the jointplot function) in the lateral plot here in this figure (in white):

Plot

column1 = "F"
array1 = np.random.randn(400)
column2 = "R"
array2 = np.random.randn(400)

df = pd.DataFrame(np.column_stack((array1, array2)), columns=[column1, column2])
viol = pd.DataFrame(np.concatenate((array1, array2)), columns=["val"])
viol["Sim"] = np.concatenate((np.repeat("F", np.size(array1)), np.repeat("R", np.size(array2))))
viol["xx"] = np.repeat("1", np.size(array1) * 2)



g = sns.jointplot(x=column1,y=column2,data=df,ratio=3,marginal_kws={"kde": False, "color": "white", "element": "poly" })
sns.regplot(x=column1,y=column2,data=df,ax=g.ax_joint)
sns.violinplot( data=viol, x="xx",  y="val",   hue="Sim")
g.ax_marg_y.get_legend().remove()
sns.despine()
g.fig.colorbar( g.ax_joint.collections[0],  ax=[g.ax_joint, g.ax_marg_y, g.ax_marg_x],   orientation="vertical")

g.ax_marg_x.remove()
g.ax_marg_y.spines["bottom"].set_visible(False)

I tried by setting the filling to "False" but the contours remained. Or set the color to "invisible". I tried removing the "ax_marg_y" but it was also removed the violin plot. An idea can be to set another scale for the bin heights so it won't be superposed on the violin plot but I didn't manage to set it.


Solution

  • You can remove the kde line in your plot by setting the linewidth to 0 inside the marginal_kws, which defines the characteristics of the line... Update the jointplot() like below (don't think you need the alpha, color, etc., but you can check and remove those as well)...

    g = sns.jointplot(x=column1, y=column2, data=df, c=H, ratio=3, 
                      joint_kws={"color":None, 'cmap':'rainbow', 'alpha':0.5, 's':100}, 
                      marginal_kws= {'kde':False, 'linewidth':0, 'color':'white', 'stat':'density', 'alpha':0.0, 'element':'poly', 'fill':False})
    

    to get the below plot.

    enter image description here