Python可視化之seborn圖形外觀設(shè)置
本文將了解什么?
1、設(shè)置背景風(fēng)格
- 使用
set_style
設(shè)置圖形背景風(fēng)格 - 不同子圖使用不同背景風(fēng)格
- 自定義背景風(fēng)格
2、設(shè)置外框(脊柱)
3、圖形縮放
4、同時(shí)設(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í)設(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實(shí)現(xiàn)PS濾鏡的旋轉(zhuǎn)模糊功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)PS濾鏡的旋轉(zhuǎn)模糊功能,涉及Python基于skimage庫針對圖片進(jìn)行旋轉(zhuǎn)與模糊化處理的相關(guān)操作技巧,需要的朋友可以參考下2018-01-01使用pytorch實(shí)現(xiàn)論文中的unet網(wǎng)絡(luò)
這篇文章主要介紹了使用pytorch實(shí)現(xiàn)論文中的unet網(wǎng)絡(luò),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06圖神經(jīng)網(wǎng)絡(luò)GNN算法基本原理詳解
這篇文章主要為大家介紹了圖神經(jīng)網(wǎng)絡(luò)GNN算法基本原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05Python異常處理如何才能寫得優(yōu)雅(retrying模塊)
異常就是程序運(yùn)行時(shí)發(fā)生錯(cuò)誤的信號,下面這篇文章主要給大家介紹了關(guān)于Python異常處理的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03Python抓取聚劃算商品分析頁面獲取商品信息并以XML格式保存到本地
這篇文章主要為大家詳細(xì)介紹了Python抓取聚劃算商品分析頁面獲取商品信息,并以XML格式保存到本地的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02conda查看、創(chuàng)建、刪除、激活與退出環(huán)境命令詳解
在不同的項(xiàng)目中經(jīng)常需要conda來配置環(huán)境,這樣能夠?qū)崿F(xiàn)不同版本的python和庫的隨意切換,并且減少了很多不必要的麻煩,下面這篇文章主要給大家介紹了關(guān)于conda查看、創(chuàng)建、刪除、激活與退出環(huán)境命令的相關(guān)資料,需要的朋友可以參考下2023-05-05