Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with the x-axis
#3
We solved this a different way in another thread, but for educational purposes I wanted to try and understand.
import pandas as pd
import matplotlib.pyplot as plt
import datetime

rawdate_start = '2007-01-01' #input('Please enter start date as YYYY-MM-DD: ')
rawdate_end = '2019-01-01' #input('Please enter end date as YYYY-MM-DD: ')
markets = ['ES', 'GC', 'CL', 'EC', 'US']
#plt.figure(facecolor='lightgrey')
subplot_count = 1
plt.subplot(3,2,subplot_count) #if this line goes here, then I get one blank graph followed by five correct graphs plotted alone (not as subplots)
for market in markets:
    columnname_0 = market+'_Close'
    columnname_1 = market+'_Daily_Rtn'
    columnname_2 = market+'_Cum_Rtn'
    columnname_3 = market+'_Value'
    df_name = market
    market = pd.read_csv(r'C:\Users\drkle\{}(daily).csv'.format(market), parse_dates=["Date"], index_col="Date")
    market_cut = market.drop(['Open','High','Low','Vol','OI'],axis=1)
    market_cut = market_cut[rawdate_start:rawdate_end]
    market_cut.columns = [columnname_0]
#    if subplot_count > 1:
 #       plt.subplot(3,2,subplot_count) #if this line goes here, then I get five blank axes/graphs with US graph (last one) correct.
    market_cut.plot(y=columnname_0,title=df_name+' Stock Price')
    subplot_count += 1
plt.show()
I tried toggling between placing the above line as Line 10 or 22. If I left line 10 (deleted 22), then I got one blank graph followed by the five correct ones (none as subplots, though). If I deleted 10 and left 22, then I got five blank graphs followed by the correct last graph (none as subplots, though).

Can you explain this? Thanks!
Reply


Messages In This Thread
Problem with the x-axis - by Mark17 - Dec-22-2020, 03:01 PM
RE: Problem with the x-axis - by MK_CodingSpace - Dec-22-2020, 05:15 PM
RE: Problem with the x-axis - by Mark17 - Dec-22-2020, 08:26 PM
RE: Problem with the x-axis - by MK_CodingSpace - Dec-22-2020, 09:31 PM
RE: Problem with the x-axis - by Mark17 - Dec-22-2020, 09:43 PM
RE: Problem with the x-axis - by MK_CodingSpace - Dec-23-2020, 02:30 PM
RE: Problem with the x-axis - by MK_CodingSpace - Dec-22-2020, 09:58 PM
RE: Problem with the x-axis - by Mark17 - Dec-23-2020, 01:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Floor division problem with plotting x-axis tick labels Mark17 5 2,186 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,519 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,528 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020