matplotlib画圆
时间: 2023-11-20 15:58:26 浏览: 71
以下是两种使用matplotlib画圆的例子:
1.使用Ellipse函数画圆
```python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse
delta = 45.0 # degrees
angles = np.arange(0, 360 + delta, delta)
ells = [Ellipse((1, 1), 4, 2, a) for a in angles]
fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'})
for e in ells:
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(0.6)
e.set_facecolor(np.random.rand(3))
plt.xlim(-2, 6)
plt.ylim(-1, 4)
plt.show()
```
2.使用sin和cos函数画圆
```python
import matplotlib.pyplot as plt
import numpy as np
x, y = 0, 0
r = 1
a_x = np.arange(0, 2*np.pi, 0.01)
a = x + r*np.cos(a_x)
b = y + r*np.sin(a_x)
plt.plot(a, b, color='r', linestyle='-')
plt.plot(a, -b, color='r', linestyle='-')
plt.axis('equal')
plt.show()
```
阅读全文