1.函数

image.png

  1. # coding=gbk
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. from scipy import signal
  5. plt.rcParams['figure.figsize'] = (8, 4.5) # 设置figure_size尺寸
  6. plt.rcParams['figure.dpi'] = 150 # 分辨率
  7. plt.rcParams['savefig.dpi'] = 300 # 图片像素
  8. plt.rcParams['image.interpolation'] = 'nearest' # 设置 interpolation style
  9. plt.rcParams['image.cmap'] = 'gray' # 设置 颜色 style
  10. # 默认的像素:[6.0,4.0],分辨率为100,图片尺寸为 600&400
  11. # 指定dpi=200,图片尺寸为 1200*800
  12. # 指定dpi=300,图片尺寸为 1800*1200
  13. # 设置figsize可以在不改变分辨率情况下改变比例
  14. x1 = np.linspace(-5, 5, 10000)
  15. y1 = x1 - np.sin(x1)
  16. plt.plot(x1, y1, c = 'k', label = r"$ y=x-sinx $")
  17. plt.grid()
  18. plt.legend()
  19. plt.show()

image.png
image.png

x1 = np.linspace(-1, 1.5, 1000)
y1 = 3 * (x1 ** 4) - 4 * (x1 ** 3) + 1
plt.plot(x1, y1, label = r"$ y = 3x^4 - 4x^3 + 1 $")

image.png
image.png

a = 1
theta = np.arange(0, 2 * np.pi, np.pi / 180)
x = np.sin(theta)
y = 3*np.cos(theta) + 3*np.power((x ** 2), 1 / 3)    # 原来用 y = np.cos(theta) + np.power(x, 2/3)只画出一半,而且报power的错
plt.plot(x, y, label=r'$x=sin\theta,\quady=cos\theta+\sqrt[3]{x^2}$')


plt.grid('equal')
plt.legend()
plt.show()

image.png

x = np.linspace(0, 10, 1000) #自变量
y = np.sin(x) + 1
z = np.cos(x**2) + 1

plt.plot(x, y, label='\$sin x+1$', color='red', linewidth='2')  # 作图,设置标签,线条颜色,大小
plt.plot(x, z, 'b--', label='\cos x^2+1')
plt.xlabel('Time(s)')  # x轴名称
plt.ylabel('Vlot')  # y轴名称
plt.title('A Simple Example')  # 标题
plt.xlim(0, 10)  # x轴范围
plt.ylim(0, 2.2)  # y轴范围
plt.legend()  # 显示图例
plt.show()  # 显示作图结果

image.png