9种方法,一键美化Python图表
Matplotlib、Seaborn默认参数美化需要大量代码。
本次分享9种方法,一键美化图表。
1 Matplotlib style sheets
Matplotlib内置多类style sheets,
Matplotlib style sheets使用,
plt.style.use('Solarize_Light2')
详细介绍👉: Matplotlib style sheets[1]
2 seaborn style sheets
seanborn内置了五套style设置,分别为darkgrid, whitegrid, dark, white, ticks,
seaborn style sheets使用,
import seaborn as sns
sns.set_style('darkgrid') #设置style'darkgrid'
详细介绍👉: seaborn style sheets[2]
3 qbstyles
qbstyles提供两种Matplotlib style:dark和light:
matplotlib代码中添加两行代码即可:
from qbstyles import mpl_style
mpl_style(dark=False) #开启light主题
详细介绍👉:qbstyles[3]
4 matplotx
matplotx整合了多种可视化主题,比Matplotlib内置主题优美,例如,
matplotlib代码中添加两行代码即可使用matplotx:
import matplotx
#仅需以上一行代码调用solarized的'dark'主题
plt.style.use(matplotx.styles.solarized['dark'])
详细介绍👉:matplotx[4]
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()
详细介绍👉:aquarel[5]
6 SciencePlots
Matplotlib扩展工具SciencePlots,一行代码绘制science、nature、ieee等要求的图形。
使用SciencePlots,
import scienceplots #导入scienceplots
plt.style.use('science') #使用scienceplots中的science主题
详细介绍👉:SciencePlots [6]
7 cyberpunk
cyberpunk让图表变得“赛博朋克”。
cyberpunk使用,
import mplcyberpunk
plt.style.use("cyberpunk") #调用cyberpunk style
详细介绍👉:cyberpunk[7]
8 matplotlib.pyplot.xkcd
一行代码可将所有Matplotlib和Seaborn绘制的图形变为手绘风格。
matplotlib.pyplot.xkcd使用,
import matplotlib.pyplot as plt
with plt.xkcd():
绘图代码
详细介绍👉:matplotlib.pyplot.xkcd[8]
9 cutecharts
cutecharts可以将Python的强表现能力和Javascript的交互性完美结合,实现萌萌的图表。
cutecharts使用,
defpie_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()
详细介绍👉:cutecharts[9]
详解Python matplotlib深度美化(第二期): https://mp.weixin.qq.com/s/PATrHwJQx7m0o5ebXKDUgg
[2]Python seaborn美化篇-风格style: https://mp.weixin.qq.com/s/vvb_Xlqz3QEvJ4Cav06nxQ
[3]当Matplotlib遇见qbstyles!: https://mp.weixin.qq.com/s/owrhi237jqjTw90E_07ngQ
[4]当Matplotlib遇上matplotx: https://mp.weixin.qq.com/s/hQPHpGm-0EWEnfKL1tkBsw
[5]当Matplotlib遇见漂亮的aquarel~: https://mp.weixin.qq.com/s/kJDkseiHCinn2Yedq447fg
[6]一行代码science、nature图表!: https://mp.weixin.qq.com/s/A7BlrP89LvKFZtk9-wqUbA
[7]当matplotlib遇见“赛博朋克”: https://mp.weixin.qq.com/s/qmRg9OK9lN1FHH39MaVt9Q
[8]一行Python代码让图形秒变「手绘风」: https://mp.weixin.qq.com/s/Hq01nngBbZ8xWkbREcK5oQ
[9]python可视化60|一款蠢萌蠢萌的可视化工具: https://mp.weixin.qq.com/s/R2OtfTU6chDm3NC1HpbGOQ
-END-
推荐阅读: 👉Python matplotlib保姆级教程