mataplotlib绘制曲线图与折线图

绘制曲线:

import time
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(x)
plt.figure(figsize=(6,4))
plt.plot(x,y,color="red",linewidth=1 )
plt.xlabel("x") #xlabel、ylabel:分别设置X、Y轴的标题文字。
plt.ylabel("sin(x)")
plt.title("正弦曲线图") # title:设置子图的标题。
plt.ylim(-1.1,1.1)# xlim、ylim:分别设置X、Y轴的显示范围。
plt.savefig('quxiantu.png',dpi=120,bbox_inches='tight')
# plt.show()
# plt.close()

mataplotlib绘制曲线图与折线图

绘制折线

#绘制折线图
import matplotlib.pyplot as plt
squares=[1,4,9,6,25]
plt.plot(squares)
plt.savefig('zhexiantu.png',dpi=120,bbox_inches='tight') #dpi 代表像素

mataplotlib绘制曲线图与折线图