我一直试图使用子图来绘制多个图形。想法是类似于https://matplotlib.org/tutorials/introductory/sample_plots.html
上子图示例部分中的代码下面是我的代码段
revenues = np.array(base_stock.getSeriesfromData(profit_loss,'Sales',-3))
profit_after_tax = np.array(base_stock.getSeriesfromData(profit_loss,'Net profit',-3))
fig,axis = plt.subplots(2,1,sharex=True)
axis[0,1].plot(base_stock.time_axis,revenues,'-o')
axis[1,1].plot(base_stock.time_axis,profit_after_tax,'-x')
当我尝试运行代码时,会弹出以下错误消息
IndexError:数组的索引过多
我打印出我给plot()调用的输入。它们如下
base stock time is [ 1 2 3 4 5 6 7 8 9 10]
revenues is [2592.45 6696.76 8238.2 14766.6 25298.4 30414.4 34660.7
37216.3 42375.5,56293.3]
profit after tax is [176.25 242.77 390.8 259.6 444.5 765 862.5 1292.3 1554.3 1597]
shape of revenues is (10,)
shape of base_stock is (10,)
shape of profit after tax is (10,)
type of revenues is <class 'numpy.ndarray'>
type of profit after tax is <class 'numpy.ndarray'>
type of base_stock time is <class 'numpy.ndarray'>
我不确定这里出了什么问题。如果有人错过了某些事情,如果有人可以给我一些见解,那就太好了。
整个错误如下所示,并带有追溯:
回溯(最近通话最近一次):
文件“”,第1行,在 runfile('F:/Investment/new_fundamental_analysis.py',wdir ='F:/ Investment')
文件 “ C:\ Users \ anoop \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py”, 行文件中的第688行 execfile(文件名,命名空间)
文件 “ C:\ Users \ anoop \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py”, 第101行,在execfile中 exec(compile(f.read(),文件名,'exec'),命名空间)
文件“ F:/Investment/new_fundamental_analysis.py”,第104行,在 axis [0,0] .plot(base_stock.time_axis,revenues,'-o')
IndexError:数组的索引过多