plt.plot()的使用方法以及參數介紹

前言

偶然的一次操作,對plt.plot()中,僅僅傳入了一個列表,然後邏輯就和預想的出現了偏差。

plt.plot()

plt.plot() 參數介紹:

  1. x, y : array-like or scalar
    The horizontal / vertical coordinates of the data points. x values are optional. If not given, they default to [0, …, N-1]. x是可選的,如果x沒有,將默認是從0到n-1,也就是y的索引。那麼我的問題就解決了。
  2. fmt : str, optional
    A format string, e.g. ‘ro’ for red circles. See the Notes section for a full description of the format strings.定義線條的顏色和樣式的操作,如“ro”就是紅色的圓圈。
    Format strings are just an abbreviation for quickly setting basic line properties. All of these and more can also be controlled by keyword arguments. 這是一個快速設置樣式的方法,更多的參數可以參考最後一個keyboard arguments。
  3. **kwargs : Line2D properties, optional
    kwargs are used to specify properties like a line label (for auto legends), linewidth, antialiasing, marker face color.這是一大堆可選內容,可以來裏面指定很多內容,如“label”指定線條的標籤,“linewidth”指定線條的寬度,等等
    Example:
plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)
plot([1,2,3], [1,4,9], 'rs',  label='line 2')

擁有的部分參數,如下:

Property Description
agg_filter a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array
alpha float
animated bool
antialiased bool
clip_box Bbox
clip_on bool
clip_path [(Path, Transform)
color color
contains callable
dash_capstyle {‘butt’, ‘round’, ‘projecting’}
dash_joinstyle {‘miter’, ‘round’, ‘bevel’}
dashes sequence of floats (on/off ink in points) or (None, None)
drawstyle {‘default’, ‘steps’, ‘steps-pre’, ‘steps-mid’, ‘steps-post’}
figure Figure
fillstyle {‘full’, ‘left’, ‘right’, ‘bottom’, ‘top’, ‘none’}
gid str
in_layout bool
label object
linestyle {’-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …}
linewidth float

參考鏈接:plt.plot()官網傳送門

代碼實例

import matplotlib.pyplot as plt

a = [1, 2, 3, 4] # y 是 a的值,x是各個元素的索引
b = [5, 6, 7, 8]

plt.plot(a, b, 'r--', label = 'aa')
plt.xlabel('this is x')
plt.ylabel('this is y')
plt.title('this is a demo')
plt.legend() # 將樣例顯示出來

plt.plot()
plt.show()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章