6.matplotlib基础使用

安装

conda install -n tensorflow matplotlib

实例,scipy部分有应用

import sys
import matplotlib.pyplot as plt
import numpy as np
print(sys.version)
'''
3.5.3 |Continuum Analytics, Inc.| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)]
'''
'''
plot()为画线函数,下面的小例子给ploy()一个列表数据[1,2,3,4],matplotlib假设它是y轴的数值序列,然后会自动产生x轴的值,因为python是从0作为起始的,所以这里x轴的序列对应为[0,1,2,3]。
'''
plt.plot([1,2,3,4])#画线
plt.ylabel('some numbers')    #为y轴加注释
plt.show()

Paste_Image.png

plt.plot([1,2,3,4], [1,4,9,16], 'ro')#画红点
plt.axis([0, 6, 0, 20])#[xmin,xmax,ymin,ymax]设定x,y刻量范围
plt.show()

Paste_Image.png

# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

Paste_Image.png

def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t)

t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

plt.figure(1)#figure()命令时可选的,因为figure(1)是默认创建的。
#subplot()命令会指定一个坐标系,默认是subplot(111),111参数分别说明行的数目numrows,列的数目numcols,第几个图像fignum(fignum的范围从1到numrows*numcols)。
#subplot(211)指定显示两行,每行一图,接下来为第一幅图像。
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')

plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()

Paste_Image.png

mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)

# the histogram of the data
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)


plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()

Paste_Image.png

线条属性:实线,虚线,点横线等等 
线条标记:点,正方形,星型
  
线条颜色:蓝,红,青,绿,黄,黑
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值