简体   繁体   中英

Invalid syntax in python while trying to plot a pareto graph

Currently, I am trying to plot a Pareto graph with some data from the vaccination in my municipality. So, to do that, I have planned to plot the absolute cumulative frequency of vaccinated individuals on the left y axis, the date of vaccination on the x axis, and the relative frequency on the right y axis.

'''

fig,(ax1, ax2) = plt.subplots(2,1,figsize=(15,15))

ax1.set_title('Relative Frequency of vaccinated ageGroup individuals by date of vaccination', fontsize= 20)
ax1.set_ylabel('Relative Frequency of vaccinated individuals by ageGroup (%)', fontsize = 15)
ax1.set_ylim([-10,10])
ax1.tick_params(axis='y', labelcolor=color2)
ax1.bar(df.filter(items=['data_vacinacao', 'ageGroup','individuos']).count().sort_values('data_vacinacao', ascending = False).unstack().plot(ax1=ax1)
ax1.set_xticklabels(df['date_vacination'], rotation=45, size=20)
ax1.set_yticklabels(df['individuals'], size=20)

ax2 = ax1.twinx()
    ax2.set_xlabel('Months', fontsize = 15)
    ax2.set_yticklabels(df['cum (%)'])
    ax2.plot(df.filter(items=['date_vacination'', 'ageGroup', 'ageGroup freq(%)']).count().sort_values('data_vacinacao', ascending = False)
    ax2.tick_params(axis = 'y',labelcolor = color2)
    ax2.set_ylim([0,120])

    
plt.show()

''' Resulting in:

File "<ipython-input-31-76f5d92b64c9>", line 8
    ax1.set_xticklabels(df['date_vacination'], rotation=45, size=20)
    ^
SyntaxError: invalid syntax

But, whenever I change the content on line 8, the invalid syntax continues to appear referring to the code that follows line 8.

Is there anything I can do to change it?

The syntax error is on line 8 because it's trying to finish parsing line 7 and it didn't find what it expected. In this case, line 7 is missing a closing ) . So unless the next thing it encounters is a comma or parenthesis, it's going to raise a syntax error on whatever it finds next, whether that's line 8 or line 9 if you comment line 8 out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM