Matplotlib Library
Official http://matplotlib.org/
Sample http://matplotlib.org/gallery.html
Document http://matplotlib.org/contents.html
Quick Start http://azaleasays.com/2010/04/27/matplotlib-beginner-guide/
Http://wenku.baidu.com/view/1f575c649b6648d7c1c74682.html
Installation Method: yum install python-matplotlib
Or
Easy_install matplotlib
Or install it from the source code.
Python setup. py build
Python setup. py install
The latter two methods may encounter errors that lack freetype packages and libpng packages. Use yum to install these dependency packages.
Applicability: two-dimensional and three-dimensional data reports
Python Imaging Library
Official http://www.pythonware.com/products/pil/
Manual http://www.pythonware.com/library/pil/handbook/introduction.htm
Image class
[Read | write]
Open the Image im = Image. open ('/tmp/Image.png ')
Read im = Image. open ('/tmp/Image.png', 'rb') from the opened file '))
Read im = Image. open (StringIO. StringIO (buffer) from a string ))
Read im = Image.open(TarIO.TarIO('Imaging.tar ', 'imaging/test/lena. ppm') from the tar archive '))
Image Information im. format, im. size, im. mode
Show image im. show ()
Save the image im. save ('/tmp/newImage.png ')
Thumbnail im. thumbnail (length, width ))
Im. save ('filename', 'jpeg ')
[Cutting | sticking | splitting | and]
Cut region = im. crop (startX, startY, endX, endY ))
Rotate region = region. transpose (Image. ROTATE_180)
Paste im. paste (region, (leftX, upperY, rightX, lowerY ))
Break down rtList = im. split ()
Merge im = Image. merge ('rgb ', (rtList [0], rtList [1], rtList [2])
[Ry conversion]
Change the size newIm = im. resize (128,128 ))
Rotate 45 ° newIm = im. rotate (45) counterclockwise)
Horizontal Axis flip newIm = im. transpose (Image. FLIP_LEFT_RIGHT)
Vertical Axis flip newIm = im. transpose (Image. FLIP_TOP_BOTTOM)
Rotate 90 ° newIm = im. transpose (Image. ROTATE_90) counterclockwise)
Rotate 180 ° newIm = im. transpose (Image. ROTATE_180) counterclockwise)
Rotate 270 ° newIm = im. transpose (Image. ROTATE_270) counterclockwise)
[Color conversion]
Color Changing newIm = im. convert ('l') # ('l'/'rgb '/other, the other must be transitioned to 'rgb)
[Image Enhancement]
Filter enhancement newIm = im. filter (ImageFilter. DETAIL) # The ImageFilter. DETAIL effect is not displayed. Other pre-defined enhancement filters in ImageFilter have not been tried.
Pixel enhancement newIm = im. point (lambda I: I * 1.2) # You can team up with paste
Image Enhancement enh = ImageEnhance. Contrast (im) # object used for im Contrast (ImageEnhance also contains objects with brightness and sharp sharpness)
NewIm = enh. enhance (3)
[Image queue]
Process a dynamic graph gifIm = Image.open('debug.gif ')
Im1 = gifIm
GifIm. seek (1) # Jump to the second frame (through the exception EOFError capture to determine whether to reach the last frame)
Im2 = gifIm
ImageDraw Module: Drawing (coordinate origin: positive direction of the X axis in the upper left corner of the image: horizontal to the right Y axis positive direction: vertical downward)
Arc drawobj. ARC (xy, start, end, options)
Bitmap drawobj. Bitmap (xy, bitmap, optiosn)
String drawobj. Chord (xy, start, end, options)
(Elliptical) circle drawobj. ellipse (xy, options) (This function fill option sets the internal color, outline is the boundary color, the first parameter (startx, starty, endx, Endy) the two vertices in are the upper left corner and the lower right corner of the rectangle, and the ellipse is formed in the rectangle)
Straight line drawobj. Line (xy, options)
Did not try drawobj. pieslice (xy, start, end, options)
Click drawobj. Point (xy, options)
Polygon drawobj. polygon (xy, options)
Rectangular drawobj. rectangle (box, options)
Text drawobj. Text (Position, String, options) (position is the upper left corner of the string, you can adjust the size of the text returned by drawobj. textsize (string, options) positoin)
#encoding=utf-8import Image, ImageDraw, sys, pprintif __name__ == '__main__': im = Image.new('L', (400,400), 255) draw = ImageDraw.Draw(im) draw.line((0,0,400,400),fill=0) draw.line((0,400,400,0),fill=0) draw.ellipse((0,0,25,25), outline=0) draw.ellipse((375,375,400,400), outline = 0) draw.ellipse((200,200,300,300), outline = 0) draw.ellipse((0,350,25,400), outline = 128) textStr = 'hello,pil!' textSize = draw.textsize(textStr) draw.text((200-textSize[0]/2.0,200-textSize[1]/2.0),textStr,fill=128) im.save('/tmp/PIL.jpg')
Mode-Gray Scale "L", color "rgba" "RGB", etc.
1 (1-bit pixels, black and white, stored with one pixel per byte)
L (8-bit pixels, black and white)
P (8-bit pixels, mapped to any other mode using a color palette)
RGB (3x8-bit pixels, true color)
RGBA (4x8-bit pixels, true color with transparency mask)
CMYK (4x8-bit pixels, color separation)
YCbCr (3x8-bit pixels, color video format)
I (32-bit integer pixels)
F (32-bit floating point pixels)
Color-Specified as 32bit value, tuple, or string
MyColor = (255, 0, 0,128) # full red, with 50% alpha
Mycolor = 0x7f0000ff # full red, with 50% alpha
Mycolor = "#00ff00" # web color
Mycolor = "RGB (75%, 0%, 0% )"
Mycolor = "HSL (0,100%, 50% )"
RGB color query http://www.wescn.com/tool/color_3.html
The following two geometric functions are difficult to write, and almost all the mathematical knowledge is returned to the teacher...
Def LineCrossCircleV1 (centerPos, r, k ): '''tmpv = math. sqrt (r ** 2/(1 + k ** 2) rtX1 = centerPos [0] + tmpVrtY1 = k * (rtX1-centerPos [0]) + centerPos [1] rtX2 = centerPos [0]-tmpV rtY2 = k * (rtX2-centerPos [0]) + centerPos [1] return (rtX1, rtY1), (rtX2, rtY2) def LineCrossCircleV2 (centerPos, r, linePos, k ): ''' calculates the intersection of [circle with centerPos as the center, circle with r as the radius] and [line with k as the slope through linePos] ''' k = float (k) r = float (r) x0, y0 = float (centerPos [0]), float (centerPos [1]) x1, y1 = float (linePos [0]), float (linePos [1]) # a * x ** 2 + B * x + c = 0a = k ** 2 + 1b = 2 * k * (y1-k * x1-y0) -2 * x0c = (y1-k * x1-y0) ** 2 + x0 ** 2-r ** 2 # (x + B/(2a )) ** 2 = (B/(2 * a) ** 2-c/asquareRt = (B/(2 * a) ** 2-c/asqrtRt = math. sqrt (squareRt) rtX1 =-B/(2 * a) + sqrtRtrtY1 = k * (rtX1-x1) + y1rtX2 =-B/(2 *) -sqrtRtrtY2 = k * (rtX2-x1) + y1 # print 'centerpos: % s r: % s linePos: % s k: % s --> (% s, % s ), (% s, % s) '% (centerPos, r, linePos, k, rtX1, rtY1, rtX2, rtY2) return (rtX1, rtY1), (rtX2, rtY2)
(It took three days to get familiar with PIL and use PIL to write a program to draw a topology. You can leave an email for it. Haha -- 0:2.9.22)
PS:
1. raise ImportError ("The _ imagingft C module is not installed ")
Solution: Download the source code from the official website and recompile and install it...
2. Chinese font files
Http://code.google.com/p/chinesepuppylinux/downloads/detail? Name = wqy-microhei.ttc