How to set ticks after log scale in Seaborn FacetGrid?

Viewed 7036

I'm trying to plot a FacetGrid consisting of histograms with a log transformation on the y axis. Im unable to set the yticks to a more readable format.

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))

I receive a Value Error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). enter image description here

enter image description here

Setting yticks = (ticks, labels) is how I achieve this in matplotlib.

while writing this and trying some last options, I went with a sns.distplot and found it to be much better option for my case. I would still appreciate any insight in this issue

1 Answers

I've finally found this solution to work. Strangely you must call grid.set() again on a new line. Hope this saves someone some time. You can NOT include the yscale argument in this line either or else it will fail.

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

Related