Line column chart with Python
A line column chart is a type of visualization that combines both line and column charts together, using dual axes displayed on the left and right sides of the chart. It allows us to show the relationship of two variables with different magnitudes and scales.
More about: Line column chart
Line column chart
# import libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
'unhcrpyplotstyle','linecolumn'])
plt.style.use([
#compute data array for plotting
= pd.read_csv('https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/change_over_time/line_column.csv')
df
#compute data for plotting
= df['year']
x = df['displaced_population']
y_col = df['displaced_proportion']
y_line
#plot the bar
= plt.subplots()
fig, ax1 =ax1.bar(x, y_col, label = 'Displaced population')
bar_plot#set y axis limits
= plt.ylim(0,100)
ylim1
#plot the line that share the same x-axis with bar
= ax1.twinx()
ax2 =ax2.plot(x, y_line, color='#EF4A60', label = 'Porportion displaced')
line_plot#set y axis limits
= plt.ylim(0,10)
ylim2
#set x axis ticks
ax1.set_xticks(x)
#set chart title
'Trend of global displacement | 2007 - 2016', pad=50)
ax1.set_title(
#set chart legend
=(0,1.05), ncol=1)
ax1.legend(loc=(0.3,1.05), ncol=1)
ax2.legend(loc
#set y-axis label
'Displaced population (millions)')
ax1.set_ylabel('Proportion displaced (number displaced per 1,000)')
ax2.set_ylabel(
#remove all ticks
=False,left=False)
ax1.tick_params(bottom=False, right=False)
ax2.tick_params(bottom
#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()