赞
踩
- import matplotlib.pyplot as plt
- import numpy as np
-
- def rec(ax, b1, b2, show_point=True, show_loc=True):
- xmin,xmax = min(b1[0], b2[0]), max(b1[0], b2[0])
- ymin,ymax = min(b1[1], b2[1]), max(b1[1], b2[1])
-
- # 1
- # ax.arrow(xmin, ymin, xmax-xmin,0)
- # ax.arrow(xmin, ymin, 0,ymax-ymin)
- # ax.arrow(xmax, ymax, xmin-xmax, 0)
- # ax.arrow(xmax, ymax, 0, ymin- ymax)
-
- # 2
- ax.hlines([ymin, ymax],[xmin, xmin], [xmax, xmax], colors='black')
- ax.vlines([xmin, xmax],[ymin, ymin], [ymax, ymax], colors='black')
-
- xs,ys = np.meshgrid([xmin, xmax],[ymin,ymax])
-
- if show_point:
- ax.scatter(xs,ys)
-
- if show_loc:
- for x,y in zip(xs.flatten(),ys.flatten()):
- ax.text(x,y,f'({x}, {y})', fontdict={'c':'r'})
-
- # [x,y],[x,y]
- rec(plt, [1,2], [3,4], False, False)
- rec(plt, [6,9], [4,9])
- plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。