如何在窗口坐标内插入带有数字的圆? [英] How insert a circle with a number in it within the window coordinate?

查看:135
本文介绍了如何在窗口坐标内插入带有数字的圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个这样的人物:

I would like to make this kind of figure :

但是我不知道如何创建带有文本的圆. 我希望根据窗口而不是轴来放置圆.我找到的所有示例都根据轴的坐标放置了圆,但是我希望在窗口上有一个坐标.例如X方向为0.2,Y方向为0.9 现在我有了这段代码:

But I don't know how I can create the circle with a text in it. I would like the circle to be place according to the window instead of the axis. All example I found place the circle according to coordinate of the axis but I would like to have a coordinate base on the window. like at 0.2 for X direction and 0.9 for Y direction For now I have this code :

import matplotlib.pyplot as plt
import numpy as np


t=np.arange(0,10,0.01)
y1=np.sin(2*3.14*10*t)

plt.figure(1)
plt.subplots_adjust(hspace=0.01)
plt.subplot(211)
plt.plot(t,y1)

# create the circle with black border and grey fill, and the text 1 in it
plt.show()

推荐答案

在图形坐标中创建注释或文本的选项有三项:

Three out of many options to create an annotation or text in figure coordinates:

plt.annotate("1",(0.2,0.9), xycoords="figure fraction",
             bbox={"boxstyle" : "circle", "color":"grey"})

  • 使用 figtext 来创建文本

  • Use figtext to create your text.

    plt.figtext(0.2,0.9,"1",
                bbox={"boxstyle" : "circle", "color":"grey"})
    

  • 指定要用于通常 text :

  • Specify the transform to use for the usual text:

    plt.text(0.2,0.9,"1", transform=plt.gcf().transFigure,
             bbox={"boxstyle" : "circle", "color":"grey"})
    

  • 这篇关于如何在窗口坐标内插入带有数字的圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