144-4 Making a bar plot and centering bars

This section states that the Axes.bar() function takes a left parameter, but I don’t see that in the documentation and it doesn’t seem to be the right parameter in my case.

However I do see it in this doc ?

When going through this exercise on Jupyter, I needed to change the bar positions from :
bar_positions = arange(5) + 0.75
bar_positions = range(1,6)
in order for tick labels and bars to align in center. Note that I also used align=center in ax.bar() prior to making the change and it still did not center them.

Does anyone know what’s up with the the way this is presented in the exercise and/or the documentation?

Here the full code I ended up using :

#Positions of bars
bar_positions = range(1,6)
#np.arange(5) + 0.75  #this did not represent the left of bar 

# Heights of the bars.  In our case, the average rating for the first movie in the dataset.
num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
bar_heights = norm_reviews[num_cols].iloc[0].values

fig,ax = plt.subplots()

ax.bar(bar_positions, bar_heights, .5, align='center')

#Setting the axis ticks and labels 
tick_positions = range(1,6)

num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']
ax.set_xticklabels(num_cols, rotation=90)

#Setting x,y labels & plot title 
plt.xlabel('Rating Source')
plt.ylabel('Average Rating')
plt.title('Average User Rating For Avengers: Age of Ultron (2015)')


I believe the version of matplotlib used in the platform is different and that may be where the trouble is. It’s mentioned in this post how to check what version of each package you’re using. Here’s the Matplotlib version 1.5.1 documentation that shows the left parameter for Axes.bar() so you can see how it compares with the 3.1.1 you linked to.

1 Like

Thanks that helped !