濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > 詳解matplotlib繪圖樣式(style)初探

詳解matplotlib繪圖樣式(style)初探

熱門標(biāo)簽:地圖標(biāo)注可以遠(yuǎn)程操作嗎 智能電話機(jī)器人調(diào)研 江門智能電話機(jī)器人 甘肅高頻外呼系統(tǒng) 杭州房產(chǎn)地圖標(biāo)注 400電話在線如何申請(qǐng) 天津塘沽區(qū)地圖標(biāo)注 如何申請(qǐng)400電話代理 滴滴地圖標(biāo)注公司

樣式是定義圖表可視化外觀的配置,它由一組預(yù)置的rcParams參數(shù)構(gòu)成。matplotlib預(yù)置了一系列樣式風(fēng)格,可直接使用。

樣式使用方法

樣式相關(guān)模塊為style。

1. 顯示本機(jī)可用樣式

matplotlib.style.available返回本機(jī)可用樣式的列表。
列表只讀,樣式更新后,需要使用reload_library()重新加載樣式。

In [1]: import matplotlib.style as style
In [2]: style.available
Out[2]:
['Solarize_Light2',
 '_classic_test_patch',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark',
 'seaborn-dark-palette',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'tableau-colorblind10']

2. 顯示樣式詳細(xì)設(shè)置

matplotlib.style.library以字典的形式返回所有樣式的定義,字典鍵為樣式名稱,鍵為定義樣式的 RcParams對(duì)象。
字典對(duì)象也是只讀的,更新樣式后,需要使用reload_library()重新加載樣式。

In [6]: style.library['fast']
Out[6]:
RcParams({'agg.path.chunksize': 10000,
     'path.simplify': True,
     'path.simplify_threshold': 1.0})

3. 重新加載樣式

matplotlib.style.reload_library()重新加載樣式。

4. 使用樣式

matplotlib.style.use(style)matplotlib的繪圖樣式設(shè)置為某種樣式。
使用default樣式可以將樣式為恢復(fù)到默認(rèn)樣式。
該函數(shù)只會(huì)更新style中定義的rcParams配置,其余rcParams配置保持不變。

參數(shù)style有四種取值:

  • str:樣式名稱或者樣式文件的路徑/url。通過style.available查看可用的樣式名稱。
  • dict:以rcParams配置項(xiàng)和值為鍵值對(duì)的字典。
  • Path:指向樣式文件的Path對(duì)象。
  • list:樣式支持組合使用,將多個(gè)樣式配置配置放置在列表中,matplotlib將逐個(gè)執(zhí)行列表中每個(gè)元素的配置,元素可以為strPath或者dict,列表右邊的元素會(huì)覆蓋前面元素的配置。
import matplotlib.pyplot as plt
plt.bar([1,2,3],[1,2,3])
plt.show()

import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.bar([1,2,3],[1,2,3])
plt.show()

import matplotlib.pyplot as plt
plt.style.use(['ggplot','dark_background'])
plt.bar([1,2,3],[1,2,3])
plt.show()

import matplotlib.pyplot as plt
plt.subplot(221)
plt.bar([1,2,3],[1,2,3])
plt.style.use('ggplot')
plt.subplot(222)
plt.bar([1,2,3],[1,2,3])
plt.style.use('grayscale')
plt.subplot(223)
plt.bar([1,2,3],[1,2,3])
plt.style.use(['ggplot','grayscale'])
plt.subplot(224)
plt.bar([1,2,3],[1,2,3])
plt.show()

樣式樣例

參見https://matplotlib.org/gallery/style_sheets/style_sheets_reference.html

自定義樣式

https://matplotlib.org/tutorials/introductory/customizing.html

到此這篇關(guān)于詳解matplotlib繪圖樣式(style)初探的文章就介紹到這了,更多相關(guān)matplotlib繪圖樣式內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 用Python的繪圖庫(matplotlib)繪制小波能量譜
  • python matplotlib繪圖實(shí)現(xiàn)刪除重復(fù)冗余圖例的操作
  • python 繪圖模塊matplotlib的使用簡(jiǎn)介
  • python之 matplotlib和pandas繪圖教程
  • Pyside2中嵌入Matplotlib的繪圖的實(shí)現(xiàn)
  • 詳解matplotlib中pyplot和面向?qū)ο髢煞N繪圖模式之間的關(guān)系
  • 解決使用Spyder IDE時(shí)matplotlib繪圖的顯示問題

標(biāo)簽:廊坊 德宏 臨汾 重慶 東莞 河池 漢中 長(zhǎng)春

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解matplotlib繪圖樣式(style)初探》,本文關(guān)鍵詞  詳解,matplotlib,繪圖,樣式,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《詳解matplotlib繪圖樣式(style)初探》相關(guān)的同類信息!
  • 本頁收集關(guān)于詳解matplotlib繪圖樣式(style)初探的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    平山县| 丰顺县| 皮山县| 上饶县| 沧源| 五大连池市| 黎平县| 玛沁县| 健康| 天长市| 香河县| 金昌市| 德昌县| 即墨市| 锡林郭勒盟| 葫芦岛市| 镶黄旗| 筠连县| 乌拉特后旗| 平泉县| 敦煌市| 靖远县| 五台县| 盖州市| 江西省| 阿城市| 河西区| 哈密市| 韶山市| 昌乐县| 济南市| 娱乐| 平原县| 承德县| 瑞丽市| 长岭县| 青河县| 伊金霍洛旗| 云龙县| 屏东县| 平陆县|