Skip to content

Instantly share code, notes, and snippets.

@abhishek-shrm
Created May 4, 2020 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhishek-shrm/af3c0982ac77b0c1c5d05ffb86ccd651 to your computer and use it in GitHub Desktop.
Save abhishek-shrm/af3c0982ac77b0c1c5d05ffb86ccd651 to your computer and use it in GitHub Desktop.
temp_summer=[ random.uniform(20,40) for i in range(5)]
temp_winter=[ random.uniform(0,10) for i in range(5)]
fig=plt.figure(figsize=(10,6))
city=['City A','City B','City C','City D','City E']
x_pos_summer=list(range(1,6))
x_pos_winter=[ i+0.4 for i in x_pos_summer]
graph_summer=plt.bar(x_pos_summer, temp_summer,color='tomato',label='Summer',width=0.4)
graph_winter=plt.bar(x_pos_winter, temp_winter,color='dodgerblue',label='Winter',width=0.4)
plt.xticks([i+0.2 for i in x_pos_summer],city)
plt.title('City Temperature')
plt.ylabel('Temperature ($^\circ$C)')
#Annotating graphs
for summer_bar,winter_bar,ts,tw in zip(graph_summer,graph_winter,temp_summer,temp_winter):
plt.text(summer_bar.get_x() + summer_bar.get_width()/2.0,summer_bar.get_height(),'%.2f$^\circ$C'%ts,ha='center',va='bottom')
plt.text(winter_bar.get_x() + winter_bar.get_width()/2.0,winter_bar.get_height(),'%.2f$^\circ$C'%tw,ha='center',va='bottom')
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment