当前位置:   article > 正文

[python plt画矩形]

python plt画矩形
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. def rec(ax, b1, b2, show_point=True, show_loc=True):
  4. xmin,xmax = min(b1[0], b2[0]), max(b1[0], b2[0])
  5. ymin,ymax = min(b1[1], b2[1]), max(b1[1], b2[1])
  6. # 1
  7. # ax.arrow(xmin, ymin, xmax-xmin,0)
  8. # ax.arrow(xmin, ymin, 0,ymax-ymin)
  9. # ax.arrow(xmax, ymax, xmin-xmax, 0)
  10. # ax.arrow(xmax, ymax, 0, ymin- ymax)
  11. # 2
  12. ax.hlines([ymin, ymax],[xmin, xmin], [xmax, xmax], colors='black')
  13. ax.vlines([xmin, xmax],[ymin, ymin], [ymax, ymax], colors='black')
  14. xs,ys = np.meshgrid([xmin, xmax],[ymin,ymax])
  15. if show_point:
  16. ax.scatter(xs,ys)
  17. if show_loc:
  18. for x,y in zip(xs.flatten(),ys.flatten()):
  19. ax.text(x,y,f'({x}, {y})', fontdict={'c':'r'})
  20. # [x,y],[x,y]
  21. rec(plt, [1,2], [3,4], False, False)
  22. rec(plt, [6,9], [4,9])
  23. plt.show()

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/742934
推荐阅读
相关标签
  

闽ICP备14008679号