资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PythonmatplotlibLine2D对象怎么用

这篇文章主要介绍 Python matplotlib Line2D对象怎么用,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

我们提供的服务有:网站设计制作、成都网站设计、微信公众号开发、网站优化、网站认证、武陵ssl等。为数千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的武陵网站制作公司

总括

matplotlib.pyplot很像MATLAB。它的每一个函数都会对现有的图形进行更改:比如建立一个图形(figure),创建画图区域,在画图区域做出线条,使用标签装饰。
如果你传入了一个简单的list或者array,matplotlib会把它当成y值,并自动生成x值。事实上所有序列都会被转换为numpy arrays。

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

Python matplotlib Line2D对象怎么用

当你传入两个list或者array时,第一个会被当成x值,第二个会被当成y值,而且你可以通过第三个参数设置显示的形状和颜色(这是一个组合),当然你也可以分别设置形状和颜色。通过plt.axis(xmin, xmax, ymin, ymax)函数你可以设置x轴,y轴的最大值和最小值:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

Python matplotlib Line2D对象怎么用

Line2D对象

Line2D

Bases: matplotlib.artist.Artistclass matplotlib.lines.Line2D(xdata, ydata, linewidth=None, linestyle=None, color=None, marker=None, markersize=None, markeredgewidth=None, markeredgecolor=None, markerfacecolor=None, markerfacecoloralt='none', fillstyle=None, antialiased=None, dash_capstyle=None, solid_capstyle=None, dash_joinstyle=None, solid_joinstyle=None, pickradius=5, drawstyle=None, markevery=None, **kwargs)

属性控制

有三种方式设置线的属性
1)直接在plot()函数中设置

plt.plot(x, y, linewidth=2.0)

2)通过获得线对象,对线对象进行设置

line, = plt.plot(x, y, '-')line.set_antialiased(False) # turn off antialising

3)获得线属性,使用setp()函数设置

lines = plt.plot(x1, y1, x2, y2)# use keyword argsplt.setp(lines, color='r', linewidth=2.0)
PropertyValue Type
alphafloat
animated[True False]
antialiased or aa[True False]
clip_boxa matplotlib.transform.Bbox instance
clip_on[True False]
clip_patha Path instance and a Transform instance, a Patch
color or cany matplotlib color
containsthe hit testing function
dash_capstyle[‘butt’ ‘round’ ‘projecting’]
dash_joinstyle[‘miter’ ‘round’ ‘bevel’]
dashessequence of on/off ink in points
data(np.array xdata, np.array ydata)
figurea matplotlib.figure.Figure instance
labelany string
linestyle or ls[‘-’ ‘–’ ‘-.’ ‘:’ ‘steps’ …]
linewidth or lwfloat value in points
lod[True False]
marker[‘+’ ‘,’ ‘.’ ‘1’ ‘2’ ‘3’ ‘4’]
markeredgecolor or mecany matplotlib color
markeredgewidth or mewfloat value in points
markerfacecolor or mfcany matplotlib color
markersize or msfloat
markevery[ None integer (startind, stride) ]
pickerused in interactive line selection
pickradiusthe line pick selection radius
solid_capstyle[‘butt’ ‘round’ ‘projecting’]
solid_joinstyle[‘miter’ ‘round’ ‘bevel’]
transforma matplotlib.transforms.Transform instance
visible[True False]
xdatanp.array
ydatanp.array
zorderany number
linestyledescription
‘-‘?or?’solid’solid line
‘–’?or?’dashed’dashed line
‘-.’?or?’dashdot’dash-dotted line
‘:’?or?’dotted’dotted line
‘None’draw nothing
‘?’draw nothing
draw nothing
markerdescription
“.”point
“,”pixel
“o”circle
“v”triangle_down
“^”triangle_up
“<”triangle_left
“>”triangle_right
“1”tri_down
“2”tri_up
“3”tri_left
“4”tri_right
“8”octagon
“s”square
“p”pentagon
“P”plus (filled)
“*”star
“h”hexagon1
“H”hexagon2
“+”plus
“x”x
“X”x (filled)
“D”diamond
“d”thin_diamond
“_”hline
TICKLEFTtickleft
TICKRIGHTtickright
TICKUPtickup
TICKDOWNtickdown
CARETLEFTcaretleft (centered at tip)
CARETRIGHTcaretright (centered at tip)
CARETUPcaretup (centered at tip)
CARETDOWNcaretdown (centered at tip)
CARETLEFTBASEcaretleft (centered at base)
CARETRIGHTBASEcaretright (centered at base)
CARETUPBASEcaretup (centered at base)
“None”,?”?”?or?”“nothing
‘ ... ’render the string using mathtext.
vertsa list of (x, y) pairs used for Path vertices. The center of the marker is located at (0,0) and the size is normalized.
patha?Path?instance.

以上是“ Python matplotlib Line2D对象怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


标题名称:PythonmatplotlibLine2D对象怎么用
URL链接:http://cdkjz.cn/article/gsicjd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220