如何在Seaborn FacetGrid中进行日志缩放后设置刻度?

时间:2019-01-11 17:56:20

标签: python matplotlib seaborn

我正在尝试绘制一个由直方图组成的FacetGrid,并在y轴上进行对数转换。我无法将yticks设置为更具可读性的格式。

ticks = [0.1, 0.3, 1, 3, 10, 30, 100, 300, 1000, 3000, 10000]
labels = [i for i in ticks]
grid = sns.FacetGrid(data = df, col = 'LoanStatus', col_wrap = 4)
grid.map(plt.hist, 'credit_score_range_average', bins = 20).set(yscale ='log', yticks = (ticks, labels))

我收到一个值错误:包含多个元素的数组的真值不明确。使用a.any()或a.all()。 enter image description here

enter image description here

设置yticks =(刻度,标签)是我在matplotlib中实现此目标的方法。

在编写此文件并尝试一些最后的选项时,我使用了sns.distplot,发现它对我的情况来说是更好的选择。我仍然希望对这个问题有任何见识

1 个答案:

答案 0 :(得分:0)

我终于找到了这种解决方案。奇怪的是,您必须在新行中再次调用grid.set()。希望这可以节省一些时间。您不能在此行中包含yscale参数,否则它将失败。

ticks = [0.1, 0.3, 1, 3, 10, 30, 100, 300, 1000, 3000, 10000, 30000]
labels = [i for i in ticks]
grid = sns.FacetGrid(data = df, col = 'LoanStatus', col_wrap = 4)
grid.map(plt.hist, 'credit_score_range_average').set(yscale = 'log')
grid.set(yticks = ticks, yticklabels = labels)

enter image description here