Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: inner() got multiple values for keyword argument 'ax'

Tags:

matplotlib

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?

like image 337
Vanna Avatar asked Dec 09 '17 09:12

Vanna


1 Answers

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,

  1. call plt.plot(...) to plot to the current axes. Set the current axes with plt.sca(), or
  2. directly call the plot() 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])
like image 100
ImportanceOfBeingErnest Avatar answered Oct 23 '22 16:10

ImportanceOfBeingErnest