机器学习的过程中处理数据,会遇到数据可视化的问题.

大部分都是利用python的matplotlib库进行数据的可视化处理.

plt.show() 默认都是输出.png文件,图片只要稍微放大一点,就糊的不行.

下面给出一段正常进行数据处理可视化输出图片的代码

import pandas as pd
import matplotlib.pyplot as plt with 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+i
ax1.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()

上面这段代码会直接显示出绘制的图像.我们可以将图片另存为.

但是我们是不是可以直接在代码中将图片进行保存呐?

matplotlib,pyplot中有一个内置函数savefig

查看savefig()函数的功能

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 Python
file-like object, or possibly some backend-dependent object
such as :class:`~matplotlib.backends.backend_pdf.PdfPages`. If *format* is *None* and *fname* is a string, the output
format is deduced from the extension of the filename. If
the filename has no extension, the value of the rc parameter
``savefig.format`` is used. If *fname* is not a string, remember to specify *format* to
ensure that the correct backend is used. Keyword arguments: *dpi*: [ *None* | ``scalar > 0`` | 'figure']
The resolution in dots per inch. If *None* it will default to
the 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 postscript
output. *format*:
One of the file extensions supported by the active
backend. Most backends support png, pdf, ps, eps and svg.

可以看到一个关键词参数format,it support png,pdf,ps,eps and svg.

重新实现上一段代码

X=df[df.columns[1:6]]
y=df['Vibration']
plt.figure()
f,ax1=plt.subplots()
for i in range(1,7):
number=320+i
ax1.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()函数的format参数选择你需要保存图片的格式,和图片的名称fname="your picture name"

就可以实现图片多种格式的输出.

利用graphviz来绘制绘图


神经网络的图(也就是其基本的模型架构)可以使用process on 也可以在python库函数中进行绘制

from pydotplus import graphviz

matplotlib绘制矢量图像(svg),pdf and ps文件的更多相关文章

  1. 用Matplotlib绘制二维图像

    唠叨几句: 近期在做数据分析,需要对数据做可视化处理,也就是画图,一般是用Matlib来做,但Matlib安装文件太大,不太想直接用它,据说其代码运行效率也很低,在网上看到可以先用Java做数据处理, ...

  2. 【译】在Asp.Net中操作PDF - iTextSharp - 绘制矢量图

    原文 [译]在Asp.Net中操作PDF - iTextSharp - 绘制矢量图 在上一篇iTextSharp文章中讲述了如何将现有的图片插入PDF中并对其进行操作.但有时,你需要在PDF中绘制不依 ...

  3. python matplotlib.pyplot对图像进行绘制

    imshow()是对图像进行绘制 imshow()函数格式为: matplotlib.pyplot.imshow(X, cmap=None) X: 要绘制的图像或数组. cmap: 颜色图谱(colo ...

  4. python包matplotlib绘制图像

    使用matplotlib绘制图像 import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator impor ...

  5. 矢量图形(Vector Picture, SVG, PDF)转TiKZ代码

    在使用LaTeX的过程中,我们需要往往需要使用一些图片,譬如,在样式文件中,但是如果在样式文件中使用外部的图片,总感觉不是那么地舒服「请原谅强迫症」.因此,想办法将图形内嵌入LaTeX文件. 首先,我 ...

  6. 用matplotlib绘制带误差的条形图及中英文字体设置

    #!/usr/bin/env python3 ## 以下是一个带误差条的条形图的例子,演示了误差条形图的绘制及中英文字体设置 import numpy as np import matplotlib ...

  7. Python学习(一) —— matplotlib绘制三维轨迹图

    在研究SLAM时常常需要对其输出的位姿进行复现以检测算法效果,在ubuntu系统中使用Python可以很好的完成相关的工作. 一. Ubuntu下Python的使用 在Ubuntu下使用Python有 ...

  8. PDG转图像、PDF的若干方法

    作者:马健邮箱:stronghorse_mj@hotmail.com发布:2006.05.26更新:2008.08.24 补充说明:此文成文较早,其中对Pdg2Pic.FreePic2Pdf的描述早已 ...

  9. matplotlib绘制动画

    matplotlib从1.1.0版本以后就开始支持绘制动画,具体使用可以参考官方帮助文档.下面是一个很基本的例子: """ A simple example of an ...

随机推荐

  1. jsp的简介(2)

    JSP(JavaServer Pages )是什么? JavaServer Pages(JSP)是一种支持动态内容开发的网页技术它可以帮助开发人员通过利用特殊的JSP标签,其中大部分以<%开始并 ...

  2. java 第一章

    1.java四要素  public static void main 2.java 的历史 and soso 3.知道java的格式和要求 4.知道如何配置环境变量 5.java的编写:  a.大括号 ...

  3. Java 内存模型详解

    概述 Java的内存模型(Java Memory Model )简称JMM.首先应该明白,Java内存模型是一个规范,主要规定了以下两点: 规定了一个线程如何以及何时可以看到其他线程修改过后的共享变量 ...

  4. Shell基本语法---shell介绍

    简介 1. shell是在linux系统上高效运行的脚本语言 2. 主要用来开发一些实用的.自动化的小工具,而不是用来开发具有复杂业务逻辑的中大型软件 3. shell的基本命令也是linux操作系统 ...

  5. Python3数据驱动ddt

    对于同一个方法执行大量数据的程序时,我们可以采用ddt数据驱动的方式,来对数据规范化整理及输出 一.需要使用python的ddt库,ddt,data,unpack方法 1.仅使用ddt和data,代码 ...

  6. BrowserSync,自动刷新,解放F5,去掉更新提示

    BrowserSync虽然这个技术不算新,但是依然有用.略微介绍下 没有安装node,先安装node,这里不再做介绍 安装 npm install -g browser-sync  全局安装,方便在任 ...

  7. 搭建谷歌浏览器无头模式抓取页面服务,laravel->php->python->docker !!!

    背景: 公司管理系统需要获取企业微信页面的配置参数如企业名.logo.人数等信息并操作,来隐藏相关敏感信息并自定义简化企业号配置流程 第一版已经实现了扫码登录获取cookie,使用该cookie就能获 ...

  8. git的使用(一)

    git   —version  展示git的版本 tanya ~$ git --version git version 2.22.0 最小配置   git config —global user.na ...

  9. 七牛云qshell工具定时备份空间文件到本地

    qshell 是利用七牛文档上公开的 API实现的一个方便开发者测试和使用七牛API服务的命令行工具,使用该工具可以实现很多的功能,今天就分享一下利用qshell定时备份空间文件到本地 1.下载qsh ...

  10. CodeForces 15D Map

    洛谷题目页面传送门 & CodeForces题目页面传送门 题意见洛谷里的翻译.(注意翻译里有错误,应该是优先选上面的矩阵,在同一行的优先选左边的矩阵) 这题一看就会做啊 (以下设大矩阵是\( ...