What is the use of 0.75 with the arrange function from numpy (in bar_positions)

Screen Link:
https://app.dataquest.io/m/144/bar-plots-and-scatter-plots/4/creating-bars

My Code:

import matplotlib.pyplot as plt
from numpy import arange
num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']

bar_heights = norm_reviews[num_cols].iloc[0].values
bar_positions = arange(5) + 0.75

fig,ax=plt.subplots()
ax.bar(bar_positions,bar_heights,0.5)
plt.show()

Kindly explain the use of arange function here and why we added 0.75 to values generated by this function.

@joshi.ananya.joshi1

If you saw the figure in instruction of that page, You will see that we want bars to start at specific position [.75,1.75,2.75,3.75,4.75]

arange function creates this list [0,1,2,3,4] . So for this case we are adding .75 to get the exact position of bars.

If you don’t know about arange function then please check it out here

Try this, it will also work fine
arange(.75,5.75,1) if you use this you won’t have to add .75 seperately, it will create this list directly [0.75,1.75,2.75,3.75,4.75]

Hope it clarifies your question!!

3 Likes