
Aquarel是一个轻量级的Python库,用于简化Matplotlib的样式配置,使数据可视化更加美观和高效。
Catppuccin是一个社区驱动的粉彩主题库,提供多种配色方案,适合用于数据可视化的美化。
mplcyberpunk是一个基于Matplotlib的库,用于创建“网络朋克风格”的图表,具有独特的视觉效果。
matplotx是一个扩展Matplotlib功能的库,提供了更多现代化的图表样式和工具。
gruvbox是一个基于复古色调的主题库,适合用于创建复古风格的图表。
bash
pip install aquarel catppuccin mplcyberpunk matplotx gruvboxfrom aquarel import load_theme
import matplotlib.pyplot as plt
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 加载并应用主题
theme = load_theme("arctic_light")
theme.apply()
# 绘制图表
plt.plot(x, y, marker='o', linestyle='-', color='red')
plt.title('Aquarel风格图表',font='SimHei')
plt.xlabel('X轴',font='SimHei')
plt.ylabel('Y轴',font='SimHei')
plt.grid(True)
# 应用转换
theme.apply_transforms()
# 显示图表
plt.show()
import matplotlib.pyplot as plt
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 手动定义Catppuccin颜色(以Mocha主题为例)
catppuccin_colors = {
'rosewater': '#dc8a78',
'flamingo': '#dd7878',
'pink': '#ea76cb',
'mauve': '#8839ef',
'red': '#d20f39',
'maroon': '#e64553',
'peach': '#fe640b',
'yellow': '#df8e1d',
'green': '#40a02b',
'teal': '#179299',
'sky': '#04a5e5',
'sapphire': '#209fb5',
'blue': '#1e66f5',
'lavender': '#7287fd',
'text': '#4c4f69',
'subtext1': '#a6adc8',
'subtext0': '#8087a2',
'overlay0': '#575e75',
'surface0': '#363a4f',
'base': '#1e1e2e',
'mantle': '#181926',
'crust': '#131420'
}
# 创建图表
plt.figure(figsize=(10, 6))
# 设置图表背景
plt.gca().set_facecolor(catppuccin_colors['base'])
# 绘制图表
plt.plot(x, y, marker='o', linestyle='-', color=catppuccin_colors['rosewater'])
# 设置标题和标签
plt.title('Catppuccin风格图表', color=catppuccin_colors['text'],font='SimHei',fontsize=30)
plt.xlabel('X轴', color=catppuccin_colors['subtext1'],font='SimHei',fontsize=30)
plt.ylabel('Y轴', color=catppuccin_colors['subtext1'],font='SimHei',fontsize=30)
# 设置网格
plt.grid(True, linestyle='--', alpha=0.5, color=catppuccin_colors['overlay0'])
# 显示图表
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt
import mplcyberpunk
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 应用网络朋克风格
plt.style.use("cyberpunk")
# 绘制图表
plt.plot(x, y, marker='o', linestyle='-', color='red')
# 添加发光效果
mplcyberpunk.add_glow_effects()
# 设置标题和标签
plt.title('网络朋克风格图表',font='SimHei')
plt.xlabel('X轴',font='SimHei')
plt.ylabel('Y轴',font='SimHei')
# 设置网格
plt.grid(True)
# 显示图表
plt.show()
import matplotlib.pyplot as plt
from aquarel import load_theme
import mplcyberpunk as mp
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 手动定义Catppuccin颜色(以Mocha主题为例)
catppuccin_colors = {
'rosewater': '#dc8a78',
'text': '#4c4f69',
'subtext1': '#a6adc8',
'overlay0': '#575e75',
'base': '#1e1e2e'
}
# 应用Aquarel主题
theme = load_theme("arctic_light")
theme.apply()
# 绘制图表
plt.figure(figsize=(10, 6))
plt.plot(x, y, marker='o', linestyle='-', color='red')
# 设置标题和标签
plt.title('复合风格图表', color=catppuccin_colors['text'], fontsize=30, fontweight='bold',font='SimHei')
plt.xlabel('X轴', color=catppuccin_colors['subtext1'], fontsize=20,font='SimHei')
plt.ylabel('Y轴', color=catppuccin_colors['subtext1'], fontsize=20,font='SimHei')
# 设置网格
plt.grid(True, linestyle='--', alpha=0.5, color=catppuccin_colors['overlay0'])
# 设置背景颜色
plt.gca().set_facecolor(catppuccin_colors['base'])
# 应用Aquarel转换
theme.apply_transforms()
# 显示图表
plt.tight_layout()
plt.show()
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from aquarel import load_theme
# 手动定义Catppuccin颜色(以Mocha主题为例)
catppuccin_colors = {
'rosewater': 'green',
'text': 'red',
'subtext1': 'blue',
'overlay0': 'purple',
'base': 'pink'
}
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
z = [3, 5, 7, 11, 13]
# 应用Aquarel主题
theme = load_theme("arctic_light")
theme.apply()
# 创建3D图表
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# 绘制3D图
ax.plot(x, y, z, c=catppuccin_colors['rosewater'], marker='o')
# 设置标题和标签
ax.set_title('3D复合风格图表', fontsize=16, color=catppuccin_colors['text'],font='SimHei')
ax.set_xlabel('X轴', fontsize=12, color=catppuccin_colors['subtext1'],font='SimHei')
ax.set_ylabel('Y轴', fontsize=12, color=catppuccin_colors['subtext1'],font='SimHei')
ax.set_zlabel('Z轴', fontsize=12, color=catppuccin_colors['subtext1'],font='SimHei')
# 设置网格
ax.grid(True, linestyle='--', alpha=0.5, color=catppuccin_colors['overlay0'])
# 设置背景颜色
ax.set_facecolor(catppuccin_colors['base'])
# 应用Aquarel转换
theme.apply_transforms()
# 显示图表
plt.tight_layout()
plt.show()
函数名 | 参数 | 描述 |
|---|---|---|
style | 无 | 应用Aquarel默认样式 |
函数名 | 参数 | 描述 |
|---|---|---|
style | 无 | 应用Catppuccin默认样式 |
colors | 无 | 获取Catppuccin主题颜色 |
函数名 | 参数 | 描述 |
|---|---|---|
style | 无 | 应用网络朋克风格 |
函数名 | 参数 | 描述 |
|---|---|---|
style | 无 | 应用matplotx默认样式 |
函数名 | 参数 | 描述 |
|---|---|---|
style | 无 | 应用gruvbox默认样式 |
通过结合Aquarel、Catppuccin、mplcyberpunk、matplotx和gruvbox库,可以轻松创建出美观且多样化的Matplotlib图表。这些库提供了丰富的主题和样式,帮助开发者快速实现高质量的可视化效果。希望本文的示例和总结能够帮助读者更好地理解和应用这些库。资源绑定附上完整资料供读者参考学习!
