Python可視化之seborn圖形外觀設(shè)置
本文將了解什么?
1、設(shè)置背景風(fēng)格
- 使用
set_style設(shè)置圖形背景風(fēng)格 - 不同子圖使用不同背景風(fēng)格
- 自定義背景風(fēng)格
2、設(shè)置外框(脊柱)
3、圖形縮放
4、同時設(shè)置背景|圖形縮放
1、設(shè)置背景風(fēng)格
使用set_style設(shè)置圖形背景風(fēng)格
#seaborn包含5中背景風(fēng)格darkgrid, whitegrid, dark, white, ticks,默認(rèn)為dark
#set_style()修改風(fēng)格,以下展示5種風(fēng)格差異
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
for i in list('darkgrid, whitegrid, dark, white, ticks'.split(', ')):
? ? sns.set_style(style='%s'%i)
? ? plt.figure()
? ? plt.plot(range(10),[i+1 for i in range(10)])?
? ? plt.title('%s'%i)


不同子圖使用不同背景風(fēng)格
axes_style() 結(jié)合with
f = plt.figure(figsize=(6, 6))
gs = f.add_gridspec(2, 2)
with sns.axes_style("darkgrid"):
? ? ax = f.add_subplot(gs[0, 0])
? ? plt.plot(range(10),[i+1 for i in range(10)])
with sns.axes_style("white"):
? ? ax = f.add_subplot(gs[0, 1])
? ? plt.plot(range(10),[i+1 for i in range(10)])
with sns.axes_style("ticks"):
? ? ax = f.add_subplot(gs[1, 0])
? ? plt.plot(range(10),[i+1 for i in range(10)])
with sns.axes_style("whitegrid"):
? ? ax = f.add_subplot(gs[1, 1])
? ? plt.plot(range(10),[i+1 for i in range(10)])
f.tight_layout()
自定義背景風(fēng)格
sns.axes_style('darkgrid')#輸出'darkgrid'默認(rèn)配置
{'figure.facecolor': 'white',
?'axes.labelcolor': '.15',
?'xtick.direction': 'out',
?'ytick.direction': 'out',
?'xtick.color': '.15',
?'ytick.color': '.15',
?'axes.axisbelow': True,
?'grid.linestyle': '-',
?'text.color': '.15',
?'font.family': ['sans-serif'],
?'font.sans-serif': ['Arial',
? 'DejaVu Sans',
? 'Liberation Sans',
? 'Bitstream Vera Sans',
? 'sans-serif'],
?'lines.solid_capstyle': 'round',
?'patch.edgecolor': 'w',
?'patch.force_edgecolor': True,
?'image.cmap': 'rocket',
?'xtick.top': False,
?'ytick.right': False,
?'axes.grid': True,
?'axes.facecolor': '#EAEAF2',
?'axes.edgecolor': 'white',
?'grid.color': 'white',
?'axes.spines.left': True,
?'axes.spines.bottom': True,
?'axes.spines.right': True,
?'axes.spines.top': True,
?'xtick.bottom': False,
?'ytick.left': False}sns.set_style("darkgrid", {"axes.facecolor": "pink"})#修改背景色
plt.plot(range(10),[i+1 for i in range(10)])
2、設(shè)置外框(脊柱)
seaborn.despine plt.plot(range(10),[i+1 for i in range(10)]) sns.despine(fig=None, ax=None,? ? ? ? ? ? ? top=True, right=True, left=False, bottom=False, #上,右,左,下外框開關(guān) ? ? ? ? ? ? offset=None, trim=False ? ? ? ? ? ?)

3、圖形縮放
plotting_context() set_context()
#seaborn包含4模式可選:paper,notebook,talk,poster,默認(rèn)為notebook
#set_context()修改模式,以下展示4種風(fēng)格差異
for i in list('paper,notebook,talk,poster'.split(',')):
? ? sns.set_context(context='%s'%i)
? ? plt.figure(dpi=80)
? ? plt.plot(range(10),[i+1 for i in range(10)])?
? ? plt.title('%s'%i)

4、同時設(shè)置背景|圖形縮放
set()
sns.set(context='notebook', #設(shè)置縮放 ? ? ? ? style='darkgrid', #設(shè)置背景風(fēng)格 ? ? ? ? palette='deep', #設(shè)置colormap ? ? ? ? font='sans-serif', font_scale=1, color_codes=True, rc=None)
到此這篇關(guān)于Python可視化之seborn圖形外觀設(shè)置的文章就介紹到這了,更多相關(guān)seborn圖形外觀設(shè)置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python?matplotlib繪圖時使用鼠標(biāo)滾輪放大/縮小圖像
Matplotlib是Python程序員可用的事實(shí)上的繪圖庫,雖然它比交互式繪圖庫在圖形上更簡單,但它仍然可以一個強(qiáng)大的工具,下面這篇文章主要給大家介紹了關(guān)于Python?matplotlib繪圖時使用鼠標(biāo)滾輪放大/縮小圖像的相關(guān)資料,需要的朋友可以參考下2022-05-05
python讀取當(dāng)前目錄下的CSV文件數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了python讀取當(dāng)前目錄下的CSV文件數(shù)據(jù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-03-03
Starship定制shell提示符實(shí)現(xiàn)信息自由
這篇文章主要介紹了Starship定制shell提示符的實(shí)現(xiàn),讓你需要的所有信息觸手可及,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03
tensorflow 實(shí)現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換
今天小編就為大家分享一篇tensorflow 實(shí)現(xiàn)數(shù)據(jù)類型轉(zhuǎn)換,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
python3實(shí)現(xiàn)跳一跳點(diǎn)擊跳躍
這篇文章主要為大家詳細(xì)介紹了python3實(shí)現(xiàn)跳一跳點(diǎn)擊跳躍,玩跳一跳小游戲的思路,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
PYTHON如何讀取和寫入EXCEL里面的數(shù)據(jù)
這篇文章主要介紹了PYTHON如何讀取和寫入EXCEL里面的數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-10-10
更改Python的pip install 默認(rèn)安裝依賴路徑方法詳解
今天小編就為大家分享一篇更改Python的pip install 默認(rèn)安裝依賴路徑方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10

