首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Label inset_axes散点图

Label inset_axes散点图
EN

Stack Overflow用户
提问于 2021-01-16 11:25:35
回答 1查看 52关注 0票数 0

我想通过对散点图中的散点标记进行编号来标记它们,但是我不知道如何获得inset_axes坐标来放置标签。

代码语言:javascript
复制
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
ax.plot(range(10))

x = np.random.rand(5)
y = np.random.rand(5)
labels = [str(num+1) for num in range(len(x))]

axin2 = ax.inset_axes(
    [5, 7, 2.3, 2.3], transform=ax.transData)
axin2.scatter(x, y)
plt.show()
EN

回答 1

Stack Overflow用户

发布于 2021-01-16 17:58:41

我对这种类型的图形没有太多的经验,但我认为我可以使用我已经设置的散点图的坐标并对其进行注释。

代码语言:javascript
复制
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(2021)
fig, ax = plt.subplots(figsize=(12,9))
ax.plot(range(10))

x = np.random.rand(5)
y = np.random.rand(5)
labels = [str(num+1) for num in range(len(x))]

axin2 = ax.inset_axes(
    [5, 7, 2.3, 2.3], transform=ax.transData)
axin2.scatter(x, y)

for i in range(len(x)):
    axin2.annotate(str(i), xy=(x[i]+0.02,y[i]))
inset = axin2.transData
# print(inset)
plt.show()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65746183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档