日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

matplotlib绘制矢量图像(svg),pdf and ps文件

發(fā)布時(shí)間:2023/12/20 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matplotlib绘制矢量图像(svg),pdf and ps文件 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

機(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)行繪制

from pydotplus import graphviz

轉(zhuǎn)載于:https://www.cnblogs.com/GeekDanny/p/9300201.html

總結(jié)

以上是生活随笔為你收集整理的matplotlib绘制矢量图像(svg),pdf and ps文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。