Line column chart with Python

Cedric Vidonne

Lei Chen

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'])

#compute data array for plotting
df = pd.read_csv('')

#compute data for plotting
x = df['year']
y_col = df['displaced_population']
y_line = df['displaced_proportion']

#plot the bar
fig, ax1 = plt.subplots(), y_col, label = 'Displaced population')
#set y axis limits
ylim1 = plt.ylim(0,100)

#plot the line that share the same x-axis with bar
ax2 = ax1.twinx()
line_plot=ax2.plot(x, y_line, color='#EF4A60', label = 'Porportion displaced')
#set y axis limits
ylim2 = plt.ylim(0,10)

#set x axis ticks

#set chart title
ax1.set_title('Trend of global displacement | 2007 - 2016', pad=50)

#set chart legend
ax1.legend(loc=(0,1.05), ncol=1)
ax2.legend(loc=(0.3,1.05), ncol=1)

#set y-axis label
ax1.set_ylabel('Displaced population (millions)')
ax2.set_ylabel('Proportion displaced (number displaced per 1,000)')

#remove all ticks
ax2.tick_params(bottom=False, right=False)

#set chart source and copyright
plt.annotate('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)

#adjust chart margin and layout

#show chart

A line column chart showing trend of global displacement | 2007 - 2016

Related chart with Python