matplotlib.pyplot.plot()参数详解「建议收藏」

matplotlib.pyplot.plot()参数详解「建议收藏」https://matplotlib.org/api/pyplot_summary.html在交互环境中查看帮助文档:importmatplotlib.pyplotasplthelp(plt.plot)以下是对帮助文档重要部分的翻译:plot函数的一般的调用形式:#单条线:plot([x],y,[fmt],data=None,**kwargs)#多条线一…

大家好,又见面了,我是你们的朋友全栈君。

https://matplotlib.org/api/pyplot_summary.html

在交互环境中查看帮助文档:

import matplotlib.pyplot as plt
help(plt.plot)

以下是对帮助文档重要部分的翻译:

plot函数的一般的调用形式:

#单条线:
plot([x], y, [fmt], data=None, **kwargs)
#多条线一起画
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)

可选参数[fmt] 是一个字符串来定义图的基本属性如:颜色(color),点型(marker),线型(linestyle)

具体形式  fmt = ‘[color][marker][line]’

fmt接收的是每个属性的单个字母缩写,例如

plot(x, y, 'bo-')  # 蓝色圆点实线

若属性用的是全名则不能用*fmt*参数来组合赋值,应该用关键字参数对单个属性赋值如:

plot(x,y2,color=’green’, marker=’o’, linestyle=’dashed’, linewidth=1, markersize=6)

