How to draw circles in Python and draw circles in Python
Http://blog.csdn.net/pipisorry/article/details/40005163
1. Call the Package function to draw a circular Circle and an elliptical Ellipse
#################################### Coding = UTF-8 #! /Usr/bin/env python # _ author _ = 'pipi' # ctime 2014.10.11 # draw an ellipse and a circle ############### ################### from matplotlib. patches import Ellipse, Circleimport matplotlib. pyplot as pltfig = 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, 0ax. 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 lengthplt. show ()
See matplotlib.pdf Release 1.3.1.
P187
18.7Ellipses(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)
See matplotlib.pdf Release 1.3.1 document contour circle
# Coding = utf-8import numpy as npimport matplotlib. pyplot as pltx = y = np. arange (-4, 4, 0.1) x, y = np. meshgrid (x, y) plt. contour (x, y, x ** 2 + y ** 2, [9]) # circular plt of x ** 2 + y ** 2 = 9. 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.
Or refer to the demo
[Pylab_examples example code: ellipse_demo.py]
2. Draw directly
# Coding = UTF-8 ''' Created on Jul 14,201 4 @ author: pipi ''' from math import pifrom numpy import cos, sinfrom matplotlib import pyplot as pltif _ name _ = '_ main __': '''plot data margin ''' angles_circle = [I * pi/180 for I in range (0,360)] # I first converts it to 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
How to draw circles in 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)
How does python draw a black circle with dots?
Image and ImageDraw modules
The Code is as follows:
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'your image.save('test.png ')