B station video: https:? //Www.bilibili.com/video/av6989413/ p = 6
Transfer: https: //www.cnblogs.com/linblogs/p/9672769.html
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) ax.add_patch(circle) #长方形 rect = mpathes.Rectangle(xy2,0.2,0.1,color='r') ax.add_patch(rect) #多边形 polygon = mpathes.RegularPolygon(xy3,5,0.1,color='g') ax.add_patch(polygon) #椭圆形 ellipse = mpathes.Ellipse(xy4,0.4,0.2,color='y') ax.add_patch(ellipse) plt.axis('equal') plt.grid() plt.show()
- Correlation function introduction
- Circle()
- Documentation: https: //matplotlib.org/api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle
- 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
- Question: painted circular is not a perfect circle, oval
- Reason: when the drawing because the x, y-axis ratio is not 1: 1
- Solution: Use axis property set function 'equal', is set equal to the scaling limit by changing shaft
- axis Documents: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis
- Rectangle()
- Documentation: https://matplotlib.org/api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle
- 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()
- Documentation: https://matplotlib.org/api/_as_gen/matplotlib.patches.RegularPolygon.html#matplotlib.patches.RegularPolygon
- Introduction: The x, y coordinates generated polygons
- Attributes
- xy: center of the polygon (property name can be omitted)
- numVertices: the number of vertices, or may be called the number of edges (attribute name may be omitted, note position)
- redus: Polygon radius (attribute name may be omitted, note position)
- color: fill color
- For more detailed document attributes
- Ellipse()
- Documentation: https://matplotlib.org/api/_as_gen/matplotlib.patches.Ellipse.html#matplotlib.patches.Ellipse
- Description: to generate an oval centered xy
- Attributes
- xy: center of the ellipse
- width: total length of the horizontal axis, (a diameter)
- height: The total length of the vertical axis (diameter)
- For more detailed document attributes
- add_patch()
- Documentation: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.add_patch.html#matplotlib.axes.Axes.add_patch
- Introduction: creating a pattern drawn on the canvas,
- Attributes
- p: To add a pattern (that is, the return value when creating the pattern)
- Circle()