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

相关推荐

  • 大数据建模流程之任务分析

    大数据建模流程之任务分析上一篇文章我们简单阐述了,大多数研究者在进行大数据分析时,所存在的逻辑问题,并简明扼要的对大数据建模流程进行了说明,那么为了使大家更加清晰每一个步骤的具体内容,我们将每一个模块展开分析。详细阐述流程中具体要做的工作内容?一.宏观角度无论是大数据还是人工智能技术,其实都是需求或者项目主题的实现手段,商业上希望技术能够将产品向商品转化,或者对市场进行科学的分析,从而引导公司决策更符合市场需求;科研上希望技术能够进行多学课融合,使得科研结果更具有说服力,亦或者是技术本身的创新与变革,使得科技文明不断发展。由此

    2022年6月4日
  • cmd ping命令大全_ping命令怎么使用

    cmd ping命令大全_ping命令怎么使用简介:ping是一种Computernetworktools(电脑网络工具),作用是测试数据包是否能通过IP协议到达特定主机。Ping是Windows系统、Unix系统和Linux系统下的一个命令。它也属于一个通信协议,是TCP/IP协议的一部分。利用“ping”命令可以检查网络是否连通,可以很好地帮助我们分析和判定网络故障。该命令还可以加许多参数使用。例如:-t,-l,-n。(注意,所有ping指令都必须在知道IP的情况下使用)使用方法:主要的用法:1.-t:不断向目标IP发送数.

    2022年9月22日
  • RegisterStartupScript() 和 RegisterClientScriptBlock()[通俗易懂]

    RegisterStartupScript() 和 RegisterClientScriptBlock()[通俗易懂] 使用RegisterStartupScript()和RegisterClientScriptBlock()添加客户端脚本块  System.Web.UI.Page类包含的两个方法可以将客户端脚本代码发送到由ASP.NETWeb页面提供的HTML中: RegisterStartupScript(key,sc

    2022年7月20日
  • 传奇三架设教程_手游传奇服务端架设教程

    传奇三架设教程_手游传奇服务端架设教程传奇3私服架设技术教程准备工具:1:装有windows98/2000/xp/2003系统、内存至少256M的电脑一台2:传奇3服务器端一个3:SQL2000一个下面开始跟着我说的步骤架设传奇3服

    2022年9月27日
  • 购物程序「建议收藏」

    购物程序「建议收藏」#-*-coding:utf-8-*-"""CreatedonTueSep1116:35:292018@author:车路历程"&

    2022年8月3日
  • C语言中的结构体,结构体中数组初始化与赋值

    C语言中的结构体,结构体中数组初始化与赋值原作地址:https://www.cnblogs.com/zhangfeionline/p/5913905.html最近写c语言中的结构体遇到了些问题,从网上找了些资料如下:结构体是连续存储的,但由于结构体中成员类型各异,所以会存在内存对齐问题,也就是内存里面会有空档,具体的对齐方式这里暂不讨论;1.结构体的定义和赋值结构体是可以直接初始化的,在定义的时候,就可

    2022年7月18日

发表回复

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

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