Today I will teach you how to draw some linear patterns using python. Friends in need can refer to it.
Draw the simplest straight line graph
The code is as follows:
import numpy as np import matplotlib.pyplot as plt x=[0,1] y=[0,1] plt.figure() plt.plot(x,y) plt.savefig("easyplot.jpg")
#x轴,y轴 x=[0,1] y=[0,1] #创建绘图对象 plt.figure() #在当前绘图对象进行绘图(两个参数是x,y轴的数据) plt.plot(x,y) #保存图象 plt.savefig("easyplot.jpg")
import numpy as np import matplotlib.pyplot as plt x=[0,1] y=[0,1] plt.figure() plt.plot(x,y) plt.xlabel("time(s)") plt.ylabel("value(m)") plt.title("A simple plot")
plt.xlabel("time(s)") #X轴标签 plt.ylabel("value(m)") #Y轴标签 plt.title("A simple plot") #标题
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000) y = np.sin(x)
plt.figure(figsize=(8,4))
plt.plot(x,y,label="$sin(x)$",color="red",linewidth=2)
plt.xlabel("Time(s)")
plt.ylabel("Volt")
plt.title("PyPlot First Example")
plt.ylim(-1.2,1.2)
plt.legend()
plt.show()
plt.savefig("sinx.jpg")
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt #X轴,Y轴数据 x = [0,1,2,3,4,5,6] y = [0.3,0.4,2,5,3,4.5,4] plt.figure(figsize=(8,4)) #创建绘图对象 plt.plot(x,y,"b--",linewidth=1) #在当前绘图对象绘图(X轴,Y轴,蓝色虚线,线宽度) plt.xlabel("Time(s)") #X轴标签 plt.ylabel("Volt") #Y轴标签 plt.title("Line plot") #图标题 plt.show() #显示图 plt.savefig("line.jpg") #保存图
Detailed code examples of how to implement stack data structure and bracket matching algorithm in php
The most popular in php Simple string matching algorithm, php matching algorithm_PHP tutorial
The simplest string matching algorithm tutorial in php
The above is the detailed content of How to draw a line chart using python. For more information, please follow other related articles on the PHP Chinese website!