用于多个图形画在同一画框中,以区分哪个图形属于哪个

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 50)
y = np.sin(x)
plt.plot(x, y)
plt.plot(x, y * 2)

plt.legend()给图像加上图例,以区分哪个图形属于哪个

 

 加上这个函数,就知道它的作用了

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 50)
y = np.sin(x)
plt.plot(x, y,c='green')
plt.plot(x, y * 2,c='blue')
plt.legend(['green','blue'])

plt.legend()给图像加上图例,以区分哪个图形属于哪个

 

 或者是这样子

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 50)
y = np.sin(x)
plt.plot(x, y, label="sin(x)",c='green')
plt.plot(x, y * 2, label="2sin(x)",c='blue')
plt.legend()

plt.legend()给图像加上图例,以区分哪个图形属于哪个

 

相关文章:

  • 2021-07-01
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-07-30
猜你喜欢
  • 2021-09-26
  • 2021-09-05
  • 2021-06-18
  • 2022-12-23
  • 2022-02-08
  • 2021-05-12
  • 2022-12-23
相关资源
相似解决方案