python绘图内容怎么保存_将绘图保存到图像文件,而不是使用Matplotlib显示 - python...
我正在編寫一個(gè)快速腳本來(lái)動(dòng)態(tài)生成繪圖。我使用下面的代碼(來(lái)自Matplotlib文檔)作為起點(diǎn):
from pylab import figure, axes, pie, title, show
# Make a square figure and axes
figure(1, figsize=(6, 6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
explode = (0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
title('Raining Hogs and Dogs', bbox={'facecolor': '0.8', 'pad': 5})
show() # Actually, don't show, just save to foo.png
我不想將圖形顯示在GUI上,而是要將圖形保存到文件(例如foo.png)中,以便例如可以在批處理腳本中使用。我怎么做?
參考方案
在回答問(wèn)題后,我想在使用matplotlib.pyplot.savefig時(shí)添加一些有用的提示。文件格式可以通過(guò)擴(kuò)展名指定:
from matplotlib import pyplot as plt
plt.savefig('foo.png')
plt.savefig('foo.pdf')
將分別給出柵格化或矢量化的輸出,這兩個(gè)都可能有用。此外,您會(huì)發(fā)現(xiàn)pylab在圖像周圍留有大量的空白,通常是不希望的空白。刪除它:
savefig('foo.png', bbox_inches='tight')
Matplotlib'粗體'字體 - python
跟隨this example:import numpy as np import matplotlib.pyplot as plt fig = plt.figure() for i, label in enumerate(('A', 'B', 'C', 'D')): ax = f…在返回'Response'(Python)中傳遞多個(gè)參數(shù) - python
我在Angular工作,正在使用Http請(qǐng)求和響應(yīng)。是否可以在“響應(yīng)”中發(fā)送多個(gè)參數(shù)。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…Python exchangelib在子文件夾中讀取郵件 - python
我想從Outlook郵箱的子文件夾中讀取郵件。Inbox ├──myfolder 我可以使用account.inbox.all()閱讀收件箱,但我想閱讀myfolder中的郵件我嘗試了此頁(yè)面folder部分中的內(nèi)容,但無(wú)法正確完成https://pypi.python.org/pypi/exchangelib/ 參考方案 您需要首先掌握Folder的myfo…R'relaimpo'軟件包的Python端口 - python
我需要計(jì)算Lindeman-Merenda-Gold(LMG)分?jǐn)?shù),以進(jìn)行回歸分析。我發(fā)現(xiàn)R語(yǔ)言的relaimpo包下有該文件。不幸的是,我對(duì)R沒(méi)有任何經(jīng)驗(yàn)。我檢查了互聯(lián)網(wǎng),但找不到。這個(gè)程序包有python端口嗎?如果不存在,是否可以通過(guò)python使用該包? python參考方案 最近,我遇到了pingouin庫(kù)。Python ThreadPoolExecutor抑制異常 - python
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…
總結(jié)
以上是生活随笔為你收集整理的python绘图内容怎么保存_将绘图保存到图像文件,而不是使用Matplotlib显示 - python...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python查询字典里的多个key_Py
- 下一篇: python 列表去重(数组)的几种方法