猫史档案馆


【Python作品分享】在一个图里面显示一条蓝色的虚线和一条抛物线图【作业帖】

用户:︶ㄣNn︶︶ㄣNn︶查看:0 回复:0 评论:0 创建时间:2021-07-31T16:49:01


【作品展示】

center_image

 

【作品介绍】

Python数据处理之函数绘制,在一个图里面显示一条蓝色的虚线和一条抛物线图。

 

【作品源代码】

import matplotlib.pyplot as plt
import numpy as np 

#画直线
'''x = np.linspace(-1,1,50) 
y = 3*x+1'''

'''x = np.linspace(-20, 20, 1000)
y = 2*x+1'''

#画抛物线
'''x = np.linspace(-1,1,50) 
y = x**2+1'''

#画sin()函数
'''x = np.linspace(0, 180, 1000) 
y = np.sin(x)+5'''

'''x = np.linspace(-20, 20, 1000)
y = np.sin(x)'''

'''plt.plot(x, y)
plt.show() '''

#同时显示多个图表
'''x = np.linspace(-20, 20, 1000)
y1 = 2*x+1
y2 = x**2+1
y3 = np.sin(x) 
plt.figure() 
plt.plot(x, y1) 
plt.figure()
plt.plot(x, y2) 
plt.figure()
plt.plot(x, y3) 
plt.show()'''

#作业1 在一个图里面显示一条蓝色的虚线和一条抛物线图
x = np.linspace(-20, 20, 1000)
y1 = 2*x
y2 = x**2-100 
plt.figure()
plt.plot(x, y1,color='blue',linestyle='--') #蓝色虚线
plt.plot(x, y2, color='red') #抛物线
plt.show()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页