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
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.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) ax.set_xticks(tick_positions) 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)') plt.show()