matplotlib绘制矢量图像(svg),pdf and ps文件
機(jī)器學(xué)習(xí)的過程中處理數(shù)據(jù),會(huì)遇到數(shù)據(jù)可視化的問題.
大部分都是利用python的matplotlib庫進(jìn)行數(shù)據(jù)的可視化處理.
plt.show() 默認(rèn)都是輸出.png文件,圖片只要稍微放大一點(diǎn),就糊的不行.
下面給出一段正常進(jìn)行數(shù)據(jù)處理可視化輸出圖片的代碼
import pandas as pd import matplotlib.pyplot as pltwith open('sourcedata2.csv')as f:df=pd.read_csv(f,header=0)X=df[df.columns[1:6]] y=df['Vibration'] plt.figure() f,ax1=plt.subplots() for i in range(1,7):number=320+iax1.locator_params(nbins=3)ax1=plt.subplot(number)plt.title(list(df)[i])ax1.scatter(df[df.columns[i]],y) plt.tight_layout(pad=0.4,w_pad=0.5,h_pad=1.0) plt.show()上面這段代碼會(huì)直接顯示出繪制的圖像.我們可以將圖片另存為.
但是我們是不是可以直接在代碼中將圖片進(jìn)行保存吶?
matplotlib,pyplot中有一個(gè)內(nèi)置函數(shù)savefig
查看savefig()函數(shù)的功能
savefig(*args, **kwargs)Save the current figure.Call signature::savefig(fname, dpi=None, facecolor='w', edgecolor='w',orientation='portrait', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.1,frameon=None)The output formats available depend on the backend being used.Arguments:*fname*:A string containing a path to a filename, or a Pythonfile-like object, or possibly some backend-dependent objectsuch as :class:`~matplotlib.backends.backend_pdf.PdfPages`.If *format* is *None* and *fname* is a string, the outputformat is deduced from the extension of the filename. Ifthe filename has no extension, the value of the rc parameter``savefig.format`` is used.If *fname* is not a string, remember to specify *format* toensure that the correct backend is used.Keyword arguments:*dpi*: [ *None* | ``scalar > 0`` | 'figure']The resolution in dots per inch. If *None* it will default tothe value ``savefig.dpi`` in the matplotlibrc file. If 'figure'it will set the dpi to be the value of the figure.*facecolor*, *edgecolor*:the colors of the figure rectangle*orientation*: [ 'landscape' | 'portrait' ]not supported on all backends; currently only on postscript output*papertype*:One of 'letter', 'legal', 'executive', 'ledger', 'a0' through'a10', 'b0' through 'b10'. Only supported for postscriptoutput.*format*:One of the file extensions supported by the activebackend. Most backends support png, pdf, ps, eps and svg.可以看到一個(gè)關(guān)鍵詞參數(shù)format,it support png,pdf,ps,eps and svg.
重新實(shí)現(xiàn)上一段代碼
X=df[df.columns[1:6]] y=df['Vibration'] plt.figure() f,ax1=plt.subplots() for i in range(1,7):number=320+iax1.locator_params(nbins=3)ax1=plt.subplot(number)plt.title(list(df)[i])ax1.scatter(df[df.columns[i]],y) plt.tight_layout(pad=0.4,w_pad=0.5,h_pad=1.0) plt.savefig(fname="name",format="svg") plt.show()在plt.savefig()函數(shù)的format參數(shù)選擇你需要保存圖片的格式,和圖片的名稱fname="your picture name"
就可以實(shí)現(xiàn)圖片多種格式的輸出.
利用graphviz來繪制繪圖
神經(jīng)網(wǎng)絡(luò)的圖(也就是其基本的模型架構(gòu))可以使用process on 也可以在python庫函數(shù)中進(jìn)行繪制
轉(zhuǎn)載于:https://www.cnblogs.com/GeekDanny/p/9300201.html
總結(jié)
以上是生活随笔為你收集整理的matplotlib绘制矢量图像(svg),pdf and ps文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA分布式快速开发基础平台iBase
- 下一篇: Raspbian 中国软件源