Issue:
All labels are getting printed when setting the rotation for the x-axis label using set_xticklabels
.
Code
winner_freq = pd.DataFrame(player_match.winner.value_counts().reset_index())
winner_freq_plot = sns.barplot(x='index', y='winner', data=winner_freq)
winner_freq_plot.set_xticklabels(winner_freq_plot.get_xticklabels(), rotation=90)
Screenshot
Fix that I tried
I don't have any idea how to fix it and googled but no answer, so I took the labels separately in a list and feed inside the set_xticklabels
but still no luck.
Thanks in advance :)
This is not really a mistake, but rather, a characteristic of
matplotlib
, whichseaborn
uses. Most of its functions return values that in some way represent the computations that they have performed.In this case,
set_xticklabels
modifies the tick labels, which are drawn withText
objects. It is thoseText
objects, collected in alist
, that are returned.What you perceive as the labels being "printed" is simply your Jupyter notebook representing that
list
as text.If you do not wish to see this, you can assign the result to a throwaway variable, like this:
That said, note that
_
normally binds to the last return value, and you will override that by doing so.An alternative is to simply append a
pass
statement to your code. Since Jupyter will render the return value of the last statement in the cell, andpass
returns nothing, you will not get any output.