Histogram with python
A histogram displays the distribution of data over a continuous interval or specific time period. The height of each bar in a histogram indicates the frequency of data points within the interval/bin. It’s a great tool to identify where values are concentrated, or if there are extreme values or gaps in the dataset.
More about: Histogram
Histogram
# import libraries
import matplotlib.pyplot as plt
import pandas as pd
'unhcrpyplotstyle','histogram'])
plt.style.use([
#load data set
= pd.read_csv('https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/distribution/histogram.csv')
df
#compute data array for plotting
= df['poc_age']
x = 25
num_bins
#plot the chart
= plt.subplots()
fig, ax = ax.hist(x, num_bins)
histo
#set x,y axis limits
= plt.xlim(0,100)
xl = plt.ylim(0,35)
yl
#set chart title
'Age distribution | 2020')
ax.set_title(
#set axis label
'Number of people')
ax.set_ylabel('Age')
ax.set_xlabel(
#set chart source and copyright
'Source: UNHCR Refugee Data Finder', (0,0), (0, -25), xycoords='axes fraction', textcoords='offset points', va='top', color = '#666666', fontsize=9)
plt.annotate('©UNHCR, The UN Refugee Agency', (0,0), (0, -35), xycoords='axes fraction', textcoords='offset points', va='top', color = '#666666', fontsize=9)
plt.annotate(
#adjust chart margin and layout
fig.tight_layout()
#show chart
plt.show()