in

Construct a Higher Bar Chart with This Trick | by Lee Vaughan | Aug, 2023


(It’s actually a seaborn scatter plot!)

A part of an “Age of Congress” scatter plot (all photographs by the writer)

Each time I want inspiration for efficient visualizations, I browse The Economist, the Visual Capitalist, or The Washington Post. Throughout considered one of these forays, I ran throughout an fascinating infographic — much like the one proven above — that plotted the age of every member of the US Congress towards their generational cohort.

My first impression was that this was a horizontal bar chart, however nearer inspection revealed that every bar was composed of a number of markers, making it a scatter plot. Every marker represented one member of Congress.

On this Fast Success Knowledge Science venture, we’ll recreate this enticing chart utilizing Python, pandas, and seaborn. Alongside the way in which, we’ll unlock a cornucopia of marker varieties you might not know exist.

As a result of the USA has Age of Candidacy legal guidelines, the birthdays of members of Congress are a part of the general public document. You’ll find them in a number of locations, together with the Biographical Directory of the United States Congress and Wikipedia.

For comfort, I’ve already compiled a CSV file of the names of the present members of Congress, together with their birthdays, department of presidency, and celebration, and saved it on this Gist.

The next code was written in Jupyter Lab and is described by cell.

Importing Libraries

from collections import defaultdict  # For counting members by age.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import patches # For drawing bins on the plot.
import pandas as pd
import seaborn as sns

Assigning Constants for the Generational Knowledge

We’ll annotate the plot in order that generational cohorts, similar to Child Boomers and Gen X, are highlighted. The next code calculates the present age spans for every cohort and contains lists for technology names and spotlight colours. As a result of we need to deal with these lists as constants, we’ll capitalize the names and use an underscore as a prefix.

# Put together generational knowledge for plotting as bins on chart:
CURRENT_YEAR = 2023…


Eye of the Beholder

Learn how to Use Chat-GPT and Python to Construct a Data Graph in Neo4j Primarily based on Your Personal Articles | by Kasper Müller | Aug, 2023