首页 > 代码库 > Python 如何绘制圆

Python 如何绘制圆

http://blog.csdn.net/pipisorry/article/details/40005163

1. 调用包函数绘制圆形Circle和椭圆Ellipse

###################################
#   !/usr/bin/env python
#   coding=utf-8
#   __author__ = 'pipi'
#   ctime 2014.10.11
#   绘制椭圆和圆形
###################################
from matplotlib.patches import Ellipse, Circle
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

ell1 = Ellipse(xy = (0.0, 0.0), width = 4, height = 8, angle = 30.0, facecolor= 'yellow', alpha=0.3)
cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)
ax.add_patch(ell1)
ax.add_patch(cir1)

x, y = 0, 0
ax.plot(x, y, 'ro')

plt.axis('scaled')
# ax.set_xlim(-4, 4)
# ax.set_ylim(-4, 4)
plt.axis('equal')   #changes limits of x or y axis so that equal increments of x and y have the same length

plt.show()
参见Matplotlib.pdf Release 1.3.1文档

p187

18.7 Ellipses (see arc)


p631
class matplotlib.patches.Ellipse(xy, width, height, angle=0.0, **kwargs)
Bases: matplotlib.patches.Patch
A scale-free ellipse.
xy center of ellipse
width total length (diameter) of horizontal axis
height total length (diameter) of vertical axis
angle rotation in degrees (anti-clockwise)

p626
class matplotlib.patches.Circle(xy, radius=5, **kwargs)


或者参见Matplotlib.pdf Release 1.3.1文档contour绘制圆

#coding=utf-8
import numpy as np
import matplotlib.pyplot as plt

x = y = np.arange(-4, 4, 0.1)
x, y = np.meshgrid(x,y)
plt.contour(x, y, x**2 + y**2, [9])     #x**2 + y**2 = 9 的圆形

plt.axis('scaled')
plt.show()
p478
Axes3D.contour(X, Y, Z, *args, **kwargs)
Create a 3D contour plot.
Argument Description
X, Y, Data values as numpy.arrays
Z
extend3d
stride
zdir
offset
Whether to extend contour in 3D (default: False)
Stride (step size) for extending contour
The direction to use: x, y or z (default)
If specified plot a projection of the contour lines on this position in plane normal to zdir
The positional and other


p1025

matplotlib.pyplot.axis(*v, **kwargs)
Convenience method to get or set axis properties.



或者参见demo

【pylab_examples example code: ellipse_demo.py】



2. 直接绘制



from:http://blog.csdn.net/pipisorry/article/details/40005163

ref:http://www.zhihu.com/question/25273956/answer/30466961?group_id=897309766#comment-61590570



Python 如何绘制圆