如何在 Matplotlib 中先繪製線條,最後繪製點?
若要先繪製線條,最後繪製點,我們可以採取以下步驟 -
使用 numpy 建立 x 點、y1 點和 y2 點,繪製線條。
使用 plot() 方法和 x、y1 和 y2 點繪製曲線。
使用 scatter 方法繪製散點。
使用 show() 方法顯示圖形。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xpoints = np.linspace(1, 1.5, 10) y1points = np.log(xpoints) y2points = np.exp(xpoints) plt.plot(xpoints, y1points) plt.plot(xpoints, y2points) for i in xpoints: plt.scatter(i, np.random.randint(10)) plt.show()
輸出

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongDO 資料庫
MySQL
Javascript
PHP