錯誤:沒有顯示名稱且沒有$DISPLAY 環境變數
當用於資料視覺化的Python 庫Matplotlib 嘗試使用需要圖形輸出但找不到有效顯示環境的後端。
Matplotlib 預設使用 Xwindows 後端,這需要設定 X 伺服器和 $DISPLAY 環境變數。在給定的場景中,該錯誤表示正在執行 Python 腳本的伺服器上顯示名稱和 $DISPLAY 變數都不可用。
解決方案:
要解決此問題,您可以將 Matplotlib 設定為使用不需要圖形輸出的非互動式後端。在匯入matplotlib 之前,在腳本開頭新增以下行:
<code class="python">import matplotlib matplotlib.use('Agg')</code>
這會將Matplotlib 配置為使用Agg 後端,這是一個非互動式後端,以檔案格式產生輸出,例如作為PNG或PDF。
或者,您可以將以下行新增至.config/matplotlib/matplotlibrc 檔案中,以使非互動式後端成為預設後端:
backend: Agg
如果您有如果遠端電腦上有可用的X 伺服器,則可以使用以下SSH 命令轉送X11 連線:
<code class="bash">ssh -X remoteMachine.com</code>
這將在遠端電腦上設定$DISPLAY 環境變量,允許Matplotlib 使用Xwindows 後端.
最後,您可以嘗試手動匯出$DISPLAY 變數:
<code class="bash">export DISPLAY=mymachine.com:0.0</code>
這會將$DISPLAY 變數設定為指定的遠端電腦並顯示編號。
有關此錯誤和可能的解決方案的更多信息,請參閱Matplotlib 文件:https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server
以上是如何修復 Matplotlib 中的「無顯示名稱且無 $DISPLAY 環境變數」錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Atom編輯器mac版下載
最受歡迎的的開源編輯器