I am plotting a bar graph showing Age Group at Intake of shelter Animals eventually adopted but I keep getting the error: "AttributeError: 'function' object has no attribute 'xlabel'"
So my plot is showing no y axis labels or no plot title. I have imported matplotlib as plt.
Here's my code:
import pandas as pd
import matplotlib as plt
# ensuring 'Age Range at Intake' column is string type:
shelter_df['Animal', 'Age Range at Intake'] = shelter_df['Age Range at Intake'].astype(str)
# Filtering data for adoption:
adoptionData = shelter_df[shelter_df['Outcome Type'] == 'Adoption']
# Grouping and counting data by Age Range at Intake and Animal type:
ageAnimalAdoptCounts = adoptionData.groupby(['Age Range at Intake', 'Animal']).size().unstack()
# plotting a bar chart to show Animal Types adopted per Age Group:
ax = ageAnimalAdoptCounts.plot(kind = 'bar', stacked = True, figsize = (12, 6))
plt.figure(figsize = (12, 6))
ax.set.xlabel('Age Range at Intake')
ax.set.ylabel('Count')
ax.set.title('Animal Types adopted per Age Group at Intake')
ax.set.xticklabels(ax.get.xticklabels(), rotation = 45, ha = 'right')
plt.tight_layout()
plt.show()
Chart showing no axis labels or title
Does anyone have any ideas what could be wrong?
I've tried importing matplotlib.pyplot as plt but doesn't make a difference. I want the y axis labels and title to be displayed on the plot. Thank you.