我想知道如何自定义FacetGrid的行标签。有一个自动值0.0、0.1等,可以更改为“比率<5%”,“比率<10%”,....
还想知道如何拥有一个xlabel和ylabel(不在网格的每个面上重复)。
查看Python图像和R图像。
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))
答案 0 :(得分:0)
也许其他人可以提出一个更简单的解决方案,但我的解决方案不是最漂亮,但可以为您提供所需的解决方案。而且由于您没有共享数据,所以我使用了seaborn
附带的玩具数据集:
import seaborn as sns
att = sns.load_dataset("attention")
g = sns.FacetGrid(att, col="subject", col_wrap=5, height=1.5)
g = g.map(plt.plot, "solutions", "score", marker=".")
#this surpresses the x- and y-labels on each axes of the bottom/leftmost column
g.set_axis_labels('', '')
# overall ylabel
g.fig.text(x=0, y=0.5,
verticalalignment='center', #make sure it's aligned at center vertically
s='Alcohol % per volume', #this is the text in the ylabel
size=16, #customize the fontsize if you will
rotation=90) #vertical text
#overall xlabel
g.fig.text(x=0.5, y=0,
horizontalalignment='center', #make sure it's aligned at center horizontally
s='Density $g/cm^3$', #this is the text in the xlabel
size=16)
答案 1 :(得分:0)
最后,我找到了一个很难看的解决方案,但是我没有收到其他解决方案!
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])