.annotate() 没有绘制所有标签

.annotate() is not plotting all labels

我创建了一个包含股票信息的数据框。当我去创建散点图和注释标签时,并不是所有的标签都包括在内。在 50 分左右的分数中,我只得到 3 个标签。我不明白为什么它没有绘制所有标签。

我的Table:

        Dividend  ExpenseRatio  Net_Assets  PriceEarnings  PriceSales
Ticker
FHLC      0.0128          0.08       6.056          22.95        1.78
ONEQ      0.0083          0.21       6.284          20.24        2.26
FTEC      0.0143          0.08       3.909          20.83        2.73
FDIS      0.0144          0.08       2.227          20.17        1.36
FENY      0.0262          0.08       4.386          25.97        1.34

我的绘图代码:

for ticker,row in df.iterrows():    
    plt.scatter(row['PriceSales'], row['PriceEarnings'], c = np.random.rand(3,1), s = 300)


for i, txt in enumerate(ticker):
    plt.annotate(df.index[i-1], (df.PriceSales[i-1], df.PriceEarnings[i-1]))

plt.xlabel('PriceSales')
plt.ylabel('PriceEarnings')  
plt.show() 

我的图表图像:

此处的ticker将具有最后一行的ticker的值;例如,"FENY"。当您调用 enumerate(ticker) 时,它将为每个字符生成一个项目,因此听起来您的最后一个代码有 3 个条目。

我认为你可以在与散点图相同的循环中注释点:

for ticker,row in df.iterrows():    
    plt.scatter(row['PriceSales'], row['PriceEarnings'], c = np.random.rand(3,1), s = 300)
    plt.annotate(ticker, (row['PriceSales'], row['PriceEarnings']))