怎么在matplotlib中繪圖樣式-創(chuàng)新互聯(lián)

這篇文章將為大家詳細(xì)講解有關(guān)怎么在matplotlib中繪圖樣式,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

創(chuàng)新互聯(lián)公司是一家企業(yè)級(jí)云計(jì)算解決方案提供商,超15年IDC數(shù)據(jù)中心運(yùn)營(yíng)經(jīng)驗(yàn)。主營(yíng)GPU顯卡服務(wù)器,站群服務(wù)器,川西大數(shù)據(jù)中心,海外高防服務(wù)器,機(jī)柜大帶寬租用·托管,動(dòng)態(tài)撥號(hào)VPS,海外云手機(jī),海外云服務(wù)器,海外服務(wù)器租用托管等。

樣式是定義圖表可視化外觀的配置,它由一組預(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è)元素的配置,元素可以為str、Path或者dict,列表右邊的元素會(huì)覆蓋前面元素的配置。

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

怎么在matplotlib中繪圖樣式

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

怎么在matplotlib中繪圖樣式

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

怎么在matplotlib中繪圖樣式

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()

關(guān)于怎么在matplotlib中繪圖樣式就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

文章標(biāo)題:怎么在matplotlib中繪圖樣式-創(chuàng)新互聯(lián)
本文來源:http://bm7419.com/article14/gihge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、企業(yè)建站響應(yīng)式網(wǎng)站、服務(wù)器托管、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)