I have a pandas dataframe that contains dates starting at 2017-09-01 (which I believe is in the correct format for a dataframe date). But the X axis is expanded dramatically. I do not have any outliers on the LHS.
JavaScript
x
3
1
with sns.axes_style('whitegrid'):
2
g = sns.relplot(x='Date', y='PL', data=daily_PL_withDate_df, height=5, aspect=1.5)
3
Advertisement
Answer
Pandas and matplotlib’s dates sometimes don’t go along well. You can set the xlims explicitly as follows:
JavaScript
1
15
15
1
import matplotlib.pyplot as plt
2
import numpy as np
3
import pandas as pd
4
import seaborn as sns
5
6
N = 700
7
daily_PL_withDate_df = pd.DataFrame({'Date':pd.date_range('2017-09-01', periods=N),
8
'PL': np.random.normal(0, 2000, N)})
9
10
sns.relplot(x='Date', y='PL', data=daily_PL_withDate_df, height=5, aspect=1.5)
11
12
plt.xlim(daily_PL_withDate_df['Date'].iloc[0], daily_PL_withDate_df['Date'].iloc[-1])
13
14
plt.show()
15