matplotlib的基本用法(一)——figure的使用

转自:https://blog.csdn.net/Quincuntial/article/details/70879516

本文主要是关于matplotlib的一些基本用法。

    

  • Demo 1

import matplotlib.pyplot as plt
import numpy as np

# 绘制普通图像
x = np.linspace(-1, 1, 50)
y = 2 * x + 1
plt.plot(x, y)
plt.show()

# 绘制普通图像
y = x**2
plt.plot(x, y)
plt.show()
 

  • 结果
  • y=x^2
  • Demo 2  
  • # figure的使用
    x = np.linspace(-1, 1, 50)
    y1 = 2 * x + 1

    # figure 1
    plt.figure()
    plt.plot(x, y1)


    # figure 2
    y2 = x**2
    plt.figure()
    plt.plot(x, y2)


    # figure 3,指定figure的编号并指定figure的大小, 指定线的颜色, 宽度和类型
    y2 = x**2
    plt.figure(num = 5, figsize = (4, 4))
    plt.plot(x, y1)
    plt.plot(x, y2, color = 'red', linewidth = 1.0, linestyle = '--')
    plt.show()

  • 结果  
  • y=2x+1
  • y=x^2

猜你喜欢

转载自blog.csdn.net/BetterMan_zjm/article/details/84898473