绘制直线图,确定x范围和y的范围 代码: import matplotlib.pyplot as pltimport numpy as np xpoints = np.array([0, 6]) #0-6的范围ypoints = np.array([0, 100]) #0-100的范围 plt.plot(xpoints, ypoints)plt.show() 绘制两个点
绘制直线图,确定x范围和y的范围
代码:
import matplotlib.pyplot as plt import numpy as np xpoints = np.array([0, 6]) #0-6的范围 ypoints = np.array([0, 100]) #0-100的范围 plt.plot(xpoints, ypoints) plt.show()
绘制两个点的坐标,用实心圆来标记点
代码:
import matplotlib.pyplot as plt import numpy as np xpoints = np.array([1, 8]) ypoints = np.array([3, 10]) plt.plot(xpoints, ypoints, 'o') plt.show()
绘制折线图,根据对应的x,y坐标
代码:
import matplotlib.pyplot as plt import numpy as np xpoints = np.array([1, 2, 6, 8]) ypoints = np.array([3, 8, 1, 10]) plt.plot(xpoints, ypoints) plt.show()
注意点,在不指定x坐标的时候,只有y坐标,那么x坐标随y坐标改变而改变,y连续,x的默认范围是【0,1】,y不连续,x的范围是从0开始的每次增加1的整数
y连续:
代码:
import matplotlib.pyplot as plt import numpy as np ypoints = np.array([3, 10]) plt.plot(ypoints) plt.show()
y不连续 :
代码:
import matplotlib.pyplot as plt import numpy as np ypoints = np.array([3, 8, 1, 10, 5, 7]) plt.plot(ypoints) plt.show()
绘制正弦函数和余弦函数曲线图
代码:
import matplotlib.pyplot as plt import numpy as np x = np.arange(0,4*np.pi,0.1) # 开始,停止,步频 y = np.sin(x) z = np.cos(x) plt.plot(x,y,x,z) plt.show()
到此这篇关于python Matplotlib绘图直线,折线,曲线的文章就介绍到这了,更多相关python Matplotlib绘图 内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!