從 Pandas 資料框繪製時註釋資料點
要在從 Pandas 資料框繪製時註釋資料點,我們可以執行以下步驟 -
使用 DataFrame 建立 df,其帶有 x、y 和索引鍵。
使用 subplots() 方法建立一個圖形和一組子圖。
使用plot() 方法、kind='scatter'、ax=ax、c='red' 和 marker='x' 繪製一系列資料框。
要使用索引值註釋散點,請迭代資料框。
要顯示圖形,請使用 show() 方法。
示例
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import string
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
df = pd.DataFrame({'x': np.random.rand(10), 'y': np.random.rand(10)}, index=list(string.ascii_lowercase[:10]))
fig, ax = plt.subplots()
df.plot('x', 'y', kind='scatter', ax=ax, c='red', marker='x')
for k, v in df.iterrows():
ax.annotate(k, v)
plt.show()輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP