pythonseaborn

How to customize automatic row labels in seaborn FacetGrid? How to get single xlabel and ylable for the whole figure?


I would like to know how to customize the row labels of the FacetGrid. There is an automatic value 0.0, 0.1 and so on to be changed into "ratio <5%", "ratio <10%", ....

Also would like to know how to have a single xlabel and ylabel (not repeated to each facet of the grid).

See Python image and R image.

g = sns.FacetGrid(df, 
                  col="chlorides_rounded", 
                  height=3.3, 
                  row='ratio_sulfur.dioxide_rounded',
                  margin_titles=True,
                  hue='quality_bucket', 
                  hue_order=['High', 'Medium', 'Low'],palette = 'RdYlGn_r')

g = (g.map(plt.scatter, "density", "alcohol", **kws).add_legend(markerscale=2))

Python image

R image


Solution

  • Finally I found a solution which is quite ugly, but I did not receive other ones!

    ratio_labels =  ["","","",
                 "ratio <5%",
                 "","","",
                 "ratio < 15%",
                 "","","",
                 "ratio <25%",
                 "","","",
                 "ratio < 35%",
                 "","","",
                 "ratio <45%",
                 "","","",
                 "ratio < 55%",
                 "","","",
                 "ratio <65%",
                 "","","",
                 "ratio < 75%"]
    
    for i, ax in enumerate(g.axes.flat):
        plt.setp(ax.texts, text=ratio_labels[i])