Python matplotlib simple drawing example, pythonmatplotlib

Source: Internet
Author: User

Python matplotlib simple drawing example, pythonmatplotlib

This example describes how to use matplotlib for simple plotting in Python. We will share this with you for your reference. The details are as follows:

#-*-Coding: UTF-8 -*-#! Python2 "Created on Mon Apr 24 12:48:40 2017 @ author: x-power" import matplotlib. pyplot as plt # first load the matplotlib drawing module pyplot and rename it plt. Import numpy as npx = np. linspace (1000,) y = np. sin (x) z = np. cos (x ** 2) plt. figure (figsize = (8, 4) # specify the aspect ratio plt of the image. plot (x, y, label = "$ sin (x) $", color = "red", linewidth = 2) # Call plot to plot in the current figure object. In fact, plot is drawing on the Axes object. If there is no Axes object in the current Figure object, an Axes object that is almost full of the entire icon will be created for it, and the Axes object will become the current Axes object. The first two parameters of the plot are the objects that represent the X and Y axes data respectively. The NumPy array is used here. Label: Create a label for the curve. This label is displayed in the figure. If there is a $ symbol before and after the label, matplotlib will display it as a mathematical formula using the built-in LaTeX engine. Color: Specifies the color of the curve. The color can be represented by an English word, a hexadecimal number starting with #, or a ancestor composed of three numbers between 0 and 1, for example, (1, 0, 0) indicates the red plt. plot (x, z, label = "$ cos (x ^ 2) $", color = "blue", linewidth = 1) plt. xlabel ("Time (s)") # title text plt of the current axis. ylabel ("Volt") plt. title ("www.jb51.net-PyPlot First Example") # title plt of the subgraph. ylim (-1.2, 1.2) # display range of the Y axis plt. legend () # displays the prompt information in the upper right corner of the graph. Plt. show ()

Running effect:

Related Article

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.