I am hoping there is someway to handle this as there are numerous questions out there about xtick formatting in pyplot but I have not found anything approaching this question.
I have the following code:
fig, ax=plt.subplots(1,1,figsize=[10, 5]) # Set dimensions for figure
plt.plot(organic_search.groupby('week-year').Amount.sum(), color='g')
plt.title('Organic Search Revenue Time Series')
fmt = '${x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick)
plt.ylabel('Revenue')
plt.xlabel('Week')
plt.grid(True)
plt.show()
It works all well and good but the output is a bit messy because this is weekly data.
Some sample data:
Week | Week_Start_Date | Amount | year | week-year |
Week 1 2018-01-01 42920 2018 Week 1 2018
Week 2 2018-01-08 37772 2018 Week 2 2018
Week 3 2018-01-15 41076 2018 Week 3 2018
Week 4 2018-01-22 38431 2018 Week 4 2018
Week 5 2018-01-29 101676 2018 Week 5 2018
output:
The xtick labels are unreadable as is and I was wondering if someone know how to have the same weekly graph but the xticks represent just the year. I have tried a few different ways but either (1) it shrinks the graph to the far left of the screen or (2) I get an error saying in effect "tick labels (4) do not match data points(186)).
I just want a neater display - not critical to analysis but help is appreciated