Introduction to mplcyberpunk Project
The mplcyberpunk project is a unique Python package designed to add a futuristic 'cyberpunk' aesthetic to data visualizations made with Matplotlib, a popular plotting library. With just a few extra lines of code, users can transform ordinary charts into vibrant, stylized graphics reminiscent of futuristic sci-fi environments.
Installation
To get started with mplcyberpunk, users simply need to install it via pip, Python's package manager, using the following command:
pip install mplcyberpunk
How to Use mplcyberpunk
After installation, users can apply the cyberpunk style to their plots by importing the package and using the Matplotlib style feature. The cyberpunk style mainly features dark backgrounds combined with neon-colored lines that glow.
Here’s a quick example of how it works:
-
Import the necessary modules:
import matplotlib.pyplot as plt import mplcyberpunk
-
Apply the cyberpunk style:
Use the cyberpunk stylesheet to start styling your plot:
plt.style.use("cyberpunk")
-
Create your plot:
Plot your data as usual. Here’s an example of plotting two lines:
plt.plot([1, 3, 9, 5, 2, 1, 1], marker='o') plt.plot([4, 5, 5, 7, 9, 8, 6], marker='o')
-
Add glow effects:
To enhance your plot with a glowing effect:
mplcyberpunk.add_glow_effects()
-
Display the plot:
Finally, to display the plot, call:
plt.show()
The above steps create a striking plot with glowing lines against a dark background, capturing the essence of cyberpunk aesthetics.
Customizing Effects
Adding Effects Individually
Users can separately add line glow and underglow effects instead of all at once using the following commands:
-
Line Glow Effect:
mplcyberpunk.make_lines_glow()
-
Underglow Effect:
mplcyberpunk.add_underglow()
These effects can be applied to specific lines or axes by passing the respective object as an argument.
Gradient Glow
For those interested in a gradient underglow effect, mplcyberpunk provides options to add this effect either together with the line glow:
mplcyberpunk.add_glow_effects(gradient_fill=True)
Or, independently:
mplcyberpunk.add_gradient_fill(alpha_gradientglow=0.5)
The gradient effect can be customized using the gradient_start
parameter to adjust the gradient starting point.
Applying Effects to Other Charts
The glow effects of mplcyberpunk are not limited to line plots. For scatter plots, users can enhance them by calling mplcyberpunk.make_scatter_glow()
. Additionally, bar charts can have a gradient glow applied using the mplcyberpunk.add_bar_gradient()
function, providing a wide range of styling options.
Default and Additional Colormaps
The default color scheme used by mplcyberpunk is the 'cool' colormap, which provides a variety of other options for color customization, allowing for additional personalization.
Visual Gallery
mplcyberpunk offers a gallery of examples and potential visualizations, showcasing the package's capability to create stunning graphics:
- World maps with cyberpunk styles
- Gradient-filled plots
- Bar charts with gradients
Some images from the project are even available for purchase as posters, highlighting their artistic appeal.
Requirements
The mplcyberpunk package is lightweight, requiring only Matplotlib to be installed, making it a versatile tool for any Python user aiming to add a touch of cyberpunk flair to their data visualizations.