How to edit the ticks in jointplot or JointGrid
Asked Answered
B

1

7

How can I change the tick placement in a seaborn jointplot or JointGrid?

I'm looking for something similar to matplotlib's plt.xticks.

Belletrist answered 3/12, 2015 at 20:25 Comment(0)
B
19

You can access the 'axes' of a JointGrid object using ax_joint (for the main plot) and ax_marg_x or ax_marg_y for the marginal distributions' plots. Then, you can use the full API for the matplotlib axes to manipulate the details of the plot, and in particular you can use the get_xticks/set_xticks to change the tick placement.

Here's a basic example of how to use this to change the xticks/yticks positions:

import numpy as np
import seaborn as sns

g = sns.jointplot(np.random.rand(100), np.random.rand(100))

g.ax_joint.set_xticks([0, 0.34, 0.88])
g.ax_joint.set_yticks([-0.1, 0.5, 1, 1.1])

This results in the following plot:

Example of a seaborn jointplot with modified ticks

Bridesmaid answered 10/12, 2015 at 18:44 Comment(2)
if you want to rotate the ticks: for tick in ax.ax_joint.get_xticklabels(): tick.set_rotation(30)Covenantee
Due to axis rotation, my x label disappears. any tricks to visualize it back?Globetrotter

© 2022 - 2024 — McMap. All rights reserved.