1

I have points that represent a bounding box in a plot. I want to connect these points in order to make a box.

What I have:

import matplotlib.pyplot as plt
import numpy as np

coords = np.random.uniform(0, 10, (4, 2))

fig, ax = plt.subplots(figsize=(4, 4))
ax.scatter(*zip(*coords))
ax.plot(*zip(*coords), color='orange')
plt.show()

enter image description here

What I want:

enter image description here

Notes

All my coordinates form a perfect rectangle, that is always randomly rotated. I just don't know how to replicate that in a reproducible example.

I believe that the question proposed as duplicate doesn't answer my question. For one, it deals with rectangles.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
  • Append your first coordinate to the end of you coordinate list before plotting. This will make the connection between the dots cyclic. – BramAppel Feb 12 '20 at 19:05
  • Use `convexHull` to get this done: https://stackoverflow.com/questions/36763853/plotting-a-set-of-given-points-to-form-a-closed-curve-in-matplotlib – SKPS Feb 13 '20 at 04:27

0 Answers0