I am plotting a simple dataframe in Python matplot lib using the following:
# Load the data
df = pd.read_csv('equityplot.csv')
df['Date'] = pd.to_datetime(df['Date']) # ensure date column is datetime
# Plotting
fig, ax = plt.subplots(figsize=(10, 6))
# Iterate over each of your variables and plot
for variable in ['SP', 'RP', 'NRP', 'HRP', 'MVO', 'EW']:
ax.plot(df['Date'], df[variable], label=variable)
# Formatting x-axis
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=3))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b %Y'))
plt.xticks(rotation=90)
# Formatting y-axis to percentage
def to_percent(y, position):
# Ignore the passed in position. This has the effect of scaling the default
# tick locations.
s = str(100 * y)
# The percent symbol needs escaping in latex
if plt.rcParams['text.usetex'] is True:
return s + r'$\%$'
else:
return s + '%'
formatter = FuncFormatter(to_percent)
ax.yaxis.set_major_formatter(formatter)
# Add legend
ax.legend()
plt.tight_layout()
plt.show()
The resulting plot looks like the following:
Instead, in excel these weird breaks do not exists:
The dataset as simple as the following:
- first column: dates
- other columns: float values (the cumulative profit and loss function of trading strategies)
Can anyone explain from where this "rigidity" in the Python plot come from?