How to add additional tick labels, formatted differently, in matplotlib
<p>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.</p>

<p>Below is <a href="http://content.screencast.com/users/cmardiros/folders/Jing/media/51a8b412-e3db-4030-81c9-cd389336f626/00000034.png" rel="nofollow">what I'm trying</a> 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.</p>

<p><a href="https://i.stack.imgur.com/V1pGKm.png" rel="nofollow"><img src="https://i.stack.imgur.com/V1pGKm.png" alt="enter image description here"></a></p>

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

<pre><code>            # 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)
</code></pre>

<p>Any ideas? Thank you!</p>

<p>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 <a href="http://matplotlib.org/examples/axes_grid/demo_parasite_axes2.html" rel="nofollow">this example</a> in the documentation as a starting point.</p>

python matplotlib