Dec-22-2020, 06:59 PM
I'm trying to plot five series as subplots:
Is there a way I can make that work? Thanks!
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'] subplot_count = 1 fig, ax = plt.subplots (3,2) plt.figure(facecolor='lightgrey') ax_indices = {1:'0,0',2:'0,1',3:'0,2',4:'1,0',5:'1,1',6:'1,2'} print(ax_indices[subplot_count]) for market in markets: columnname_0 = market+'_Close' 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] # ax[ax_indices[subplot_count]].plot(market_cut[columnname_0]) ax[0,0].plot(market_cut[columnname_0]) subplot_count += 1 plt.show()This plots all lines in the upper left subplot. If I comment out Line 22 and uncomment out Line 21, then I get "IndexError: only integers, slices (
:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices." Is there a way I can make that work? Thanks!