Mar-09-2022, 02:37 PM
Matplotlib is giving me fits. Here's the graphing portion of my code:
From an internet search, I was able to construct the highlighted (with asterisks) line. This only affects the x-axis on the fourth and final graph, though. Even if I include this line in the blocks for each of the last three graphs (two others are now commented out), it only affects the very bottom. Why is this? Does it have to do with setting up the graphs as subplots where one x-axis is used for all three? But then--I do get an x-axis for graphs 2-3 with increments of 10. And, the first graph with a datetime x-axis is just as I want.
Would it be better to avoid doing these graphs as subplots? Thanks!
datetimes = pd.to_datetime(btstats['Date']) #need datetime column for btstats.Date to let plt do its thing with auto-scaling. btstats['Date'] = datetimes trade_dates_in_datetime = [datetime.strptime(i, "%Y-%m-%d") for i in trade_list] marker_list = [] #Graph cumulative realized_pnl fig, axs = plt.subplots(4,1) #no 0-indexing here fig.set_size_inches(16, 12) for i in range(len(btstats)): if btstats.loc[i,'Date'] in trade_dates_in_datetime: marker_list.append('d') else: marker_list.append('') axs[0].plot(btstats['Date'],btstats['Cum.PnL'],marker='',color='black',linestyle='solid') #plots line only for xp, yp, m in zip(btstats['Date'].tolist(), btstats['Cum.PnL'].tolist(), marker_list): axs[0].plot(xp,yp,m,color='orange',markersize=12) #plots markers only (or lack thereof) axs[0].set_xlabel('Date', fontsize = 14) #in all cases, axs[0] rather than axs[0,0] since we specified above only one column. axs[0].set_ylabel('Cumulative PnL', fontsize = 14) plt.xticks(rotation = 0, fontsize = 14) plt.yticks(fontsize = 14) #plt.show() #now it'd be nice to get a heavy dot at the start of every new trade. axs[1].plot(P_price_orig_all, marker='o', color='orange') axs[1].set_xlabel('Trade #', fontsize = 16) axs[1].set_ylabel('Original Pos. Price', fontsize = 14) plt.xticks(np.arange(len(P_price_orig_all)), np.arange(1, len(P_price_orig_all)+1), fontsize = 14) #******************** #plt.xticks(fontsize = 14) plt.yticks(fontsize = 14) axs[2].plot(P_price_orig_all, marker='o', color='orange') axs[2].set_xlabel('Trade #', fontsize = 16) axs[2].set_ylabel('Original Pos. Theta', fontsize = 14) #plt.xticks(np.arange(len(P_theta_all)), np.arange(1, len(P_theta_all)+1), fontsize = 14) plt.xticks(fontsize = 14) plt.yticks(fontsize = 14) axs[3].plot(P_theta_orig_price_all, marker='o', color='orange') axs[3].set_xlabel('Trade #', fontsize = 16) axs[3].set_ylabel('Orig. Theta / Pos. Price', fontsize = 14) #plt.xticks(np.arange(len(P_theta_orig_price_all)), np.arange(1, len(P_theta_orig_price_all)+1), fontsize = 14) plt.xticks(fontsize = 14) plt.yticks(fontsize = 14) plt.tight_layout() plt.show()I'm trying to do four graphs here. For the last three, the x-axis shows trade number. I currently have 55 trades and it defaults to major ticks with increments of 10. That is too much.
From an internet search, I was able to construct the highlighted (with asterisks) line. This only affects the x-axis on the fourth and final graph, though. Even if I include this line in the blocks for each of the last three graphs (two others are now commented out), it only affects the very bottom. Why is this? Does it have to do with setting up the graphs as subplots where one x-axis is used for all three? But then--I do get an x-axis for graphs 2-3 with increments of 10. And, the first graph with a datetime x-axis is just as I want.
Would it be better to avoid doing these graphs as subplots? Thanks!