ste*_*ter 6 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))
Run Code Online (Sandbox Code Playgroud)
我收到一个值错误:包含多个元素的数组的真值不明确。使用 a.any() 或 a.all()。

设置 yticks = (ticks, labels) 是我在 matplotlib 中实现的方式。
在写这篇文章并尝试最后的一些选项时,我使用了 sns.distplot 并发现它对我的情况来说是更好的选择。我仍然希望对这个问题有任何见解
我终于找到了这个解决方案。奇怪的是,您必须在新行上再次调用 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4796 次 |
| 最近记录: |