I have some problems with setting xticks in swarmplot and pointplot in seaborn (though with traditional plt.plot it's OK). When I use typical commands like:
plt.xticks([2,3,4,5,6,7,8])
or:
ax2.xaxis.set_major_locator(ticker.LinearLocator(8))
xticks are only in a short range which doesn't cover the whole x axis. https://i.stack.imgur.com/H1D5Q.jpg
(left subplot on the image). When I dont't type plt.xticks(... then I get something like on the right subplot.
My code is here:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
df = pd.read_csv('dane/iris.csv')
df['Legend'] = df['variety']
df['variety'].replace( {'Setosa':1, 'Versicolor':2, 'Virginica':3}, inplace = True)
fig = plt.figure(figsize = (13,7), facecolor = 'white')
ax1 = fig.add_subplot(1,2,1)
sns.swarmplot(df['sepal.length'], df['sepal.width'], hue = df['Legend'], ax = ax1)
plt.xlabel('Sepal length', fontsize = 14)
plt.ylabel('Sepal width', fontsize = 14)
plt.xticks([])
plt.xticks([2,3,4,5,6,7,8])
ax2 = fig.add_subplot(122)
sns.swarmplot(df['petal.length'], df['petal.width'], hue = df['Legend'], ax = ax2)
plt.xlabel('Petal length', fontsize = 14)
plt.ylabel('Petal width', fontsize = 14)
plt.savefig(Figure = fig, fname = 'iris.png')