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
, which seaborn
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 with Text
objects. It is those Text
objects, collected in a list
, 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, use a semicolon at the end of the last statement in a cell to prevent its output.
Alternatively, you can assign the result to a throwaway variable, like this:
_ = winner_freq_plot.set_xticklabels(winner_freq_plot.get_xticklabels(), rotation=90)
That said, note that _
normally binds to the last return value, and you will override that by doing so.
Another 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, and pass
returns nothing, you will not get any output.
if you are using jupyter notebook just
ax.set_xticklabels(...); <- line ends by a semicolon.
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