python-matplotlib库画矩形

matplotlib库画矩形


这样可以很清晰的看到各个参数是怎样控制作图的

import matplotlib.pyplot as plt
if __name__ == "__main__":
    fig1 = plt.figure()
    ax1 = fig1.add_subplot(111)
    rect=plt.Rectangle(
            (1, 2),  # (x,y)矩形左下角
            3,  # width长
            4,  # height宽
            color='maroon', 
            alpha=0.5      )
    ax1.add_patch(rect)
    plt.xlim(-1, 6)
    plt.ylim(1, 7)
    plt.show()
    plt.savefig("1.png")

python-matplotlib库画矩形_第1张图片

你可能感兴趣的:(python相关,python)