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().
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
set_xticks() and Axes. set_yticks() functions in axes module of matplotlib library are used to Set the ticks with a list of ticks on X-axis and Y-axis respectively. Parameters: ticks: This parameter is the list of x-axis/y-axis tick locations.
FacetGrid object takes a dataframe as input and the names of the variables that will form the row, column, or hue dimensions of the grid. The variables should be categorical and the data at each level of the variable will be used for a facet along that axis.
col_wrapint. “Wrap” the column variable at this width, so that the column facets span multiple rows. Incompatible with a row facet. share{x,y}bool, 'col', or 'row' optional. If true, the facets will share y axes across columns and/or x axes across rows.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With