Python's matplotlib Library common functions encyclopedia (with notes)

Source: Internet
Author: User

Plt.savefig (' Test ', DPI = 600): Save the drawn picture in PNG format, named Test

Plt.ylabel (' Grade '): Name of the y-axis

Plt.axis ([-1, 0, 6]): X-axis starting at-1, terminating at ten, y-axis starting at 0, terminating at 6

Plt.subplot (3,2,4): Divided into 3 rows and 2 columns, a total of 6 plot areas, drawing in the 4th area. Sort to line first. You can also Plt.subplot (324) and omit the comma.

. plot function

Plt.plot (x, Y, format_string, **kwargs): X is the x-axis data, can be a list or an array, y is the same, format_string is the format string that controls the curve, **kwargs the second group or more (x, Y, Format_ String

Format_String: consists of color characters, style characters, and marker characters.

Color characters: ' B ' blue; ' #008000 ' rgb a color; ' 0.8 ' grayscale value string

Style characters: '-' solid line; '--' broken line; '-. ' Dot dash; ': ' dashed line; ' ' Wireless bar

Tagged characters: '. ' Dot Mark ' O ' solid ring ' V ' inverted triangle ' ^ ' Upper triangle

Eg:plt.plot (A, a*1.5, ' go-', A, a*2, ' * ') the second curve has no curves, only points

. Plot display Chinese characters

Pyplot does not support Chinese display by default and requires Rcparams to modify fonts to implement

Properties of the Rcparams:

' font.family ' is used to display the name of the font

' Font.style ' font style, normal ' ' normal ' or italic ' italic '

' Font.Size ' font size, integer size or ' large ' x-small '

eg

Import Matplotlib

matplotlib.rcparams[' font.family '] = ' stsong '

matplotlib.rcparams[' font.size '] = 20

Sets the entire font of the drawing area into Chinese imitation with a font size of 20

Chinese display 2: Just want to draw Chinese characters in some place, do not change the font of other places

In the Chinese output place, add an attribute: Fontproperties

eg

Plt.xlabel (' Horizontal axis: Time ', fontproperties = ' Simhei ', fontsize = 20)

Pyplot Text display function:

Plt.xlabel (): Add text label to x axis

Plt.ylabel (): similarly

Plt.title (): Adds a text label to the overall shape

Plt.text (): Add text at any location

Plt. Annotate (s, xy = ARROW_CRD, Xytext = text_crd, arrowprops = dict)

: Adds an annotation with arrows in the drawing. s indicates what string to annotate, XY corresponds to the position of the arrow, Xytext corresponds to the position of the text, Arrowprops defines the displayed properties

eg

Plt.xlabel (' Horizontal axis: Time ', fontproperties = ' Simhei ', FontSize =, color = ' green ')

Plt.ylabel (' longitudinal axis: amplitude ', fontproperties = ' Simhei ', fontsize = 15)

Plt.title (R ' sine wave instance $y =cons (2\pi x) $ ', fontproperties = ' Simhei ', FontSize = 25)

Plt.annotate (R '%mu=100$, XY = (2, 1), Xytext = (3, 1.5),

Arrowprops = dict (Facecolor = ' black ', shrink = 0.1, width = 2) # width indicates arrowhead width

Plt.text (2, 1, R ' $\mu=100$, FontSize = 15)

Plt.grid (True)

Plt. Annotate (s, xy = ARROW_CRD, Xytext = text_crd, arrowprops = dict)

Plt Sub-plot area

Plt.subplot2grid (Gridspec, Curspec, Colspan=1, rowspan=1): Sets the grid, selects the grid, determines the number of columns selected, numbering starts at 0.

eg

Plt.subplot2grid ((3, 3), (1, 0), colspan = 2): (3,3) is divided into 3 rows and 3 columns, (1,0) indicates that the 1th row is selected, the area of column No. 0 is plotted, and colspan=2 represents the extension in the selected area

Gridspec class



Chart functions for plot

Plt.plot (x, Y, FMT): Plotting a coordinate chart

Plt.boxplot (Data,notch, Position): Drawing box plots

Plt.bar (left,height, Width, bottom): Draw a bar chart

Plt.barh (Width,bottom, left, height): Draw a horizontal bar chart

Plt.polar (theta,r): Drawing polar Plots

Plt.pie (Data,explode): Draw pie chart

Plt.scatter (x, y): Plot scatter plot

Plt.hist (X,bings, normed): Drawing histograms

Draw a pie chart

Explode is prominent, such as Orange this piece prominent; autopct represents the format of the display data; Shadow represents a two-dimensional pie chart; StartAngle represents the starting angle;

This is an oval pie chart, to be rounded, add: plt.axis (' equal ')

Draw a histogram

Bings the value range of the histogram is divided into bings intervals evenly.

Normed =1 said the frequency of occurrence was normalized. Normed=0, it is frequency;

Alpha indicates the transparency of the histogram [0, 1];

Histtype = ' stepfilled ' means removing the black border of the bar

Object-oriented Polar map drawing

Object-oriented scatter plot

Turns subplots () into an object, with fig and ax representing subplots generated charts and related areas. When subplots is empty, the default is subplots (111)

Python's matplotlib Library common functions encyclopedia (with notes)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.