Matplotlib练习2:figure

完整程序

import matplotlib.pyplot as plt
import numpy as np

#numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
#在指定的间隔内返回均匀间隔的数字。
x = np.linspace(-1, 1, 100)
y1 = 2*x + 1
y2 = x**2
#生成第一个图像y1
plt.figure()
plt.plot(x, y1)
#生成第二个图像y2,设置长2,宽2
plt.figure(figsize=(2,2))
plt.plot(x, y2)

plt.show()

figure1

figure2

修改上面程序中图1的参数,设置直线性质

#将上面的第一张figure1中的直线设置为红色,宽度1,线风格虚线
plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--')

效果图

修改上面程序中图2的参数,设置曲线性质

#设置曲线y2颜色为蓝色,线宽2,线风格为实线
plt.plot(x, y2, color='blue', linewidth=2.0, linestyle='-')

效果图

猜你喜欢

转载自blog.csdn.net/weixin_48524215/article/details/111768837