繁体   English   中英

散点对坐标的 plot,用 pandas DataFrame 标签的索引名称注释

[英]Scatter plot of pair coordinates, annotated with pandas DataFrame index name for labels

For a two-column pandas DataFrame, whose rows contain a pair of two values that belong to one another as xy coordinates, how can a 2D plot be generated such that each pair of coordinates are given an annotated text label equal to the index name for那一排?

在此处输入图像描述

例如,坐标 ( 0.983801 , 0.0155373 ) 应在 plot 中显示为单个点,并使用AXP进行注释。 与其余行类似,每个行都唯一命名

DataFrame 由两个一维 numpy arrays ab构造而成,而标签是两者长度相等的列表:

#columns labeled on next line since the transpose of index arg is columns
df = pd.DataFrame(np.vstack((a,b)),index=['pe','jsc']).T 
df.index = labels #row labels

尝试这样的事情:

# sample data
df = pd.DataFrame(np.random.rand(4,2), columns=['pe','jsc'], index=list('abcd'))

plt.scatter(df['pe'], df['jsc'])
for idx, row in df.iterrows(): 
    plt.text(row['pe'], row['jsc'], idx)

Output:

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM