I created a boxplot with matplotlib. Because of one outlier the range of the x-axis is very wide and the box in relation to the axis small. Is there a possibility to interrupt the x-axis f.e. with a double slash "//" or anything else? So that I can see the outlier but get a bigger box.
example dataframe
data = { 'T1': ['ja', 'ja', 'ja', 'ja', 'ja', 'nein', 'nein', 'nein', 'nein', 'nein', 'ja', 'ja', 'ja', 'ja', 'ja', 'nein', 'nein', 'nein', 'nein', 'nein', 'ja', 'ja', 'ja', 'ja', 'ja', 'nein', 'nein', 'nein', 'nein'], 'days': [2000,200,200,400,400,100,500,50,400,600,30,200,200,400,400,100,100,50,400,600,30,200,200,400,400,100,100,50,400]}
df = pd.DataFrame(data)
plot box with seaborn
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
f, ax = plt.subplots(figsize=(15,5))
sns.boxplot(data=df,
x = df.loc[:,'days'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax)
ax.set_xlabel('days')
ax.legend().remove()
plt.show()
Now the outlier is at 2000 days, for my purpose it is necessary to show this extreme value. But I want to condense the x-axis. So my idea is, to use f.e. // to disrupt the x-axis between 700 and 1750. Has anyone an idea?
After trying to transfer it to my data, following problem popped up: #renamed 2nd column to 'days_after' and create 3rd column
df.loc[:, 'days_before']=0-df.loc[:, 'days_after']
If I tried now to boxplot the same graph with splitted x-axis, it doesn't work.
[![f, (ax1, ax2) = plt.subplots(ncols=2, sharey=True, gridspec_kw={'width_ratios':\[5,1\]}, figsize=(5,2))
sns.boxplot(data=df,
x = df.loc\[:,'days_before'\],
y= df.loc\[:,'T1'\],
hue='T1',
ax=ax1, showfliers = False)
sns.boxplot(data=df,
x = df.loc\[:,'days_before'\],
y= df.loc\[:,'T1'\],
hue='T1',
ax=ax2)
ax1.set_xlabel('days')
ax1.legend().remove()
ax2.legend().remove()
ax1.spines\['right'\].set_visible(False)
ax2.spines\['left'\].set_visible(False)
ax2.yaxis.set_visible(False)
ax1.set_xlim(right=-1750)
ax2.set_xlim(left=-750)
plt.show()][2]][2]