源自:http://www.bkjia.com/ASPjc/892396.html
-------------------------------------------------------------------------
http://blog.csdn.net/pipisorry/article/details/40005163
1. 调用包函数绘制圆形Circle和椭圆Ellipse
################################### # coding=utf-8 # !/usr/bin/env python # __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)
p631class matplotlib.patches.Ellipse(xy, width, height, angle=0.0, **kwargs)Bases: matplotlib.patches.PatchA scale-free ellipse.xy center of ellipsewidth total length (diameter) of horizontal axisheight total length (diameter) of vertical axisangle rotation in degrees (anti-clockwise)p626class 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. 直接绘制
#coding=utf-8 ''' Created on Jul 14, 2014 @author: pipi ''' from math import pi from numpy import cos, sin from matplotlib import pyplot as plt if __name__ == '__main__': '''plot data margin''' angles_circle = [i*pi/180 for i in range(0,360)] #i先转换成double #angles_circle = [i/np.pi for i in np.arange(0,360)] # <=> # angles_circle = [i/180*pi for i in np.arange(0,360)] X x = cos(angles_circle) y = sin(angles_circle) plt.plot(x, y, 'r') plt.axis('equal') plt.axis('scaled') plt.show()
from:http://blog.csdn.net/pipisorry/article/details/40005163
ref:http://www.zhihu.com/question/25273956/answer/30466961?group_id=897309766#comment-61590570
# coding=utf-8
python 怎画圆
import mathtry: import matplotlib.pyplot as pltexcept: raisedef circle(x,y,r):xarr=[]yarr=[]for i in range(20):jiao=float(i)/20*2*math.pix1=x+r*math.cos(jiao)y1=y+r*math.sin(jiao)xarr.append(x1)yarr.append(y1)print xarrprint yarrplt.plot(xarr,yarr,linestyle='-', marker='o', color='r',markersize=10)plt.show() # displaycircle(5,5,5)
python怎用点画一个黑圆
代码如下
import Image, ImageDrawimage = Image.new('RGBA', (200, 200))draw = ImageDraw.Draw(image)draw.ellipse((20, 180, 180, 20), fill = 'blue', outline ='blue')#draw.ellipse((20, 20, 180, 180), fill = 'black', outline ='black')draw.point((100, 100), 'red')image.save('test.png')