I created a Boxplot like this:
f, ax = plt.subplots(figsize=(15,7))
sns.despine(bottom=True, left=True)
sns.boxplot(x=x)
ax.set(xlim=(0, 120))
ax.grid(linestyle='-', axis="x")
ax.xaxis.set_major_locator(ticker.MultipleLocator(24))
ax.set_axisbelow(True)
plt.show()
Which look like this:
Like i already marked in the Picture, i want a different xtick range for a specific part in the graph. So until the value of 24 the ticker should be ticker.MultipleLocator(8)
and then it should continue with ticker.MultipleLocator(24)
.
CodePudding user response:
Since multiple locators cannot be mixed, there is a way to create and combine scales for each.
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
tips = sns.load_dataset("tips")
fig, ax = plt.subplots(figsize=(15,7))
sns.despine(bottom=True, left=True)
g = sns.boxplot(x=tips['total_bill'])
ax.set(xlim=(0, 120))
ax.grid(linestyle='-', axis="x")
tickA = np.arange(0,24,8)
tickB = np.arange(24,120,24)
new_ticks = np.concatenate([tickA, tickB])
ax.set_xticks(new_ticks)
ax.set_axisbelow(True)
plt.show()