gpt4 book ai didi

python - 仅在 matplotlib 中绘制带边框的矩形

转载 作者:IT老高 更新时间:2023-10-28 22:25:29 27 4
gpt4 key购买 nike

于是我找到了以下代码 here :

from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle
someX, someY = 0.5, 0.5
plt.figure()
currentAxis = plt.gca()
currentAxis.add_patch(Rectangle((someX - .1, someY - .1), 0.2, 0.2,alpha=1))
plt.show()

这给出了: enter image description here

但我想要的是一个只有蓝色边框且内部透明的矩形。我该怎么做?

最佳答案

您只需要将 facecolor 设置为字符串 'none'(不是 python None)

from matplotlib import pyplot as plt
from matplotlib.patches import Rectangle
someX, someY = 0.5, 0.5
fig,ax = plt.subplots()
currentAxis = plt.gca()
currentAxis.add_patch(Rectangle((someX - 0.1, someY - 0.1), 0.2, 0.2,
alpha=1, facecolor='none'))

关于python - 仅在 matplotlib 中绘制带边框的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21445005/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com