I tried to run the below code:
Code:
df1=pd.read_excel('F:/MRCS_New_struture/2. EHM_Vanna/2015 Reports/Statistic_Env.xlsx', sheetname='Daitom (2)', header=0, index_col='Year')
CaAB=df1.iloc[:5,17:34]; print CaAB
a=[2007, 2008, 2011, 2013, 2015]
b=[100,200,300,500,22.33]
fig, ax=plt.subplots(2,1)
plt.plot(a, b, 'go-', label='line 1', linewidth=2, ax=ax)
plt.xticks(a, map(str,a))
CaAB.plot(kind='bar', ax=ax)
And, it generated error (TypeError: inner() got multiple values for keyword argument 'ax'). What's wrong to my code?
ax is not a valid argument for plt.plot(). The reason is that plt.plot() will call the plot method of the current active axes, same as plt.gca().plot(). Hence the axes is already given by the instance itself. Supplying it again as keyword argument does not make any sense and eventually produces the error.
Solution: Don't use ax as argument to plt.plot(). Instead,
plt.plot(...) to plot to the current axes. Set the current axes with plt.sca(), orplot() method of the axes. ax.plot(...)
Mind that in the example from the question, ax is not an axes. If this is confusing, name it differently,
fig, ax_arr = plt.subplots(2,1)
ax_arr[0].plot(a, b, 'go-', label='line 1', linewidth=2)
ax_arr[0].set_xticks(a)
ax_arr[0].set_xticklabels(list(map(str,a)))
df.plot(kind='bar', ax=ax_arr[1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With