Created
May 4, 2020 05:37
-
-
Save abhishek-shrm/f5f0ef8aa69860c698330cf36b9714a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.title('City Temperature') | |
plt.ylabel('Temperature ($^\circ$C)') | |
# removing axes from the figure | |
plt.gca().spines['right'].set_visible(False) | |
plt.gca().spines['top'].set_visible(False) | |
#Modifiying ticks | |
plt.xticks([i+0.2 for i in x_pos_summer],city,fontname='Chilanka',rotation=45,fontsize=14) | |
#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