溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么在matplotlib中獲取相關(guān)系統(tǒng)目錄

發(fā)布時(shí)間:2021-02-04 15:29:22 來源:億速云 閱讀:121 作者:Leah 欄目:開發(fā)技術(shù)

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在matplotlib中獲取相關(guān)系統(tǒng)目錄,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

一、獲取matplotlib的安裝位置

導(dǎo)入matplotlib,打印__file__屬性,即可顯示matplotlib包的安裝位置。

In [1]: import matplotlib
In [2]: matplotlib.__version__
Out[2]: '3.3.2'
In [3]: matplotlib.__file__
Out[3]: 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.py

二、獲取matplotlib的配置目錄

配置目錄獲取比較復(fù)雜,遵循以下規(guī)律:
如果設(shè)置了MPLCONFIGDIR 環(huán)境變量,那么配置目錄就是該變量對應(yīng)目錄。如果沒有選擇,那么配置目錄為$HOME/.matplotlib。

In [4]: matplotlib.get_configdir()
Out[4]: 'C:\\Users\\adminstrator\\.matplotlib'

三、獲取matplotlib的緩存目錄

一般情況下,get_cachedir()和get_configdir()返回同一個(gè)目錄,特例是在linux中,如果設(shè)置環(huán)境變量$XDG_CACHE_HOME/$HOME/.cache,則使用環(huán)境變量設(shè)置的目錄。
matplotlib的字體緩存存放在該目錄。

In [5]: matplotlib.get_cachedir()
Out[5]: 'C:\\Users\\adminstrator\\.matplotlib'

四、獲取matplotlib的配置文件路徑

matplotlib_fname()獲取的即配置文件matplotlibrc文件所在位置。

In [6]: matplotlib.matplotlib_fname()
Out[6]: 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data\\m
atplotlibrc'

五、獲取matplotlib的數(shù)據(jù)文件目錄

matplotlib安裝時(shí)附帶了一些數(shù)據(jù),比如字體、導(dǎo)航界面圖片、樣本數(shù)據(jù)、繪圖風(fēng)格等,在Windows平臺中,rc文件默認(rèn)也保存在該目錄。該目錄結(jié)構(gòu)如下:

├─mpl-data
│ ├─fonts
│ │ ├─afm
│ │ ├─pdfcorefonts
│ │ └─ttf
│ ├─images
│ ├─sample_data
│ │ └─axes_grid
│ └─stylelib
In [7]: matplotlib.get_data_path()
Out[7]: 'd:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\mpl-data'

上述就是小編為大家分享的怎么在matplotlib中獲取相關(guān)系統(tǒng)目錄了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI