Feb-28-2022, 10:20 PM
I've had this problem before. I'll have dates in a df column and plotting one year with 256 dates results in a black blur on the bottom.
Now... I wound up with this after searching the Net, finding a number of different pages, and incorporating some different ones:
And in general, I don't like this solution because at the top, I ended up with:
Any input is appreciated!
Now... I wound up with this after searching the Net, finding a number of different pages, and incorporating some different ones:
fig, ax = plt.subplots() ax.plot(btstats['Date'], btstats['Cum.PnL']) ax.set_xlabel('Date') ax.set_ylabel('Cumulative PnL') date_form = DateFormatter("%b") ax.xaxis.set_major_formatter(date_form) #months = mdates.MonthLocator() ax.xaxis.set_major_locator(mdates.MonthLocator(interval = 1)) #ax.set_xticklabels(ax.get_xticks(), rotation = 90) plt.tight_layout() plt.show()It now plots just 3-letter abbreviations for each month but the labels don't line up right with the data. The last label shown is Sep whereas the data go through the end of Dec. Why might that be?
And in general, I don't like this solution because at the top, I ended up with:
import matplotlib.pyplot as plt import matplotlib.dates as mdates from matplotlib.dates import DateFormatterI had to import three different packages for this? Seems like often when I find a plt solution that solves one problem, I have to import something different. That's frustrating because when I learned plt, it was said to be a highly effective, efficient library, etc.
Any input is appreciated!