python matplotlib draw shapes (rectangles, circles, etc.)

B station video: https:? // p = 6

Transfer: https: //

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpathes

fig,ax = plt.subplots()
xy1 = np.array([0.2,0.2])
xy2 = np.array([0.2,0.8])
xy3 = np.array([0.8,0.2])
xy4 = np.array([0.8,0.8])
circle = mpathes.Circle(xy1,0.05)
rect = mpathes.Rectangle(xy2,0.2,0.1,color='r')
polygon = mpathes.RegularPolygon(xy3,5,0.1,color='g')
ellipse = mpathes.Ellipse(xy4,0.4,0.2,color='y')

  • Correlation function introduction
    • Circle()
      • Documentation: https: //
      • Summary: xy of a given radius to create a true circle = (x, y) at
      • Attributes
        • xy: circular central (property name can be omitted)
        • redius: radius of the circle (property name can be omitted)
        • For more detailed document attributes
      • common problem
    • Rectangle()
      • Documentation:
      • Introduction: the x, y coordinates to generate a rectangular, (x, y position is the lower left corner of the rectangle)
      • Attributes
        • xy: a rectangular bottom and left coordinate (property name can be omitted)
        • width: rectangle width (attribute name can be omitted, the height and width of the order noted, the second wide)
        • height: the height of the rectangle (property name can be omitted, note that the height and width of the order, the third high)
        • color: fill color
        • For more detailed document attributes
    • RegularPolygon()
    • Ellipse()
    • add_patch()

Guess you like