plot(x,y3,color=’#900302′,marker=’+’,linestyle=’-‘)

常见的颜色参数:**Colors**

 

也可以对关键字参数color赋十六进制的RGB字符串如 color=’#900302′

    =============    ===============================
    character        color
    =============    ===============================
    ``'b'``          blue 蓝
    ``'g'``          green 绿
    ``'r'``          red 红
    ``'c'``          cyan 蓝绿
    ``'m'``          magenta 洋红
    ``'y'``          yellow 黄
    ``'k'``          black 黑
    ``'w'``          white 白
    =============    ===============================
 点型参数**Markers**,如:marker='+' 这个只有简写,英文描述不被识别
=============    ===============================
    character        description
    =============    ===============================
    ``'.'``          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
    =============    ===============================

线型参数**Line Styles**,linestyle=’-‘

    =============    ===============================
    character        description
    =============    ===============================
    ``'-'``          solid line style 实线
    ``'--'``         dashed line style 虚线
    ``'-.'``         dash-dot line style 点画线
    ``':'``          dotted line style 点线
    =============    ===============================

样例1

函数原型:matplotlib.pyplot.plot(*args, scalex=True, scaley=True, data=None, **kwargs)
>>> plot('xlabel', 'ylabel', data=obj)
解释:All indexable objects are supported. This could e.g. be a dict, a pandas.DataFame or a structured numpy array.
data 参数接受一个对象数据类型,所有可被索引的对象都支持,如 dict 等
import matplotlib.pyplot as plt  
import numpy as np
'''read file 
fin=open("para.txt")
a=[]
for i in fin:
  a.append(float(i.strip()))
a=np.array(a)
a=a.reshape(9,3)
'''
a=np.random.random((9,3))*2 #随机生成y
 
y1=a[0:,0]
y2=a[0:,1]
y3=a[0:,2]
 
x=np.arange(1,10)
 
ax = plt.subplot(111)
width=10
hight=3
ax.arrow(0,0,0,hight,width=0.01,head_width=0.1, head_length=0.3,length_includes_head=True,fc='k',ec='k')
ax.arrow(0,0,width,0,width=0.01,head_width=0.1, head_length=0.3,length_includes_head=True,fc='k',ec='k')
 
ax.axes.set_xlim(-0.5,width+0.2)
ax.axes.set_ylim(-0.5,hight+0.2)

plotdict = { 'dx': x, 'dy': y1 }
ax.plot('dx','dy','bD-',data=plotdict)

ax.plot(x,y2,'r^-')
ax.plot(x,y3,color='#900302',marker='*',linestyle='-')

plt.show()

matplotlib.pyplot.plot()参数详解「建议收藏」

样例2,

import matplotlib.pyplot as plt  
import numpy as np  
  
x = np.arange(0, 2*np.pi, 0.02)  
y = np.sin(x)  
y1 = np.sin(2*x)  
y2 = np.sin(3*x)  
ym1 = np.ma.masked_where(y1 > 0.5, y1)  
ym2 = np.ma.masked_where(y2 < -0.5, y2)  
  
lines = plt.plot(x, y, x, ym1, x, ym2, 'o')  
#设置线的属性
plt.setp(lines[0], linewidth=1)  
plt.setp(lines[1], linewidth=2)  
plt.setp(lines[2], linestyle='-',marker='^',markersize=4)  
#线的标签
plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'), loc='upper right')  
plt.title('Masked line demo')  
plt.show()  

matplotlib.pyplot.plot()参数详解「建议收藏」

例3 :圆

import numpy as np
import matplotlib.pyplot as plt

theta = np.arange(0, 2*np.pi, 0.01)
xx = [1,2,3,10,15,8]
yy = [1,-1,0,0,7,0]
rr = [7,7,3,6,9,9]

fig = plt.figure()
axes = flg.add_subplot(111)

i = 0
while i < len(xx):
    x = xx[i] + rr[i] *np.cos(theta)
    x = xx[i] + rr[i] *np.cos(theta)
    axes.plot(x,y)
    axes.plot(xx[i], yy[i], color='#900302', marker='*')
     i = i+1
width = 20
hight = 20
axes.arrow(0,0,0,hight,width=0.01,head_width=0.1,head_length=0.3,fc='k',ec='k')
axes.arrow(0,0,width,0,width=0.01,head_width=0.1,head_length=0.3,fc='k',ec='k')
plt.show()

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159244.html原文链接:https://javaforall.net

(1)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Rollup Bridge 介绍(三):Celer cBridge

    Rollup Bridge 介绍(三):Celer cBridge直播预告今晚7:30,我们邀请了Arweave生态头部项目everFinance带你玩转Arweave!敲黑板:观看直播还有机会获得丰厚ARtoken奖励与惊喜小礼品!C…

    2022年5月4日
    61
  • mysql批量插入大量数据「建议收藏」

    mysql批量插入大量数据「建议收藏」mysql批量插入大量数据时间:2020年11月25日今天遇到了一个批量插入大量数据任务,然后出于小白本能,直接for-each循环插入不就好了,于是手上开始噼里啪啦一顿操作,写好了从读取excel到插入数据库的工作,于是就美滋滋的开始了自己的测试,试了一把,一次通过perfect,然后后面就悲剧了,后面发现数据量稍微大一点,速度就会很慢很慢。于是掏出自己的制胜法典,后来我在知识和海洋中获取到了两种靠谱的方法。下面一点一点讲。测试的服务器信息1核2g5m的阿里云服务器(你懂得),mysql直接装

    2022年10月5日
    2
  • Redis集群搭建以及操作

    Redis集群搭建以及操作

    2021年6月4日
    101
  • 简述OTA测试「建议收藏」

    简述OTA测试「建议收藏」一、什么是OTA测试?  OTA测试是与RF传导测试相对应的,但与大家经常接触的RF传导有一些差异。  从连接控制方式看:  RF传导测试,是通过射频线将DUT直连到测试仪表的连接方式实现,如果有测试仪表就较容易实现。  而OTA测试,是通过“overtheair”方式实现与测试仪表连接,除了需要测试仪表,还需要有OTAchamber,以及实现控制DUT和测试仪表的OTA系统软件。  RFOTA(OverTheAir)测试会模拟产品的无线信号在空气中的传输场景,而此种测试

    2025年8月13日
    1
  • 计算机中1kb表示的字节数是多少_在计算机中1KB是指几字节

    计算机中1kb表示的字节数是多少_在计算机中1KB是指几字节大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答。1kb等于1024个字节。kB(Kilobyte),是一种资讯计量单位,是计算机数据存贮器存储单位字节的多倍形式。现今通常在标识内存等具有一般容量的储存媒介之储存容量时使用。根据国际单位制标准,1kB=1000B(字节,Byte)。根据按照IEC命名标准,用于二进制存储单位的标准命名是KiB,MiB等,1kiB=1024B。这是由…

    2022年9月30日
    1
  • linux查看文件权限修改记录_文件修改记录

    linux查看文件权限修改记录_文件修改记录1、从文件类型上分可分为三种,   用ls-l查询,以“一”开头的是文件,以字母“d”开头的是目录(俗称文件夹),以字母“l”开头的是连接。 2、剩下的9个分别三个为一组每一组都有四种符号组成分别是“r”,“w”,“x”,“-”。    r(read):代表读的权限    w(write):代表写的权限    x(execuite):

    2022年9月11日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号