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_themetheme?=?load_theme("arctic_light")
theme.apply()
#?在這里添加繪圖代碼
theme.apply_transforms()
詳細介紹👉:當Matplotlib遇見漂亮的aquarel~
6 SciencePlots?
Matplotlib擴展工具SciencePlots,一行代碼繪制science、nature、ieee等要求的圖形
。
?使用SciencePlots,
import scienceplots #導入scienceplotsplt.style.use('science') #使用scienceplots中的science主題
詳細介紹👉:一行代碼science、nature圖表!
7 cyberpunk?
cyberpunk讓圖表變得“賽博朋克”。
?使用,
import?mplcyberpunkplt.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 chartpie_radius().render_notebook()
詳細介紹👉:python可視化60|一款蠢萌蠢萌的可視化工具?