【Python】python中plot用法——线条、点、颜色

【Python】python中plot用法——线条、点、颜色,第1张

概述图的存在,让数据变得形象化。无论多么复杂的东西,都是简单的组合。plot画图时可以设定线条参数。包括:颜色、线型、标记风格。

图的存在,让数据变得形象化。无论多么复杂的东西,都是简单的组合。

plot画图时可以设定线条参数。包括:颜色、线型、标记风格。
1)控制颜色
颜色之间的对应关系为
b---blue   c---cyan  g---green    k----black
m---magenta r---red  w---white    y----yellow
有三种表示颜色的方式:
a:用全名  b:16进制如:#FF00FF  c:RGB或RGBA元组(1,1,1) d:灰度强度如:‘0.7’
2)控制线型
符号和线型之间的对应关系
-      实线
--     短线
-.     短点相间线
:     虚点线

<pre >
>>>import matplotlib

from pylab import *
help(plot)
Help on function plot in module matplotlib.pyplot:

plot(*args,*kwargs)
    Plot lines and/or markers to the
    :class:~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.axes.Axes.  
args is a variable length
    argument,allowing for multiple
x,y pairs with an
    optional format string.  For example,each of the following is
    legal::
    
        plot(x,y)         # plot x and y using default line style and color
        plot(x,y,'bo')   # plot x and y using blue circle markers
        plot(y)            # plot y using x as index array 0..N-1
        plot(y,'r+')      # ditto,but with red plusses
    
    If
x and/or y is 2-dimensional,then the corresponding columns
    will be plotted.
    
    An arbitrary number of
