pyplot matplotlib plot,pyplotmatplotlib

來源:互聯網
上載者:User

pyplot matplotlib plot,pyplotmatplotlib

matplotlib實際上是一套物件導向的繪圖庫,它所繪製的圖表中的每個繪圖元素,例如線條Line2D、文字Text、刻度等在記憶體中都有一個對象與之對應。
為了方便快速繪圖matplotlib通過pyplot模組提供了一套和MATLAB類似的繪圖API,將眾多繪圖對象所構成的複雜結構隱藏在這套API內部。我們只需要調用pyplot模組所提供的函數就可以實現快速繪圖以及設定圖表的各種細節。pyplot模組雖然用法簡單,但不適合在較大的應用程式中使用。
為了將物件導向的繪圖庫封裝成只使用函數的調用介面,pyplot模組的內部儲存了當前圖表以及當前子圖等資訊。當前的圖表和子圖可以使用plt.gcf()和plt.gca()獲得,分別表示"Get Current Figure"和"Get Current Axes"。在pyplot模組中,許多函數都是對當前的Figure或Axes對象進行處理,比如說:
plt.plot()實際上會通過plt.gca()獲得當前的Axes對象ax,然後再調用ax.plot()方法實現真正的繪圖。
可以在Ipython中輸入類似"plt.plot??"的命令查看pyplot模組的函數是如何對各種繪圖對象進行封裝的。

1、pyplot.plot(*args, **kwargs)

這個函數有兩個參數,一個可變參數,一個具名引數。可變參數可以指定三個參數,x,y序列和線條格式字串,下面的例子是一些常用的搭配

    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
如果沒有使用具名引數,那麼可以設定任意組的x,y,格式字串,例如:
a.plot(x1, y1, 'g^', x2, y2, 'g-')

plot的傳回值類型是matplotlib.lines.Line2D object
如果不指定plot會採用預設的線條和顏色,下面給出線條和顏色的可設值
線條值
================    ===============================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'``             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================    ===============================顏色值==========  ========character   color==========  ========'b'         blue'g'         green'r'         red'c'         cyan'm'         magenta'y'         yellow'k'         black'w'         white==========  ========

具名引數可以用來設定線條的屬性,每個屬性都有一個set_...的方法,可以用來設定線條的標籤,線寬等等

字串格式指定格式只是縮寫的形式,可以不用縮寫的形式,只用具名引數的形式設定線條的格式,樣本如下

具名引數的屬性就是類matplotlib.lines.Line2D的屬性,對應的屬性有

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.