Getting this error:
TypeError: ‘Axes’ object is not subscriptable
this is the code :
fig, ax = plt.subplots(len(job_titles), 1)
sns.set_theme(style='ticks')
for i, job_title in enumerate(job_titles):
df_plot = df_skills_count[df_skills_count['job_title_short'] == job_title].head(5)[::-1]
sns.barplot(data=df_plot, x='skill_count', y='job_skills', ax=ax[i], hue='skill_count', palette='dark:b_r')
ax[i].set_title(job_title)
ax[i].invert_yaxis()
ax[i].set_ylabel('')
ax[i].set_xlabel('')
ax[i].get_legend().remove()
ax[i].set_xlim(0, 45000) # make the scales the same
fig.suptitle('Counts of Skills Requested in US Job Postings', fontsize=15)
fig.tight_layout(h_pad=0.5) # fix the overlap
plt.show()
This is the whole error I’m getting:
TypeError Traceback (most recent
Cell In[44], line 7
5 for i, job_title in enumerate(job_titles):
6 df_plot = df_skills_count[df_skills_count['job_title_short'] == job_title].head(5)[::-1]
----> 7 sns.barplot(data=df_plot, x='skill_count', y='job_skills', ax=ax[i], hue='skill_count', palette='dark:b_r')
8 ax[i].set_title(job_title)
9 ax[i].invert_yaxis()
TypeError: 'Axes' object is not subscriptable
can someone suggest how can i fix this error or what if wrong in this error?
enter image description here
I am trying to get this plot.
Akshar Kher is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.