x,y,fmt groups can be
    specifIEd,as in::
    
        a.plot(x1,y1,'g^',x2,y2,'g-')
    
    Return value is a List of lines that were added.
    
    The following format string characters are accepted to control
    the line style or marker:
    
    ================    ===============================
    character           description
    ================    ===============================
    '-'             solID line style
    '--'            dashed line style
    '-.'            dash-dot line style
    ':'             dotted line style
    '.'             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'             triup 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    '|'            v<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne marker    '_'            h<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne marker     ================    ===============================          The f<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>lowing <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a> abbreviations are supported:          ==========  ========     ch<a href="https://www.jb51.cc/tag/ara/" target="_blank" >ara</a>cter   <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>     ==========  ========     'b'         blue     'g'         green     'r'         red     'c'         cyan     'm'         <a href="https://www.jb51.cc/tag/magenta/" target="_blank" >magenta</a>     'y'         yellow     'k'         black     'w'         white     ==========  ========          In addition,you can specify <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>s in many weird and     wonderf<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a> ways,including f<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>l <a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>s ('green'),hex     strings ('#008000'),RGB or RGBA tuples ((0,1)) or     grayscale intensit<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>s as a string ('0.8').  Of these,the     string specifications can be used in place of afmtgroup,    but the tuple forms can be used only askwargs.          <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne styles and <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>s are combined in a single format string,as in    'bo'for blue circles.          The *<a href="https://www.jb51.cc/tag/kwargs/" target="_blank" >kwargs</a>* can be used to set <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne propert<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>s (any property that has     aset_*method).  You can use this to set a <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne label (for <a href="https://m.jb51.cc/tag/auto/" target="_blank" >auto</a>     legends),<a href="https://www.jb51.cc/tag/linewidth/" target="_blank" >linewidth</a>,anitia<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>sing,marker face <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>,etc.  Here is an     example::              plot([1,2,3],[1,'go-',label='<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne 1',<a href="https://www.jb51.cc/tag/linewidth/" target="_blank" >linewidth</a>=2)         plot([1,4,9],'rs', label='<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne 2')         axis([0,10])         legend()          If you make m<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>tiple <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a> with one plot command,the <a href="https://www.jb51.cc/tag/kwargs/" target="_blank" >kwargs</a>     apply to all those <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>,e.g.::              plot(x1,antia<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>sed=False)          Neither <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne will be antia<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ased.          You do not need to use format strings,which are just     abbreviations.  All of the <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne propert<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>s can be contr<a href="https://m.jb51.cc/tag/ol/" target="_blank" >ol</a>led     by keyword arguments.  For example,you can set the <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>,    marker,<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>tyle,and marker<a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a> with::              plot(x,<a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>='green',<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>tyle='dashed',marker='o',             markerface<a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>='blue',markersize=12).  See              :class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>.<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne2D` for details.          The <a href="https://www.jb51.cc/tag/kwargs/" target="_blank" >kwargs</a> are :class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>.<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ne2D` propert<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>s:            agg_filter: unk<a href="https://www.jb51.cc/tag/Now/" target="_blank" >Now</a>n       <a href="https://m.jb51.cc/tag/Alpha/" target="_blank" >Alpha</a>: <a href="https://m.jb51.cc/tag/float/" target="_blank" >float</a> (0.0 <a href="https://m.jb51.cc/tag/transparent/" target="_blank" >transparent</a> through 1.0 opaque)                animated: [True | False]                antia<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>ased or aa: [True | False]                axes: an :class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.axes.Axes` instance                c<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>p_<a href="https://www.jb51.cc/tag/Box/" target="_blank" >Box</a>: a :class:`matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://m.jb51.cc/tag/transform/" target="_blank" >transform</a>s.B<a href="https://www.jb51.cc/tag/Box/" target="_blank" >Box</a>` instance                c<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>p_on: [True | False]                c<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>p_path: [ (:class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.path.Path`,        :class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://m.jb51.cc/tag/transform/" target="_blank" >transform</a>s.<a href="https://m.jb51.cc/tag/transform/" target="_blank" >transform</a>`) |         :class:`~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.patches.Patch` | None ]                <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a> or c: any matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b <a href="https://m.jb51.cc/tag/color/" target="_blank" >color</a>                contains: a callable function                dash_capstyle: ['butt' | 'round' | 'projecting']                dash_joinstyle: ['miter' | 'round' | 'bevel']                dashes: sequence of on/off ink in points                data: 2D array (rows are x,y) or two 1D arrays                drawstyle: [ 'defa<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>t' | 'steps' | 'steps-pre' | 'steps-m<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>' | 'steps-post' ]                <a href="https://www.jb51.cc/tag/fig/" target="_blank" >fig</a>ure: a :class:`matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://www.jb51.cc/tag/fig/" target="_blank" >fig</a>ure.<a href="https://www.jb51.cc/tag/fig/" target="_blank" >fig</a>ure` instance                fillstyle: ['f<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>l' | '<a href="https://m.jb51.cc/tag/left/" target="_blank" >left</a>' | 'right' | 'b<a href="https://www.jb51.cc/tag/ott/" target="_blank" >ott</a>om' | '<a href="https://m.jb51.cc/tag/top/" target="_blank" >top</a>']                g<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>: an <a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a> string                label: any string                <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>tyle or ls: ['-'|'--'|'-.'|':'|'None'|' '|'']         and any drawstyle in combination with a <a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a><a href="https://www.jb51.cc/tag/nes/" target="_blank" >nes</a>tyle,e.g.'steps--'.                <a href="https://www.jb51.cc/tag/linewidth/" target="_blank" >linewidth</a> or lw: <a href="https://m.jb51.cc/tag/float/" target="_blank" >float</a> value in points                lod: [True | False]                marker: [7|4|5|6|'o'|'D'|'h'|'H'|'_'|''|None|'None'|' '|'8'|'p'|','|'+'|'.'|'s'|''|'d'|3|0|1|2|'1'|'3'|'4'|'2'|'v'|'<'|'>'|'^'|'|'|'x'|'$...$'`` | tuple | Nx2 array ]
      markeredgecolor or mec: any matplotlib color         
      markeredgewIDth or mew: float value in points         
      markerfacecolor or mfc: any matplotlib color         
      markerfacecoloralt or mfcalt: any matplotlib color         
      markersize or ms: float         
      markevery: None | integer | (startind,strIDe)
      picker: float distance in points or callable pick function         fn(artist,event)         
      pickradius: float distance in points         
      rasterized: [True | False | None]         
      snap: unkNown
      solID_capstyle: ['butt' | 'round' |  'projecting']         
      solID_joinstyle: ['miter' | 'round' | 'bevel']         
      transform: a :class:matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.<a href="https://m.jb51.cc/tag/transform/" target="_blank" >transform</a>s.<a href="https://m.jb51.cc/tag/transform/" target="_blank" >transform</a> instance         
      url: a url string         
      visible: [True | False]         
      xdata: 1D array         
      ydata: 1D array         
      zorder: any number         
    
    kwargs
scalex and scaley,if defined,are passed on to
    :meth:~matplot<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>b.axes.Axes.<a href="https://m.jb51.cc/tag/auto/" target="_blank" >auto</a>scale_v<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>w to determine
    whether the
x and y axes are autoscaled; the default is
   
True*.
    
    Additional kwargs: hold = [True|False] overrIDes default hold state

总结

以上是内存溢出为你收集整理的【Python】python中plot用法——线条、点、颜色全部内容,希望文章能够帮你解决【Python】python中plot用法——线条、点、颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1209145.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存