I'm trying to make the x and y axes (including axes tick values) of my jointplot to start and end with specific values and to be scaled in set increments.
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
g = sns.jointplot(x="LONGITUDE", y="LATITUDE", data=data,
kind='reg', color="#774499", dropna=True, size=7, space=0.3, ratio=5,
xlim=(-180,180), ylim=(-90,90), fit_reg=False);
plt.rc("legend", fontsize=15)
plt.xlabel('Longitude', fontsize=15)
plt.ylabel('Latitude', fontsize=15)
plt.title('Spatial Location Plot', fontsize=15 )
plt.tick_params(axis="both", labelsize=15)
Notice that the lower and upper edges of both axes do not have any tick values. I want the tick values to start and end at the axes edges using exactly the values I specified in xlim() and ylim().
My preferred increments are 90 and 45 degrees for the X and Y axes respectively. So, I want the X axis to look this: -180, -90, 0, 90, 180. And the Y axis to be: -90, -45, 0, 45, 90. Thanks for your suggestions.
You can use matplotlib.ticker
to set the major_locator
on the axes. The JointGrid
returned by jointplot
(g
) has a ax_joint
attribute, which we can use to set the ticks. To set ticks every multiple of a number, we can use a MultipleLocator
:
import matplotlib.ticker as ticker
g.ax_joint.xaxis.set_major_locator(ticker.MultipleLocator(90))
g.ax_joint.yaxis.set_major_locator(ticker.MultipleLocator(45))
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