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

大部分都是利用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. HTML结构 语义化思想

    总体思想:用正确的标签做正确的事情! 根据内容的结构化(内容语义化),选择合适的标签(代码语义化)便于开发者阅读和写出更优雅的代码的同时让浏览器的爬虫和机器很好地解析. 主要体现: 1. 对用户而言, ...

  2. C#汽车租赁系统 完整版

      Truck.cs类 //卡车类 public class Truck : Vehicle1 { //重载 public int Load { get; set; } //构造函数 public T ...

  3. 网站性能优化的方法--Yahoo

    如何能让用户更快的打开我们的网页? 1.尽可能减少HTTP请求数 2.使用CDN(内容分发网络) 3.添加Expire/Cache-Control头 4.启用Gzip压缩 5.将CSS放在页面最上面 ...

  4. javaweb入门-----request与response的作用

    request对象和request对象的原理 1.request和response对象request对象和request对象的原理时由服务器创建的,我们来使用它们 2.request对象是来获取请求消 ...

  5. 【Algorithm】选择排序法

    简单的选择排序法思想: * 首先找到数组中最小的元素,将它和数组第一个元素互换位置(如果第一个元素就是最小那么它就和自己交换). * 其次,在剩下的元素中找到最小的元素,将它与数组的第二个元素互换位置 ...

  6. Java 字符串分隔 split

    Java中的我们可以利用 split 方法(Java.lang.string.split)把字符串按照指定的分割符进行分割,然后返回字符串数组,下面是string.split的用法实例及注意事项. s ...

  7. RabbitMQ(四):使用Docker构建RabbitMQ高可用负载均衡集群

    本文使用Docker搭建RabbitMQ集群,然后使用HAProxy做负载均衡,最后使用KeepAlived实现集群高可用,从而搭建起来一个完成了RabbitMQ高可用负载均衡集群.受限于自身条件,本 ...

  8. go单元测试

    testing模块 测试代码放在当前包以_test.go结尾的文件中 测试函数以Test为名称前缀 测试命令(go test) 正常编译操作(go build/install)会忽略测试文件 单例模式 ...

  9. javascript+jQuery补充

    一.jQuery事件绑定 <div class='c1'> <div> <div class='title'>菜单一</div> <div cla ...

  10. 自定义 Button 选择器

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...