python Matplotlib绘图 基础笔记

                                      python Matplotlib 基础笔记

目录

       1、可查备忘之代码笔记

        2、效果


   1、可查备忘之代码笔记

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imread, imsave, imresize

#Matplotlib是一个作图库。这里简要介绍matplotlib.pyplot模块,功能和MATLAB的作图功能类似。

x=np.linspace(0,20,16)[:,np.newaxis]
noise=np.random.normal(0,0.1,size=x.shape)
y1=np.power(x,2)+noise
y2=np.cos(x)

#1、折线图和散点图
#1.1 初步体验
#折线图
#plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--')
plt.plot(x,y1)
plt.show()

#散点图
#plt.scatter(x,y2,marker='o',  s = 20,c="green")
plt.scatter(x,y2,marker='o',  s = 20,c="red")
plt.show()

# 1.2 同一张图
plt.plot(x,y1,color='red')
plt.plot(x,y2,color='blue')
plt.show()

# 1.3 多个图在一个列表中
plt.subplot(1,2,1)   #行  列  序号
plt.plot(x,y1)
plt.subplot(1,2,2)
plt.scatter(x,y2,marker='o',  s = 10,c="black")
plt.show()

# 1.4 图的轴标签,图例,图标题
plt.plot(x,y1,c='red')
plt.plot(x,y2,c='blue')
plt.xlabel('x axis label')         #x坐标标签
plt.ylabel('y axis label')         #y坐标标签
plt.title('squre and sin')        #标题
plt.legend(['squre', 'sine'])   #图例
plt.show()


#1.5 画布的使用
#1.5.1 体验
fig=plt.figure()
p1 = fig.add_subplot(211)
p2=  fig.add_subplot(212)
p1.plot(x,y1,c='red')
p2.scatter(x,y2)
plt.show()

#1.5.2  完整参数 设置画布大小

#设置坐标轴范围
#plt.xlim((-1,0.5))
#plt.ylim((-1,0.5))
plt.figure(num=1,figsize=(8,5))
plt.plot(x,y1)
plt.figure(num=2,figsize=(6,4))
plt.plot(x,y2)
plt.show()

# 1.6 显示图像
img=imread('E:/TEST_IMG/1.jpg')
plt.imshow(img)
plt.show()

# 2、 3D绘图
#............................待续

 

    2、效果

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值