学习笔记与雷达图

numpy的读书笔记:

1.创建ndarray:

# 列表转换
data1 = [6, 7.5, 8, 0, 1]
arr1 = np.array(data1)

# 嵌套序列
data2 = [[1,2,3,4],[5,6,7,8]]
arr2 = np.array(data2)

np.zeros(10)
np.zeros((3,6))
np.empty((2,3,2)) 
np.arange(15)

ndarray的数据类型:

# 创建的时候指定类型
arr1 = np.array([1,2,3], dtype=np.float64) #双精度浮点
arr2 = np.array([1,2,3], dtype=np.int32)

 

 

matplotlib读书笔记:

  1. from pylab import *
  2. from numpy import *
  3. x = linspace(0, 5, 10)
  4. y = x ** 2
  5. figure()
  6. plot(x, y, 'r')
  7. xlabel('x')
  8. ylabel('y') 
  9. title('title')
     
    #创建子图,选择绘图用的颜色与符号
    subplot(1,2,1)
    plot(x, y, 'r--')
    subplot(1,2,2)
    plot(y, x, 'g*-');
     
     
     
     
     
    雷达图:
    import numpy as np
    import matplotlib.pyplot as plt
    plt.rcParams['font.family'] = 'SimHei' 
    plt.rcParams['font.sans-serif'] = ['SimHei'] 
    labels = np.array(['第一周','第二周','第三周','第四周','第五周','第六周','第七周'])
    datas = np.array([50,87.3,100,100,93.3,60,0])
    angles = np.linspace(0, 2*np.pi, 7, endpoint = False) 
    datas = np.concatenate((datas, [datas[0]]))
    angles = np.concatenate((angles, [angles[0]]))
    fig = plt.figure(facecolor = 'white') 
    plt.subplot(111, polar = True) 
    plt.plot(angles, datas, 'bo-', color = 'g', linewidth = 1) 
    plt.fill(angles, datas, facecolor = 'g', alpha = 0.25) 
    plt.thetagrids(angles*180/np.pi, labels) 
    plt.figtext(0.52, 0.95, '成绩雷达图', ha = 'center') 
    plt.grid(True) 
    plt.show() 

posted @ 2020-05-03 21:41  心辰  阅读(250)  评论(0)    收藏  举报