Simple Visualization of Poverty Overview in Indonesia using Matplotlib

Image for post
Image for post
Photo by Zeyn Afuang on Unsplash

Import Modules

import pandas as pdimport numpy as npimport matplotlib.pyplot as plt%matplotlib inline #%matplotlib inline sets the backend of matplotlib to the ‘inline’ backendplt.style.use(‘ggplot’) #for better style of graphpd.set_option(‘float_format’, ‘{:.2f}’.format)

Import Data

xls = pd.ExcelFile(r’indonesia_poverty.xlsx’)data = xls.parse(0)data = data.dropna()data.tail()
Image for post
Image for post

Data Plotting

def text_value(x, y):for i,j in zip(x, y):plt.annotate(str(“{:.2f}”.format(j)), (i,j))fig, ax = plt.subplots(figsize=(20,7))x_axis = data[‘Tahun’].iloc[-19:]y1, y2, y3 = data[‘Jumlah Penduduk Miskin (Kota)’].iloc[-19:], data[‘Jumlah Penduduk Miskin (Desa)’].iloc[-19:], data[‘Jumlah Penduduk Miskin (Total)’].iloc[-19:]plt.plot(x_axis, y1, linestyle=’dashed’, marker=’o’, markersize=12)text_value(x_axis, y1)plt.plot(x_axis, y2, linestyle=’dashed’, marker=’o’, markersize=12)text_value(x_axis, y2)plt.plot(x_axis, y3, linestyle=’dashed’, marker=’o’, markersize=12)text_value(x_axis, y3)ax.set_ylabel(‘Total Population Living in Poverty (in million)’)plt.title(‘Comparison of Total Population Living under Poverty Line in Indonesia’)plt.legend([‘Total Urban Population Living in Poverty’, ‘Total Village Population Living in Poverty’, ‘Overall Total Population Living in Poverty’])
Image for post
Image for post
fig, ax = plt.subplots(figsize=(20,7))x_axis = np.arange(19)y1, y2, y3 = data[‘Persentase Kemiskinan (Kota)’].iloc[-19:], data[‘Persentase Kemiskinan (Desa)’].iloc[-19:], data[‘Persentase Kemiskinan (Total)’].iloc[-19:]plt.bar(x_axis, y1, width=0.2, align=’center’)plt.bar(x_axis+0.2, y2, width=0.2, align=’center’)plt.bar(x_axis+2*0.2, y3, width=0.2, align=’center’)ax.set_xticks(x_axis+0.2)ax.set_xticklabels( [i for i in data[‘Tahun’].iloc[-19:]] )ax.set_ylabel(‘Poverty Percentage (%)’)plt.title(‘Poverty Percentage Comparison in Indonesia’)plt.legend([‘Urban Poverty Percentage’, ‘Village Poverty Percentage’, ‘Overall Poverty Percentage’])
Image for post
Image for post
x_axis = np.arange(36–23)y1, y2 = data[‘Garis Kemiskinan Desa’].iloc[23:36], data[‘Garis Kemiskinan Kota’].iloc[23:36]plt.barh(x_axis, y1, height=0.3, align=’center’)plt.barh(x_axis+0.3, y2, height=0.3, align=’center’)ax.set_yticks(x_axis+0.15)ax.set_yticklabels( [i for i in data[‘Tahun’].iloc[23:36]] )ax.set_xlabel(‘Poverty Line (Rp)’)plt.title(‘Poverty Line Comparison in Urban and Village Area’)plt.legend([‘Village Poverty Line’, ‘Urban Poverty Line’])
Image for post
Image for post
fig = plt.figure(figsize=(20,8))y = data[‘Garis Kemiskinan Kota’].iloc[-19:]x = data[‘Tahun’].iloc[-19:]for i,j in zip(x, y):plt.annotate(int(j), (i,j))plt.ylabel(‘Poverty Line (Rp)’)plt.title(‘Indonesia\’s Poverty Line Graph’)plt.plot(x,y,marker=’o’, markersize=10, markerfacecolor=’white’, linestyle=’:’)
Image for post
Image for post

〖A data geek 📊〗〖Life-long learner〗〖ESFP-T〗〖✨ŸØⱠØ✨〗

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store