Python 如何绘制圆,Python绘制圆(超棒!!)

源自: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

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怎用点画一个黑圆

用到Image, ImageDraw模块

代码如下
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')

  • 8
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值