Publish AI, ML & data-science insights to a global community of data professionals.

How to Make Cyberpunk “Dark Mode” Data Visualizations in Python

Neon Lines and Dark Designs, An Introduction

I’ve always loved a dark background on a chart with neon lines for their aesthetic, and also their improved accessibility for certain types of vision impairments – in this article we’ll be discussing how you can make some very cool and aesthetically pleasing cyberpunk-style charts in Python.

(ps. shoutout to one of my early Analytics managers who said my charts were ugly and unprofessional – you’d hate this article! 👋 )

Image created by me, using DALL-E
Image created by me, using DALL-E

At Chime, my friend Maia Bittner and I used to create charts that looked like this in Google Sheets and Excel, by manually selecting all of the neon colors to make our data eye catching + engaging. With this method, you can easily generate them in Python too!

Now, let’s take a look at how we can create some cool cyberpunk style neon data visualizations using the Palmer Penguins dataset which you can access directly in your python notebook by installing palmerpenguins

💫 Enter mplcyberpunk, a "Python package on top of matplotlib to create ‘cyberpunk’ style plots with 3 additional lines of code."

First, make sure to install the packages we’ll need for this tutorial before proceeding, and load the penguins dataset like so:

pip install palmerpenguins
pip install mplcyberpunk
from palmerpenguins import load_penguins
import matplotlib.pyplot as plt
import mplcyberpunk

# Load the penguin dataset
penguins = load_penguins()

Now, we’re ready to incorporate cyberpunk into our charts, this package works best with line charts, so let’s take a look at the distribution of body mass in different species of penguin.

Image created by the author. Code to generate this data visualization below:
Image created by the author. Code to generate this data visualization below:
# Create the plot with the cyberpunk style
plt.style.use("cyberpunk")
fig, ax = plt.subplots(figsize=(10, 6))

# Define the colors for each species
species_colors = {
    'Adelie': 'cyan',
    'Chinstrap': 'magenta',
    'Gentoo': 'yellow'
}

# Plot KDE for body mass by species
for species in penguins['species'].unique():
    subset = penguins[penguins['species'] == species]
    sns.kdeplot(subset['body_mass_g'], ax=ax, lw=3, color=species_colors[species])

# Enhance with cyberpunk style
mplcyberpunk.add_glow_effects()

# Manually create legend handles and labels
handles = [plt.Line2D([], [], color=species_colors[species], label=species, linewidth=3) for species in penguins['species'].unique()]

# Create the legend
ax.legend(handles=handles, title='Species')
legend = ax.get_legend()
plt.setp(legend.get_texts(), color='white')

# Set the title and labels
ax.set_title('Body Mass Distribution by Species')
ax.set_xlabel('Body Mass (g)')
ax.set_ylabel('Density')
plt.show()

Another example of how to create unique + eye-catching cyberpunk styled charts in a situation where you want to visualize time series data (chart created using dummy data) – the glow effect available in this package lends itself very well to time series and percent change charts in particular:

Image created by the author.
Image created by the author.

The Cyberpunk package works best with line charts, but here’s an example of how we can use it to visualize the correlation of Penguin stats in a scatterplot, which still looks pretty cool!

Image created by the author. Code to generate this data visualization below:
Image created by the author. Code to generate this data visualization below:
# Create the plot with the cyberpunk style
plt.style.use('cyberpunk')
fig, ax = plt.subplots(figsize=(8, 6))
scatter = ax.scatter(penguins['flipper_length_mm'], penguins['body_mass_g'], s=30,
                     c=penguins['island'].astype('category').cat.codes, cmap='cool')

# Enhance the plot with cyberpunk style glow effect
mplcyberpunk.make_scatter_glow(ax)

# Set the title and labels
ax.set_title("Penguin Stats- Flipper Length vs Body Mass By Island")
ax.set_xlabel("Flipper Length (mm)")
ax.set_ylabel("Body Mass (g)")
plt.show()

In summary, this package is a great addition to your Python data viz tool kit to up-level boring + basic matplotlib charts. A large part of our job as data scientists and analysts is to engage our audience, and one way to do that is to create eye-catching charts. I’d love to hear if you try this out! Let me know if you give it a go ✨

Big shoutout to the creator of this package, Dominik Haitz. You can find his work on Github! 👇

GitHub – dhaitz/mplcyberpunk: "Cyberpunk style" for matplotlib plots


And if you like Data + AI, please check out my other stories! 👇

Thanks for reading.

SQL Mastery: Advanced Techniques for Data Professionals


Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.

Write for TDS

Related Articles