Column chart
In a column chart, each category is represented by a vertical rectangle, with the height of the rectangle being proportional to the values being plotted.
More about: Column chart - Other tutorials: R Matplotlib D3
Basic column chart
import plotly.express as px
import pandas as pd
import template_
#load data set
df = pd.read_csv('https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/comparison/column.csv')
fig = px.bar(df, x='year', y='displaced_number', title='Global IDP displacement | 2010 - 2020<br><sup>Number of people (in millions)</sup>', text='displaced_number', template="my_template")
# Update axis titles
fig.update_layout(xaxis_title='',
yaxis_title='',
yaxis_showticklabels=False,
yaxis_showgrid=False,)
# Add data labels
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.show()
Grouped column
Grouped column charts are a type of colour-coded column chart used to represent and compare different categories of two or more groups.
More about: Grouped column chart - Other tutorials: R Matplotlib D3
Basic grouped column chart
import plotly.express as px
import pandas as pd
import template_
#load data set
df = pd.read_csv('https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/comparison/column_grouped.csv')
# Define the order of the categories in the legend
category_order = ['East and Horn of Africa and Great Lakes', 'Southern Africa', 'West and Central Africa']
# Create the grouped bar chart
fig = px.bar(df, x='year', y='refugee_number', color='main_office', barmode='group',
title='Refugee numbers by main office and year',
template='my_template',category_orders={'main_office': category_order})
# Update axis titles
fig.update_layout(xaxis_title='',
yaxis_title='Refugee number',
legend_title_text='',
)
fig.show()