Cyberpunk 2077" is a very popular single-player game ~
The game is set in the year 2077, a highly developed technology but chaotic and disorderly "cyberpunk" city.
In this world, although the technology is highly developed, but the standard of living of human beings is extremely low, or the standard of living of the poor is extremely low.
Moreover, in addition to a very small number of rich capitalists, the rest are all poor.
So, this is a world of extremes, containing a very large number of elements. Visually, the bustling three-dimensional city is full of neon lights, artificial light is all the light source, and there is not even sunlight.
Correspondingly, in the slums, it is dark and humid.
Virtual and real boundaries are blurred, artificial intelligence and artificial people are silly, the poor and the rich are extremely divided, and terrorism abounds everywhere.
This issue is about introducing a "cyberpunk" style Python package, "mplcyberpunk".
First install via pip.
pip install mplcyberpunk
Let's look at the first example first.
import matplotlib.pyplot as plt
import mplcyberpunk
# Add style
plt.style.use("cyberpunk")
plt.plot([1, 3, 9, 5, 2, 1, 1], marker='o')
plt.plot([4, 5, 5, 7, 9, 8, 6], marker='o')
# Set line glow + area map
mplcyberpunk.add_glow_effects()
plt.show()
Obtain a line glow area map.
It does fit well with the neon style of cyberpunk, artificial light.
A look at the library's source code file core.py reveals two main functions of the library.
That is, make_lines_glow (line glow) and add_underglow (line area map).
We will use each method once in the following.
import numpy as np
import mplcyberpunk
import matplotlib.pyplot as plt
plt.style.use("cyberpunk")
# Data
x = np.arange(-7, 7, 0.1)
y1 = np.sin(x)
y2 = np.sin(x) + x
y3 = np.sin(x) * x
y4 = np.sin(x) / x
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.plot(x, y4)
# Line glow
mplcyberpunk.make_lines_glow()
# Area Map
mplcyberpunk.add_underglow()
# Save image
plt.savefig("defalut.png")
The first one is the default format, the second one adds line glow, and the third one is line glow + area map.
There are also some other types of colors that can be customized.
The default colormap is cool.
import matplotlib.pyplot as plt
from matplotlib import cm
import mplcyberpunk
import numpy as np
# time
t = np.arange(0, 6.4, 0.1)
# frequency
f = 1
amplitudes = np.arange(-10, 11, 1)
# amplitude
A = [x * np.cos(f*t) for x in amplitudes]
# Set color style,cool、spring、winter、tab20、coolwarm
colormap_sect = np.linspace(0, 1, len(amplitudes))
colors = [cm.coolwarm(x) for x in colormap_sect]
plt.rcParams['figure.figsize'] = [6, 4]
plt.style.use("cyberpunk")
plt.xlim(right=6.3)
for i in range(21):
plt.plot(t, A[i], color=colors[i])
mplcyberpunk.make_lines_glow()
# Title Name,cool、spring、winter、tab20、coolwarm
plt.title("Colormap: 'coolwarm'")
plt.savefig("colormap.png")
Get a chart of 5 color schemes.
Finally, a "cyberpunk" style map can be generated.
The ridge map used is the ridge_map.
# Installation
pip install ridge_map
# Installing library dependencies
pip install scikit-image==0.14.2
Note here that you need to specify version 0.14.2 when installing scikit-image, otherwise it will report an error.
Since the library ridge_map has more content, I won't expand on it.
import matplotlib.font_manager as fm
import matplotlib.pyplot as plt
from ridge_map import RidgeMap
import mplcyberpunk
# Cyberpunk style
plt.style.use("cyberpunk")
# Chinese display
plt.rcParams['font.sans-serif'] = ['SimHei'] # Windows
plt.rcParams['font.sans-serif'] = ['Hiragino Sans GB'] # Mac
plt.rcParams['axes.unicode_minus'] = False
# Fonts
font_prop = fm.FontProperties(fname="name.ttf")
# Get the data, special skills are needed here to succeed
rm = RidgeMap(bbox=(-156.250305, 18.890695, 154.714966, 20.275080), font=font_prop)
# Set the number of lines, orientation, and other properties
values = rm.get_elevation_data(num_lines=200, viewpoint='north')
values = rm.preprocess(values=values,
water_ntile=10,
vertical_ratio=240)
# Set title, line color, background color, etc.
rm.plot_map(values, label="夏威夷", kind='gradient', line_color=plt.get_cmap('spring'), background_color='#212946')
plt.savefig('夏威夷.png')
Get the ridge map of Hawaii Island, punk style full of it!
It seems to be possible to use the heightmaps format images directly, interested partners, you can try it yourself!