0

To borrow some default code with default libraries (extra helpful that you have to load the data explicitly, instead of having it polluting globals like in R...):

sns.set(style="whitegrid") tips = sns.load_dataset("tips") ax = sns.violinplot(y="day", x="total_bill", data=tips) 

This produces the following image:

enter image description here

I want to rotate the day of the week labels 90 degrees such that the baseline for those labels matches the word day, also on the Y axis.

I've looked at the answers already here, but they seem primarily to deal with (1) the X axis and (2) the first-order Y-axis label (here, the day label) rather than the Y-axis sub-labels (here, the days of the week).

2
  • You can take any answer for xticklabels and replace the x by a y. Commented Apr 3, 2019 at 21:21
  • Tried that, ax.set_yticklabels(rotation=90) yields an error. Answer below, accepted, also notes and corrects for that. Commented Apr 4, 2019 at 12:33

1 Answer 1

1

Most stackoverflow answers would recommend using ax.set_yticklabels(rotation = 90), while this does work, it also requires you to provide the positional parameter labels (failing to provide this will give you a TypeError). I'd recommend using plt.yticks(rotation = 90). This is how it'd look:

import seaborn as sns import matplotlib.pyplot as plt sns.set(style="whitegrid") tips = sns.load_dataset("tips") ax = sns.violinplot(y="day", x="total_bill", data=tips) plt.yticks(rotation = 90) plt.show(ax) 

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

The recommended way would rather be ax.tick_params(axis="y", rotation=90). Which other answers use set_yticklabels?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.