參考: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 matplotlib.transforms.Bbox instance
clip_on [True | False]
clip_path [ (PathTransform)
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 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 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()

待续。。。。

最新文章

  1. 介绍一款原创的四则运算算式生成器:CalculateIt2
  2. kafka原理存储
  3. LeetCode 1 Two Sum(二分法)
  4. PHP中的Array
  5. 网站开发常用jQuery插件总结(一)提示插件alertify
  6. ACM训练计划step 1 [非原创]
  7. ArcGIS加载高德、OSM和谷歌等地图
  8. 比特币区块结构Merkle树及简单支付验证分析
  9. 20162330 实验四 《Android程序设计》 实验报告
  10. ACM Least Common Multiple
  11. css中绝对定位和相对定位的区别
  12. Linux基础命令---sysctl修改内核参数
  13. 如何禁用Chrome / Firefox /IE浏览器的Cookie
  14. charles本地调试之map和rewrite功能
  15. CentOS7 设置集群时间同步
  16. yii2自定义json格式success,error跳转
  17. 《Linux内核设计与实现》 第一、二章学习笔记
  18. Solr4.4入门,介绍Solr的安装、IK分词器的配置及高亮查询结果(转)
  19. ArrayDeque源代码分析
  20. Python - PIL-pytesseract-tesseract验证码识别

热门文章

  1. ReLU激活函数:简单之美
  2. Selenium示例集锦--常见元素识别方法、下拉框、文本域及富文本框、鼠标操作、一组元素定位、弹窗、多窗口处理、JS、frame、文件上传和下载
  3. 自学php【一】 任务:图片上传即时可见
  4. 最容易理解的HMM文章
  5. windows 下完全卸载service
  6. Spring scheduled cron 表达式
  7. TCP端口状态LISTENING ESTABLISHED CLOSE_WAIT TIME_WAIT SYN_SENT
  8. java学习_5_21
  9. oracle 备份/恢复
  10. Invalid ON UPDATE clause for &#39;create_date&#39; column