matplotlib.pyplot.plot()用法


Python–Matplotlib(基本用法)
python绘制三维图

一图多线

在这里插入图片描述
画一条线plot(x,y3,color='#900302',marker='+',linestyle='-')
画多条线 plt.plot(x,y,"bo-",x,z,"g1--",x,m,"kv:")
"g1–"
颜色(color),点型(marker),线型(linestyle),
‘[color][marker][line]’

import numpy as np 
from matplotlib import pyplot as plt 
 
x = np.arange(1,11,2) 
print(x)
y =  np.sin(x)
z =2*np.cos(10*x)
m =2*x+3
plt.title("Matplotlib demo") 
plt.xlabel("x axis caption") 
plt.ylabel("测试") 
plt.plot(x,y,"bo-",x,z,"g1--",x,m,"kv:") 
plt.show()
    =============    ===============================
    character        颜色(color)
    =============    ===============================
    ``'b'``          blue 蓝
    ``'g'``          green 绿
    ``'r'``          red 红
    ``'c'``          cyan 蓝绿
    ``'m'``          magenta 洋红
    ``'y'``          yellow 黄
    ``'k'``          black 黑
    ``'w'``          white 白
    =============    ===============================
    =============    ===============================
    character        点型(marker)
    =============    ===============================
    ``'.'``          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
    =============    ===============================
    =============    ===============================
    character        线型(linestyle)
    =============    ===============================
    ``'-'``          solid line style 实线
    ``'--'``         dashed line style 虚线
    ``'-.'``         dash-dot line style 点画线
    ``':'``          dotted line style 点线
    =============    ===============================

参考线、网格线、数学函数

三角:sin、cos、tan、
指数:exp
对数:log、log10
开方:sqrt
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,5,1000) 
print(x)
y = np.log(x)
plt.plot(x,y,"b")
plt.hlines(2,0,6,linestyle='--')
plt.vlines(4,-3,4,linestyle='--')
plt.grid(alpha=0.4,linestyle='--')
plt.show()

动态图

import numpy as np
import matplotlib.pyplot as plt

N = 20
plt.close() # 关闭打开的图形窗口
def anni():
    fig = plt.figure()
    plt.ion() # 打开交互式绘图interactive
    for i in range(N):
        plt.cla()           # 清除原有图像
        plt.xlim(-0.2,20.4) # 设置x轴坐标范围
        plt.ylim(-1.2,1.2)  # 设置y轴坐标范围
        # 每当i增加的时候,增加自变量x的区间长度,可以理解为不断叠加绘图,所以每次循环之前都使用plt.cla()命令清除原有图像
        x = np.linspace(0,i+1,1000) 
        y = np.sin(x)
        plt.plot(x,y)
        plt.pause(0.1)
    plt.ioff() #关闭交互式绘图
    plt.show()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值