python - 如何在 Seaborn FacetGrid 中对数刻度后设置刻度?

标签 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 = (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)

enter image description here

关于python - 如何在 Seaborn FacetGrid 中对数刻度后设置刻度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54151721/

相关文章:

python - 将 DataFrame 导出和导入到 Access 文件 (.mdb)

pandas - 获取并绘制列的 groupby 结果分布图

python - 在不清除图形的情况下删除流图(matplotlib)

python - 使用 numpy 和 matplotlib 进行基本图像处理

python - 如何用seaborn热图中的词汇填充xticklabels?

python - 可以使用 Python 3 的数字格式将数字四舍五入到百、千等

python - 当值为0时如何在轴上显示条形类别

python : how to import module in other module

Python 正则表达式 : Find all caps with no following lowercase

python - 搜索缺少的时间戳并在 python 中显示?