Xticklabels not displaying

Hi all,
I’m working on the Star Wars survey project and trying to create grouped bar charts of the rankings and movies seen by gender. Everything works except my the labels for my x ticks. Here is my code:

names_map = ['The Phantom Menace', 'Attack of the Clones', 'Revenge of the Sith',
            'A New Hope', 'The Empire Strikes Back', 'Return of the Jedi']

#create a bar plot of the rankings by gender
fig, ax = plt.subplots()
bar_positions = np.arange(len(names_map))
width = 0.35
men_rankings = ax.bar(bar_positions - width/2, male_rankings, width, label='Men')
women_rankings = ax.bar(bar_positions + width/2, female_rankings, width, label='Women')
ax.set_title('Movie Rankings by Gender')
ax.set_ylabel('Average Rank')
ax.legend()
ax.set_xticks(bar_positions)
ax.set_xticklabels=(names_map)
plt.show()

#create a bar plot of the movies seen by gender
fig, ax = plt.subplots()
bar_positions = np.arange(len(names_map))
width = 0.35
men_rankings = ax.bar(bar_positions - width/2, male_seen_cols, width, label='Men')
women_rankings = ax.bar(bar_positions + width/2, female_seen_cols, width, label='Women')
ax.set_title('Films Seen')
ax.set_ylabel('Respondents Who\'ve Seen the Film')
ax.legend()
ax.set_xticks(bar_positions)
ax.set_xticklabels=(names_map)
plt.show()

What I expected to happen:
The list names_map should become the xticklabels.

What actually happened:
Xticklabels don’t display at all. In fact, no matter what I do, I can’t seem to get the xticks to display any label other than the default 0-5. Anyone see anything glaringly obvious that I’m missing?

Thanks in advance!

Hi @jwb0026

Since I don’t have the structure for male_rankings etc. variables. I tried for my own plot using a dummy_list like names_map.

ax.set_xticklabels(names_map) this worked for me. Let us know if this doesn’t work for you.

What intrigues me is, there is no syntax error when we use = in between. :thinking:

1 Like

That worked!

I can’t believe I didn’t notice that. I swear I stared at that code and twenty different examples from the matplotlib docs and Stackoverflow and still missed it! Yeah, it’s really weird that there was no syntax error. I can usually figure out an issue if I have an error to google, but this just didn’t work. Very strange.

Anyway, thanks for your help. I really appreciate it!