Use Python for a simple drawing operation

Source: Internet
Author: User
Tags cos sin

I use the Python matplotlib module for a simple drawing operation, as a primer reference, directly below the code:

#coding: Utf-8import numpy as npimport matplotlib.pyplot as pltx=np.linspace (- Np.pi,np.pi,512,endpoint=true) C=np.cos (x) s=np.sin (x) plt.figure (1)    #首先建立一张图figure1plt. Plot (X,c,color = ' Red ', linewidth= ' 1.0 ', label= ' COS ', linestyle= '-', alpha=0.5 ' Plt.plot (x,s, ' b--', label= "SIN")    #- Represents the type of drawing line, you can also use the * Draw line Plt.title ("Cos & sin")      #图的名字 # Set Axis AX=PLT.GCA ()        ax.spines["Right"].set_color ("none")     #设置坐标轴的颜色ax. spines["Top"].set_ Color ("none") ax.spines["left"].set_position (("Data", 0))    #设置坐标轴的位置ax. spines["Bottom"].set_position (( "Data", 0)) ax.xaxis.set_ticks_position ("bottom")     #x轴的数据显示在x轴右侧ax. Yaxis.set_ticks_position (" Left ")      #y轴的数据显示在y轴左侧plt. Legend (loc=" Upper,left ")    #显示图例 #plt.axis ([ -1,1,-0.5,1 ])     #指定绘图范围, X from 1 to 1,y from 0.5 to 1plt.grid ()       #显示网格线plt. Fill_between (x, Np.abs (x) <0.5,c,c>0.7,color= ' green ', alpha=0.5)   #填充颜色plt. Show () 

The drawing effect is as follows:

Use Python for a simple drawing operation

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.