1. 程式人生 > >python繪製散點圖並標記序號

python繪製散點圖並標記序號

實現二維平面上散點的繪製,並可以給每個散點標記序號或者名稱:

import numpy as np
import matplotlib.pyplot as plt


x=[2.3,4.5,3,7,6.5,4,5.3]
y=[5,4,7,5,5.3,5.5,6.2]
n=np.arange(7)


fig,ax=plt.subplots()
ax.scatter(x,y,c='r')


for i,txt in enumerate(n):
    ax.annotate(txt,(x[i],y[i]))