簡體   English   中英

Matplotlib Scatter圖以numpy行索引作為標記

[英]Matplotlib Scatter plot with numpy row index as marker

我有一個numpy數組,我正在嘗試使用matplotlib繪制散點圖。

from matplotlib import pyplot as plt
from matplotlib import pylab as pl

pl.plot(matrix[:,0],matrix[:,1], 'ro')

這給了我類似的東西: 情節

現在我想用與numpy數組中行的索引相對應的數字替換紅點。 我怎么能這樣做?

謝謝 !

您可以使用plt.text執行此操作:

from matplotlib import pyplot as plt

import numpy as np
N = 100
matrix = np.random.rand(N,2)

plt.plot(matrix[:,0],matrix[:,1], 'ro', alpha = 0.5)
for i in range(matrix.shape[0]):
    plt.text(matrix[i,0], matrix[i,1], str(i))

plt.show()

在此輸入圖像描述

如果要替換紅點,則設置alpha = 0.0

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM