matplotlib中plt.scatter()與plt.plot()參數詳解

scatter繪製散點,plot繪製經過點的曲線

scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None,edgecolors=None, hold=None, data=None, **kwargs)

x,y:輸入數據,array_like,shape(n,)
s:點的大小
  標量或array_like,shape(n,),可選大小以點數^ 2。默認是rcParams ['lines.markersize'] ** 2
c:點的顏色
  順序或顏色順序,可選,默認:‘b’ c可以是單個顏色格式的字符串,也可以是一系列顏色 規範的長度爲N,或一系列N數字 使用通過kwargs指定的cmapnorm映射到顏色(見下文)。請注意,c不應該是單個數字RGB或RGBA序列,因爲這與數組無法區分值將被彩色映射。 c可以是一個二維數組,其中的行是RGB或RGBA,但是,包括單個的情況行爲所有點指定相同的顏色。
marker:點的形狀  
    〜matplotlib.markers.MarkerStyle,可選,默認值:‘o’ 請參閱〜matplotlib.markers以獲取有關不同的更多信息標記分散支持的樣式。 marker可以是該類的實例或特定文本的簡寫
標記。
cmap〜matplotlib.colors.Colormap,可選,默認:無 一個〜matplotlib.colors.Colormap實例或註冊名稱。cmap僅在c是浮點數組時使用。如果沒有,默認爲rcimage.cmap
norm〜matplotlib.colors.Normalize,可選,默認:無 〜matplotlib.colors.Normalize實例用於縮放亮度數據爲0,1。norm只有在c是一個數組時才被使用 彩車。如果None',則使用默認值:func:normalize。 **vmin**,vmax:標量,可選,默認值:無vminvmaxnorm結合使用來標準化亮度數據。如果其中任何一個都是無’,那麼最小和最大的 使用顏色數組。請注意,如果你通過一個“規範”實例,你的vminvmax的設置將被忽略。
alpha:標量,可選,默認值:無 alpha混合值,介於0(透明)和1(不透明)之間,
linewidths:標量或array_like,可選,默認值:無 如果無,則默認爲(lines.linewidth,)。
verts:(x,y)的序列,可選 如果marker爲None,這些頂點將用於 構建標記。標記的中心位於在(0,0)爲標準化單位。整體標記重新調整 由s完成。
edgecolors :顏色或顏色順序,可選,默認值:無如果無,則默認爲’face’

如果’face’,邊緣顏色將永遠是相同的顏色。 如果它是’none’,補丁邊界不會 被畫下來。對於未填充的標記,“edgecolors” kwarg 被忽視並被迫在內部“面對”。

備註:
1.點的形狀marker參數如下
在這裏插入圖片描述

2.點的顏色c參數如下:
在這裏插入圖片描述

plt.plot()

plt.plot() 參數介紹:

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的索引。那麼我的問題就解決了。
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。
**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’)

擁有的部分參數,如下:
在這裏插入圖片描述
在這裏插入圖片描述

代碼實例

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()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章