Matplotlib.patches.CirclePolygon类

Matplotlib.patches.CirclePolygon类

Python matplotlib.patches.CirclePolygon类用于圆patch的多边形近似。它用于在xy = (x, y)处作一个半径为已知的圆。有分辨边的正多边形近似用这个圆表示。

语法:

matplotlib.patches.CirclePolygon(xy, radius=5, resolution=20, **kwargs)

参数:

  • xy:待画圆的原点坐标。
  • radius:这是一个可选参数,用于设置圆的半径。
  • resolution:顾名思义,它用于设置图像分辨率。它是可选的,默认为20。

示例1

import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon
  
  
circle = CirclePolygon((0, 0), 
                       radius = 0.75,
                       fc = 'y')
  
plt.gca().add_patch(circle)
  
verts = circle.get_path().vertices
trans = circle.get_patch_transform()
points = trans.transform(verts)
  
plt.plot(points[:, 0], points[:, 1])
plt.axis('scaled')
  
plt.show()

输出:

Matplotlib.patches.CirclePolygon类

示例2

import numpy as np
import matplotlib
from matplotlib.patches import Circle, Wedge, Polygon, Ellipse
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
import matplotlib.patches as matpatches
  
  
fig, ax = plt.subplots(figsize =(8, 8))
patches = []
  
  
circle = Circle((2, 2), 2)
patches.append(circle)
  
  
  
polygon = matpatches.PathPatch(patches[0].get_path())
patches.append(polygon)
  
  
colors = 2 * np.random.rand(len(patches))
p = PatchCollection(patches, 
                    cmap = matplotlib.cm.jet,
                    alpha = 0.4)
  
p.set_array(np.array(colors))
ax.add_collection(p)
  
plt.axis([-10, 10, -10, 10])
  
plt.show()

输出:

Matplotlib.patches.CirclePolygon类

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程