zoukankan      html  css  js  c++  java
  • 使用numpy与matplotlib.pyplot画图

    使用numpy与matplotlib.pyplot画图

    1. 折线图

    复制代码
     1 # -*- enccoding:utf-8 -*-
     2 import numpy as np
     3 import matplotlib.pyplot as plt
     4 plt.rcParams['font.family'] = 'SimHei'             #用来正常显示中文
     5 plt.rcParams['font.sans-serif'] = ['SimHei']     #用来正常显示中文
     6 plt.rcParams['axes.unicode_minus'] = False   #用来正常显示负号
     7 fig = plt.figure()
     8 ph = fig.add_subplot(1,1,1)
     9 x = range(100)
    10 y = np.cos(x) * np.sin(x)**2 * 200
    11 ph.plot(x,y,'y-')
    12 ph.set_xticks([0,25,50,75,100])
    13 ph.set_title("常欣的声音频率")
    14 ph.set_xlabel('Time')
    15 ph.set_ylabel('Hz')
    16 plt.show()
    复制代码

    2. 等高线

    复制代码
     1 import matplotlib.pyplot as plt
     2 import numpy as np
     3 def f(x,y):
     4     return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)*1000
     5 plt.rcParams['font.family'] = 'KaiTi'               #用来正常显示中文
     6 plt.rcParams['font.sans-serif'] = ['SimHei']    #用来正常显示中文
     7 plt.rcParams['axes.unicode_minus'] = False   #用来正常显示负号
     8 
     9 x = np.linspace(-3,3,256)
    10 y = np.linspace(-3,3,256)
    11 X,Y = np.meshgrid(x,y)
    12 
    13 plt.contourf(X, Y, f(X,Y), 8, alpha=.75, cmap=plt.cm.hot)
    14 C = plt.contour(X, Y, f(X,Y), 8, colors='black')
    15 
    16 #plt.clabel(C, inline=1, fontsize=10)
    17 plt.title("常欣火焰山")
    18 plt.show()
    复制代码

  • 相关阅读:
    POJ 1095 Trees Made to Order 最详细的解题报告
    Producter and Consumer
    How to use the function of bind
    How to use the functions of apply and call
    Configurate vim tool
    #4713. 方程
    #4709. 树
    #4718. 管理
    #4710. 并
    #4707. 点分治
  • 原文地址:https://www.cnblogs.com/Exin/p/10748164.html
Copyright © 2011-2022 走看看