Seaborn怎么支持圖表注釋和標(biāo)簽

小億
103
2024-05-17 15:56:16

Seaborn 可以通過(guò) annotatetext 方法支持圖表注釋和標(biāo)簽。

  1. annotate 方法用于添加注釋,語(yǔ)法如下:
import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x='x', y='y', data=data)
plt.annotate('Annotation text', xy=(x_coord, y_coord), xytext=(x_text, y_text), 
             arrowprops=dict(facecolor='black', shrink=0.05))
plt.show()
  1. text 方法用于添加文本標(biāo)簽,語(yǔ)法如下:
import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x='x', y='y', data=data)
plt.text(x_coord, y_coord, 'Label text', fontsize=12)
plt.show()

這樣就可以在 Seaborn 生成的圖表上添加注釋和標(biāo)簽。

0