温馨提示×

使用Rectangle函数怎么去边框

小亿
91
2023-08-04 09:14:19
栏目: 编程语言

要去掉Rectangle函数绘制的边框,可以通过设置边框的颜色为透明来实现。具体步骤如下:

  1. 导入绘图库
import matplotlib.pyplot as plt
  1. 创建一个矩形对象并设置边框颜色为透明
rect = plt.Rectangle((x, y), width, height, edgecolor='none')
  1. 将矩形对象添加到图形中
plt.gca().add_patch(rect)
  1. 显示图形
plt.show()

完整代码示例:

import matplotlib.pyplot as plt
x = 0  # 矩形左下角 x 坐标
y = 0  # 矩形左下角 y 坐标
width = 5  # 矩形宽度
height = 3  # 矩形高度
rect = plt.Rectangle((x, y), width, height, edgecolor='none')
plt.gca().add_patch(rect)
plt.show()

这样就可以绘制一个没有边框的矩形图形。

0