# 赛博朋克这么火，如果与Python结合，能有多酷？

《赛博朋克2077》，最近一款非常火的单机游戏～

GitHub：

https://github.com/dhaitz/mplcyberpunk

pip install mplcyberpunk

import matplotlib.pyplot as plt

import mplcyberpunk

# 添加样式

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’ )

# 设置线条发光+面积图

plt.show()

import numpy as np

import mplcyberpunk

import matplotlib.pyplot as plt

plt.style.use( “cyberpunk” )

# 数据

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)

# 线条发光

mplcyberpunk.make_lines_glow()

# 面积图

# 保存图片

“defalut.png”

)

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]

# 设置颜色样式，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()

# 标题名，cool、spring、winter、tab20、coolwarm

plt.title( “Colormap: ‘coolwarm'” )

“colormap.png”

)

GitHub：

https://github.com/ColCarroll/ridge_map

# 安装

pip install ridge_map

# 安装库的依赖

pip install scikit-image==0.14.2

import matplotlib.font_manager as fm

import matplotlib.pyplot as plt

from ridge_map import RidgeMap

import mplcyberpunk

# 赛博朋克样式

plt.style.use( “cyberpunk” )

# 中文显示

plt.rcParams[ ‘font.sans-serif’ ] = [ ‘SimHei’ ] # Windows

plt.rcParams[ ‘font.sans-serif’ ] = [ ‘Hiragino Sans GB’ ] # Mac

plt.rcParams[ ‘axes.unicode_minus’ ] = False

# 字体

font_prop = fm.FontProperties(fname= “方正兰亭刊黑.ttf” )

# 获取数据，此处需特殊技巧才能成功

rm = RidgeMap(bbox=( -156.250305 , 18.890695 , 154.714966 , 20.275080 ), font=font_prop)

# 设置线条数，朝向，以及其他属性

values = rm.get_elevation_data(num_lines= 200 , viewpoint= ‘north’ )

values = rm.preprocess(values=values,

water_ntile= 10 ,

vertical_ratio= 240 )

# 设置标题，线条颜色，背景颜色等

rm.plot_map(values, label= “夏威夷” , kind= ‘gradient’ , line_color=plt.get_cmap( ‘spring’ ), background_color= ‘#212946’ )

‘夏威夷.png’

)

import matplotlib.font_manager as fm

import matplotlib.pyplot as plt

from ridge_map import RidgeMap

import mplcyberpunk

# 赛博朋克样式

plt.style.use( “cyberpunk” )

# 中文显示

plt.rcParams[ ‘font.sans-serif’ ] = [ ‘SimHei’ ] # Windows

plt.rcParams[ ‘font.sans-serif’ ] = [ ‘Hiragino Sans GB’ ] # Mac

plt.rcParams[ ‘axes.unicode_minus’ ] = False

# 字体

font_prop = fm.FontProperties(fname= “方正兰亭刊黑.ttf” )

# 获取数据，此处需特殊技巧才能成功

rm = RidgeMap(bbox=( 122.014 , 25.344 , 120.036 , 21.902 ), font=font_prop)

# 设置线条数，朝向，以及其他属性

values = rm.get_elevation_data(num_lines= 200 , viewpoint= ‘north’ )

values = rm.preprocess(values=values,

water_ntile= 10 ,

vertical_ratio= 240 )

# 设置标题，线条颜色，背景颜色等

rm.plot_map(values, label= “台湾省” , kind= ‘gradient’ , line_color=plt.get_cmap( ‘spring’ ), background_color= ‘#212946’ )

‘台湾省.png’

)