scikit-learn:matplotlib.pyplot经常使用绘图功能总结(1)
參考:http://matplotlib.org/api/pyplot_api.html
绘图功能总结(2):http://blog.csdn.net/mmc2015/article/details/48222611
1、matplotlib.pyplot.plot(*args, **kwargs)。最简单的沿坐标轴划线函数:
以下四种格式都合法:
- plot(x, y) # plot x and y using default line style and color
- plot(x, y, 'bo') # plot x and y using blue circle markers
- plot(y) # plot y using x as index array 0..N-1
- plot(y, 'r+') # ditto, but with red plusses
- <pre name="code" class="python">import numpy as np
- import matplotlib.pyplot as plt
- x1=np.arange(0,5,0.1)
- y1=np.sin(x1)
- x2=np.linspace(1,10,20,True)
- y2=np.cos(x2)
- plt.plot(x1,y1,'b^')
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
也能够同一时候画一组图:
- plt.plot(x1, y1, 'go', x2, y2, 'r-')
假设颜色不显示指出,则默认循环使用不同的颜色,支持的颜色有:
character | color |
---|---|
‘b’ | blue |
‘g’ | green |
‘r’ | red |
‘c’ | cyan |
‘m’ | magenta |
‘y’ | yellow |
‘k’ | black |
‘w’ | white |
支持的line style有:
character | description |
---|---|
'-' | solid line style |
'--' | dashed line style |
'-.' | dash-dot line style |
':' | dotted line style |
'.' | point marker |
',' | pixel marker |
'o' | circle marker |
'v' | triangle_down marker |
'^' | triangle_up marker |
'<' | triangle_left marker |
'>' | triangle_right marker |
'1' | tri_down marker |
'2' | tri_up marker |
'3' | tri_left marker |
'4' | tri_right marker |
's' | square marker |
'p' | pentagon marker |
'*' | star marker |
'h' | hexagon1 marker |
'H' | hexagon2 marker |
'+' | plus marker |
'x' | x marker |
'D' | diamond marker |
'd' | thin_diamond marker |
'|' | vline marker |
'_' | hline marker |
加入图例:
- plt.plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
- plt.plot([1,2,3], [1,4,9], 'rs', label='line 2')
- plt.legend()
指定坐标范围:
- plt.plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
- plt.plot([1,2,3], [1,4,9], 'rs', label='line 2')
- plt.<strong>axis(</strong>[0, 4, 0, 10])
- plt.legend()
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
加入坐标轴说明和标题说明:
- plt.plot([1,2,3], [1,2,3], 'go-', <strong>label=</strong>'line 1', linewidth=2)
- plt.plot([1,2,3], [1,4,9], 'rs', label='line 2')
- plt.axis([0, 4, 0, 10])
- plt.<strong>xlabel</strong>('data x')
- plt.ylabel('target y')
- plt.<strong>title</strong>('test plot')
- plt.<strong>legend()</strong>
加入网格:
- plt.grid()
- plt.legend(['3','4','5'], loc='upper right')
- plt.show()
上面全部的格式都能够通过关键词来控制(格式,即參数kwargs):
- plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12).
The kwargs are Line2D properties:
Property | Description |
---|---|
agg_filter | unknown |
alpha | float (0.0 transparent through 1.0 opaque) |
animated | [True | False] |
antialiased or aa |
[True | False] |
axes | an Axes instance |
clip_box | a matplotlib.transforms.Bbox instance |
clip_on | [True | False] |
clip_path | [ (Path, Transform) | Patch | None ] |
color or c |
any matplotlib color |
contains | a callable function |
dash_capstyle | [‘butt’ | ‘round’ | ‘projecting’] |
dash_joinstyle | [‘miter’ | ‘round’ | ‘bevel’] |
dashes | sequence of on/off ink in points |
drawstyle | [‘default’ | ‘steps’ | ‘steps-pre’ | ‘steps-mid’ | ‘steps-post’] |
figure | a matplotlib.figure.Figure instance |
fillstyle | [‘full’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’ | ‘none’] |
gid | an id string |
label | string or anything printable with ‘%s’ conversion. |
linestyle or ls |
['-' | '--' | '-.' | ':' | 'None' | ' ' | ''] |
linewidth or lw |
float value in points |
lod | [True | False] |
marker | A valid marker style |
markeredgecolor or mec |
any matplotlib color |
markeredgewidth or mew |
float value in points |
markerfacecolor or mfc |
any matplotlib color |
markerfacecoloralt or mfcalt |
any matplotlib color |
markersize or ms |
float |
markevery | [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float] |
path_effects | unknown |
picker | float distance in points or callable pick function fn(artist, event) |
pickradius | float distance in points |
rasterized | [True | False | None] |
sketch_params | unknown |
snap | unknown |
solid_capstyle | [‘butt’ | ‘round’ | ‘projecting’] |
solid_joinstyle | [‘miter’ | ‘round’ | ‘bevel’] |
transform | a matplotlib.transforms.Transform instance |
url | a url string |
visible | [True | False] |
xdata | 1D array |
ydata | 1D array |
zorder | any number |
2、matplotlib.pyplot.scatter(x, y, s=20, c=u'b', marker=u'o', cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None,verts=None, hold=None, **kwargs)散点图:
本质上和plot没甚差别。但要注意:
1)不能同一时候画多个曲线,plt.scatter(x1, y1, c='b', marker='o', x2, y2, c='r', marker='^', s=5)不合法。
2)color、marker等不能同一时候作为一个參数,plt.scatter(x1, y1, 'bo', s=5)不合法。
3)给个样例:
- plt.scatter(x1, y1, c='b', marker='o', s=5)
4)我们看到,scatter会自己主动在坐标的头尾加上“延长”的部分,但plot假设不指定axis,则不会延长。
5)为了同一时候在一个图上画多条曲线。能够使用holdkeyword:
(When hold is True,
subsequent plot commands will be added to the current axes. When hold is False,
the current axes and figure will be cleared on the next plot command.)
- plt.scatter(x1, y1, s=10, c='b', marker='o', label='test plot 1')
- plt.<strong>hold(True)</strong>
- plt.scatter(x2, y2, s=5, c='r', marker='^', label='test plot 2')
- plt.legend()
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
假设不使用hold,效果例如以下:
- plt.scatter(x1, y1, s=10, c='b', marker='o', label='test plot 1')
- plt.hold(<strong>False)</strong>
- plt.scatter(x2, y2, s=5, c='r', marker='^', label='test plot 2')
- plt.legend()
待续。。。。
scikit-learn:matplotlib.pyplot经常使用绘图功能总结(1)的更多相关文章
- 在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the python-tk package
在绘图的时候import matplotlib.pyplot as plt报错:ImportError: No module named '_tkinter', please install the ...
- matplotlib.pyplot 绘图详解 matplotlib 安装
apt-get install python-matplotlib 转载自: http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086. ...
- 服务器上使用matplotlib.pyplot绘图
在linux服务器端执行python脚本,有时候需要画图,但是linux没有GUI界面,因此需要在导入matplotlib.pyplot库之前先执行 import matplotlib as mpl ...
- (原创)(四)机器学习笔记之Scikit Learn的Logistic回归初探
目录 5.3 使用LogisticRegressionCV进行正则化的 Logistic Regression 参数调优 一.Scikit Learn中有关logistics回归函数的介绍 1. 交叉 ...
- Scikit Learn: 在python中机器学习
转自:http://my.oschina.net/u/175377/blog/84420#OSC_h2_23 Scikit Learn: 在python中机器学习 Warning 警告:有些没能理解的 ...
- 利用cv与matplotlib.pyplot读图片与显示图片
import matplotlib.pyplot as pltimport cv2 as cva=cv.imread('learn.jpg')cv.imshow('learn',a)fig=plt.f ...
- 如何美化 Matplotlib 的工具栏和绘图风格
前言 matplotlib 功能十分强大,就是工具栏丑了点.忍了一个学期之后,还是决定自己动手,魔改一波 matplotlib 的工具栏样式.同时给大家分享一下自己按照 MATLAB 写的 matpl ...
- (原创)(三)机器学习笔记之Scikit Learn的线性回归模型初探
一.Scikit Learn中使用estimator三部曲 1. 构造estimator 2. 训练模型:fit 3. 利用模型进行预测:predict 二.模型评价 模型训练好后,度量模型拟合效果的 ...
- 数据分析之matplotlib.pyplot模块
首先都得导模块. import numpy as np import pandas as pd import matplotlib.pyplot as plt from pandas import S ...
随机推荐
- TASKCTL5.0日志乱码解决方案
从大学毕业到现在,做了不少银行外包项目,数据类的项目基本都用到taskctl调度产品,一直习以为然,觉得调度产品都应该是这样的,所以也没觉得怎样,直到后来有两个外包项目没用taskctl调度工具,要接 ...
- Angular——MVC模式开发实战
创建项目 创建工作目录 使用bower下载需要插件 git init.add.commit之后得到分支master,再创建developer分支,然后再此分支上进行具体功能开发 MVC架构 之前小项目 ...
- CentOS上oracle 11g R2数据库安装折腾记
1.虚拟机上centos镜像的获取.这里推荐网易镜像站中的CentOS7版本(其他开源镜像站亦可).这里给出链接: http://mirrors.163.com/centos/7.3.1611/iso ...
- LR中日志参数的设置
LR中日志参数的设置 1.Run-Time Setting日志参数的设置 在loadrunner的vuser菜单下的Run-Time Setting的General的LOG选项中可以对在执行脚本时Lo ...
- Jmeter之JDBC请求参数化(二)
二.上面已经讲了一些基本的配置,和简单的jdbc请求,下面来看下具体的如何将查询语句参数化. 参数化这里有几种方法,foreach,计数器,csv等,这里介绍几种方法.
- CAD利用Select2得到所有实体(网页版)
主要用到函数说明: IMxDrawSelectionSet::Select2 构造选择集.详细说明如下: 参数 说明 [in] MCAD_McSelect Mode 构造选择集方式 [in] VARI ...
- 【转载】dubbo约束的引入(解决eclipse中报错问题)
在采用分布式系统架构时,我们会经常使用到阿里巴巴的dubbo的分布式框架. 在相关xml配置了dubbo的约束依赖后,即使能上网eclipse.myeclipse等IDE也是无法识别dubbo的相关约 ...
- EXP-00083: 调用 EXFSYS.DBMS_EXPFIL_DEPASEXP.schema_info_exp 时出现前一问题
select owner,object_name,object_type,status from dba_objects where object_name = 'LT_EXPORT_PKG'; 如果 ...
- UVA - 12661 Funny Car Racing (Dijkstra算法)
题目: 思路: 把时间当做距离利用Dijkstra算法来做这个题. 前提:该结点e.c<=e.a,k = d[v]%(e.a+e.b); 当车在这个点的1处时,如果在第一个a这段时间内能够通过且 ...
- Python学习-变量
什么是变量? 概念:变量就是会变化的量,主要是“变”与“量”二字.变即是“变化”. 特点:与其他编程语言相同,变量是最基本的存储单位,是用来存放数据的容器.可以引用一个具体的数值,进而直接去改变这个引 ...