matplotlib绘制矢量图像(svg),pdf and ps文件
机器学习的过程中处理数据,会遇到数据可视化的问题.
大部分都是利用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文件的更多相关文章
- 用Matplotlib绘制二维图像
唠叨几句: 近期在做数据分析,需要对数据做可视化处理,也就是画图,一般是用Matlib来做,但Matlib安装文件太大,不太想直接用它,据说其代码运行效率也很低,在网上看到可以先用Java做数据处理, ...
- 【译】在Asp.Net中操作PDF - iTextSharp - 绘制矢量图
原文 [译]在Asp.Net中操作PDF - iTextSharp - 绘制矢量图 在上一篇iTextSharp文章中讲述了如何将现有的图片插入PDF中并对其进行操作.但有时,你需要在PDF中绘制不依 ...
- python matplotlib.pyplot对图像进行绘制
imshow()是对图像进行绘制 imshow()函数格式为: matplotlib.pyplot.imshow(X, cmap=None) X: 要绘制的图像或数组. cmap: 颜色图谱(colo ...
- python包matplotlib绘制图像
使用matplotlib绘制图像 import matplotlib.pyplot as plt from matplotlib.pyplot import MultipleLocator impor ...
- 矢量图形(Vector Picture, SVG, PDF)转TiKZ代码
在使用LaTeX的过程中,我们需要往往需要使用一些图片,譬如,在样式文件中,但是如果在样式文件中使用外部的图片,总感觉不是那么地舒服「请原谅强迫症」.因此,想办法将图形内嵌入LaTeX文件. 首先,我 ...
- 用matplotlib绘制带误差的条形图及中英文字体设置
#!/usr/bin/env python3 ## 以下是一个带误差条的条形图的例子,演示了误差条形图的绘制及中英文字体设置 import numpy as np import matplotlib ...
- Python学习(一) —— matplotlib绘制三维轨迹图
在研究SLAM时常常需要对其输出的位姿进行复现以检测算法效果,在ubuntu系统中使用Python可以很好的完成相关的工作. 一. Ubuntu下Python的使用 在Ubuntu下使用Python有 ...
- PDG转图像、PDF的若干方法
作者:马健邮箱:stronghorse_mj@hotmail.com发布:2006.05.26更新:2008.08.24 补充说明:此文成文较早,其中对Pdg2Pic.FreePic2Pdf的描述早已 ...
- matplotlib绘制动画
matplotlib从1.1.0版本以后就开始支持绘制动画,具体使用可以参考官方帮助文档.下面是一个很基本的例子: """ A simple example of an ...
随机推荐
- Web安全之CSRF攻击(转载)
CSRF是什么? CSRF(Cross Site Request Forgery),中文是跨站点请求伪造.CSRF攻击者在用户已经登录目标网站之后,诱使用户访问一个攻击页面,利用目标网站对用户的信任, ...
- Spring 核心技术(5)
接上篇:Spring 核心技术(4) version 5.1.8.RELEASE 1.4.5 自动装配协作者 Spring 容器可以自动连接协作 bean 之间的关系.你可以让 Spring 通过检查 ...
- 计算机网络中IP地址和MAC地址
计算机 网络中的网络地址有I P 地址和物理地址之分,对 于主机间的通信时,它们的作用也不一样 . l I P 地址 为 了保证 I n t e r n e t 网上主机通信时能够相互识别 ,不引 ...
- light oj 1159 - Batman LCS
学过简单动态规划的人应该对最长公共子序列的问题很熟悉了,这道题只不过多加了一条字符串变成三条了,还记得,只要把状态变成三维的即可. //http://lightoj.com/volume_showpr ...
- c#小灶——初识c#
提到c#,就不得不说.net,.net是微软开发的一个平台,简单来说,在这个平台上,可以编写.运行程序.可能很多人觉得这个平台离我们很遥远,其实不然,这个平台就一直在我们的windows操作系统里,默 ...
- C# Winform 自定义控件——TextBox
效果: 描述: 类似html标签里input标签里的placeHolder属性,控件继承TextBox,拥有一个描述提示信息的字段_txtPlaceHolder,重写了消息处理函数WndProc, ...
- 基于Spring注解的上下文初始化过程源码解析(一)
最近工作之余有时间和精力,加上平时对源码比较感兴趣,就开始啃起了Spring源码.为加深印象写了这篇博客,如有错误,望各位大佬不吝指正. 我看的是Spring5的源码,从同性社区download下来后 ...
- 无法正常卸载pr
控制面板找不到pr和ps,根本无法卸载,我试过官方工具没用,也试过ccleaner,也检测不到?
- L1063 能量项链
1 #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b ...
- java并发编程(十七)----(线程池)java线程池架构和原理
前面我们简单介绍了线程池的使用,但是对于其如何运行我们还不清楚,Executors为我们提供了简单的线程工厂类,但是我们知道ThreadPoolExecutor是线程池的具体实现类.我们先从他开始分析 ...