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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 时间复杂度是什么_时间复杂度的表示方法

    时间复杂度是什么_时间复杂度的表示方法-宝宝为啥听不懂他们在讨论的时间复杂度0.0-我怎么知道这个算法运行得比那个算法快0.0-我究竟会不会超时0.0-我为什么还会超时0.0-时间复杂度怎么算0.0在别人还不会求时间复杂度的时候而你会了是不是很酷在别人都会求时间复杂度的时候而你不会是不是很尴尬千里之行始于足下希望这篇文章能祝你一臂之力=w= 此篇详解,希望能帮助各位稍微解决一下不解=w=…

    2025年6月6日
    2
  • 关于安装QCAT/QXDM异常的问题

    关于安装QCAT/QXDM异常的问题第一种情况安装之后报licenseerror原因:可能安装时出错;解决:卸载QXDM和QCAT之后,删除注册表的信息,删除C盘文件夹内容:注册表位置:HKEY_LOCAL_MACHINE\SOFTWARE\Qualcomm\QIKC盘内容位置:C:\ProgramData\Qualcomm\QIKC:\ProgramFiles(x86)\Qualcomm\QIKTool…

    2022年10月2日
    1
  • django filter查询_搜索全局排序方法

    django filter查询_搜索全局排序方法前言当我们需要对后台的数据进行过滤的时候,drf有两种,搜索过滤和排序过滤。搜索过滤:比如我们想返回sex=1的,那么我们就可以从所有数据中进行筛选排序过滤:比如我们想对价格进行升序排列,就可以

    2022年7月31日
    6
  • IDEA + Groovy脚本一键生成实体类,用法舒服,高效!

    点击上方“全栈程序员社区”,星标公众号 重磅干货,第一时间送达 作者:悲凉的秋风 blog.csdn.net/qq_34371461/article/details/8057128…

    2021年6月27日
    95
  • 45天带你玩转Node(第二天)走进Node.js「建议收藏」

    45天带你玩转Node(第二天)走进Node.js「建议收藏」粉丝要求博主系统的写一篇关于Node.js的学习资料,但其实我们的Node.js知识点并不少,所以博主为大家搭建了一个专栏,为了方便大家系统的学习Node.js,大家记得订阅哦!虽然我们的Node.js还很年轻,但是他也已经有了很高的地位,让我们尽情的畅游在Node.js的专栏中吧,希望通过此专栏我们能够系统的将Node.js学好,它将会成为我们的一大亮点,我们可以用这款前端中的后端语言让提升我们的价值与眼界,如今的他也已经成为面试官口中的高并发面试内容了,一起加油!

    2022年7月16日
    20
  • phpstorm激活码使用方法2021_通用破解码

    phpstorm激活码使用方法2021_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    65

发表回复

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

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