大数跨境
0
0

当Matplotlib遇见漂亮的aquarel~

当Matplotlib遇见漂亮的aquarel~ 数据分析与开发
2024-02-15
1
导读:当Matplotlib遇见漂亮的aquarel~

aquarel可轻松拯救matplotlib丑陋的默认出图,提供多种绘图浅色light和深色weight绘图主题,极大丰富matplotlib的plt.style库。

aquarel安装

pip install aquarel

aquarel效果

aquarel目前支持11种绘图主题,支持自定义,

arctic_dark
arctic_light
boxy_dark
boxy_light
gruvbox_dark
gruvbox_light
minimal_dark
minimal_light
scientific
umbra_dark
umbra_light

展示一下主题效果,

arctic_dark和boxy_dark主题
scientific和arctic_light主题
gruvbox_light和umbra_light主题

效果还是很棒的~


aquarel使用

aquarel使用有两种方法

  • 方法1、全局设置

如果你打开了一个jupyter notebook,通过以下代码使用aquarel的arctic_light主题,那么整个notebook中绘图都是arctic_light主题,

from aquarel import load_theme

theme = load_theme("arctic_light")
theme.apply()
# 在这里添加绘图代码
theme.apply_transforms()
  • 方法2、临时设置

如果你打开了一个jupyter notebook,通过以下代码使用aquarel的arctic_light主题,那么只有当前notebook中当前cell使用了arctic_light主题,不影响其它cell,

from aquarel import load_theme

with load_theme("arctic_light"):
    #在这里添加绘图代码

下面以方法1,简单举两个例子,

未使用aquarel主题,matplotlib默认图表,

例子1,使用arctic_light主题,

from aquarel import load_theme
import matplotlib.pyplot as plt
import numpy as np
theme = load_theme("arctic_light"#调用aquarel中的'arctic_dark'
plt.figure(figsize=(126))

# 创建数据
np.random.seed(10)
data_boxplot = [np.random.normal(0, std, 100for std in range(15)]
data_lineplot = [np.cumsum(np.random.randn(100)) for _ in range(4)]

#调用aquarel
theme.apply()
plt.subplot(121)
plt.boxplot(data_boxplot)
plt.xticks([1234], ['Group 1''Group 2''Group 3''Group 4'])
plt.title('arctic_light')

plt.subplot(122)
for i, line_data in enumerate(data_lineplot):
    plt.plot(line_data, label=f'Line {i+1}')
plt.title('arctic_light')

plt.legend()
theme.apply_transforms()
plt.tight_layout()
plt.show()

例子2,使用arctic_dark主题,

from aquarel import load_theme
import matplotlib.pyplot as plt
import numpy as np
theme = load_theme("arctic_dark"#调用aquarel中的'arctic_dark'
plt.figure(figsize=(126))

# 创建数据
np.random.seed(10)
data_boxplot = [np.random.normal(0, std, 100for std in range(15)]
data_lineplot = [np.cumsum(np.random.randn(100)) for _ in range(4)]

#调用aquarel
theme.apply()
plt.subplot(121)
plt.boxplot(data_boxplot)
plt.xticks([1234], ['Group 1''Group 2''Group 3''Group 4'])
plt.title('arctic_dark'

plt.subplot(122)
for i, line_data in enumerate(data_lineplot):
    plt.plot(line_data, label=f'Line {i+1}')
plt.title('arctic_dark')
plt.legend()
theme.apply_transforms()
plt.tight_layout()
plt.show()

参考:https://aquarel.readthedocs.io/en/latest/?badge=latest

推荐阅读  点击标题可跳转

1、事半功倍,必看这4个Pandas神器!

2、一条查询SQL是如何执行的

3、300万数据导入导出优化方案,从80s优化到8s(实测)

【声明】内容源于网络
0
0
数据分析与开发
「数据分析与开发」分享数据分析与开发相关技术文章、教程、工具
内容 2105
粉丝 0
数据分析与开发 「数据分析与开发」分享数据分析与开发相关技术文章、教程、工具
总阅读654
粉丝0
内容2.1k