0

I'm having real problems plotting a 2nd line of tick labels on x-axis directly underneath the original ones. I'm using seaborn so I need to add these extra labels after the plot is rendered.

Below is what I'm trying to achieve but I'd like the gap between the 2 rows of tick labels to be a bit bigger and make the 2nd row bold and a different colour.

enter image description here

My attempts involve hacking the existing tick labels and appending the new strings underneath separated by newline:

 # n_labels is list that has the new labels I wish to plot directly
 # underneath the 1st row
 locs = ax.get_xticks().tolist()
 labels = [x.get_text() for x in ax.get_xticklabels()]
 nl = ['\n'.join([l, n_labels[i]]) for i, l in enumerate(labels)]
 ax.set_xticks(locs)
 ax.set_xticklabels(nl)

Any ideas? Thank you!

unutbu
885k197 gold badges1.8k silver badges1.7k bronze badges
asked Oct 18, 2016 at 18:37

1 Answer 1

1

One possibility would be to create a second x-axis on top of the first, and adjust the position and xtickslabels of the second x-axis. Check this example in the documentation as a starting point.

answered Oct 18, 2016 at 20:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.