I have 4 figures (y1,y2,y3,y4) that i want to plot on a common x axis (yr1,yr2,yr3,m1,m2,m3,m4,m5). In this code however i have kept axaxis as separate since i am trying to get the basics right first.
import matplotlib.pyplot as plt
import numpy as np
plt.figure(1)
xaxis = ['y1','y2','y3','m1','m2','m3', 'm4', 'm5']
y1 = np.array([.73,.74,.71,.75,.72,.75,.74,.74])
y2 = np.array([.82,.80,.77,.81,.72,.81,.77,.77])
y3 = np.array([.35,.36,.45,.43,.44,.45,.48,.45])
y4 = np.array([.49,.52,.59,.58,.61,.65,.61,.58])
plt.subplot(221)
plt.plot(xaxis,y1)
plt.subplot(222)
plt.plot(xaxis,y2)
plt.subplot(223)
plt.subplot(xaxis,y3)
plt.subplot(224)
plt.subplot(xaxis,y4)
plt.show()
Getting this error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-23-dfe04cc8c6c4> in <module>
14 plt.plot(xaxis,y2)
15 plt.subplot(223)
---> 16 plt.subplot(xaxis,y3)
17 plt.subplot(224)
18 plt.subplot(xaxis,y4)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in subplot(*args, **kwargs)
1074
1075 fig = gcf()
-> 1076 a = fig.add_subplot(*args, **kwargs)
1077 bbox = a.bbox
1078 byebye = []
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\figure.py in add_subplot(self, *args, **kwargs)
1412 self._axstack.remove(ax)
1413
-> 1414 a = subplot_class_factory(projection_class)(self, *args, **kwargs)
1415
1416 return self._add_axes_internal(key, a)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\axes\_subplots.py in __init__(self, fig, *args, **kwargs)
62 # num - 1 for converting from MATLAB to python indexing
63 else:
---> 64 raise ValueError(f'Illegal argument(s) to subplot: {args}')
65
66 self.update_params()
ValueError: Illegal argument(s) to subplot: (['y1', 'y2', 'y3', 'm1', 'm2', 'm3', 'm4', 'm5'], array([0.35, 0.36, 0.45, 0.43, 0.44, 0.45, 0.48, 0.45]))
Please help understand the issue here !