# -*- coding:utf-8 -*- # @Author len # @Create 2023/12/31 11:15 import matplotlib.pyplot as plt def draw_trapezoid(color='blue'): # 创建一个新的图形和轴,设置背景为透明 fig, ax = plt.subplots(figsize=(5, 5), dpi=80) fig.patch.set_alpha(0.0) # 定义梯形的四个顶点 points = [[0.2, 0.2], [0.8, 0.2], [0.6, 0.8], [0.4, 0.8]] # 绘制梯形,颜色为指定颜色 trapezoid = plt.Polygon(points, closed=True, color=color) ax.add_patch(trapezoid) # 设置坐标轴的范围 ax.set_xlim(0, 1) ax.set_ylim(0, 1) # 移除坐标轴 ax.axis('off') # 保存图像为PNG格式,背景设为透明 plt.savefig('trapezoid.png', transparent=True, bbox_inches='tight', pad_inches=0) # 显示图像 plt.show() # 调用函数并传入您选择的颜色 draw_trapezoid(color='blue')