Matplotlib、Seaborn默认参数不好看,美化需要大量代码。
本次分享9种方法,一键美化图表,看看那个是你的菜。
1 Matplotlib style sheets
Matplotlib内置多类style sheets,
一行代码使用,
plt.style.use('Solarize_Light2')
详细介绍👉: 详解Python matplotlib深度美化(第二期)
2 seaborn style sheets
seanborn内置了五套style设置,分别为darkgrid, whitegrid, dark, white, ticks,
一行代码使用,
import seaborn as sns
sns.set_style('darkgrid') #设置style'darkgrid'
详细介绍👉: Python seaborn美化篇-风格style
3 qbstyles
qbstyles提供两种Matplotlib style:dark和light
:
matplotlib代码中添加两行代码即可:
from qbstyles import mpl_style
mpl_style(dark=False) #开启light主题
详细介绍👉:当Matplotlib遇见qbstyles!
4 matplotx
matplotx整合了多种可视化主题
,比Matplotlib内置主题优美,例如,
matplotlib代码中添加两行代码即可使用matplotx:
import matplotx
#仅需以上一行代码调用solarized的'dark'主题
plt.style.use(matplotx.styles.solarized['dark'])
详细介绍👉:当Matplotlib遇上matplotx
5 aquarel
aquarel可轻松拯救matplotlib丑陋的默认出图,提供多种绘图浅色light和深色weight绘图主题
,极大丰富matplotlib的plt.style库。
matplotlib代码中使用aquarel:
from aquarel import load_theme
theme = load_theme("arctic_light")
theme.apply()
# 在这里添加绘图代码
theme.apply_transforms()
详细介绍👉:当Matplotlib遇见漂亮的aquarel~
6 SciencePlots
Matplotlib扩展工具SciencePlots,一行代码绘制science、nature、ieee等要求的图形
。
使用SciencePlots,
import scienceplots #导入scienceplots
plt.style.use('science') #使用scienceplots中的science主题
详细介绍👉:一行代码science、nature图表!
7 cyberpunk
cyberpunk让图表变得“赛博朋克”。
使用,
import mplcyberpunk
plt.style.use("cyberpunk") #调用cyberpunk style
详细介绍👉:当matplotlib遇见“赛博朋克”
8 matplotlib.pyplot.xkcd
一行代码可将所有Matplotlib和Seaborn绘制的图形变为手绘风格。
使用,
import matplotlib.pyplot as plt
with plt.xkcd():
绘图代码
详细介绍👉:一行Python代码让图形秒变「手绘风」
9 cutecharts
cutecharts可以将Python的强表现能力和Javascript的交互性完美结合,实现萌萌的图表。
使用,
def pie_radius():
chart = Pie("Pie")
chart.set_options(
labels=['我是卢本伟2号', 'Faker', 'Easyhoon', 'Pawn', 'Dopa'],
inner_radius=0,
)
chart.add_series([6, 5, 1, 2, 4])
return chart
pie_radius().render_notebook()
详细介绍👉:python可视化60|一款蠢萌蠢萌的可视化工具