zoukankan      html  css  js  c++  java
  • 无聊八卦图

     

    【效果图】

    【源代码】

     1 import matplotlib.pyplot as plt
     2 import matplotlib.tri as tri
     3 import numpy as np
     4 import math
     5 
     6 
     7 n_angles = 12
     8 n_radii = 5
     9 min_radius = 0.0
    10 radii = np.linspace(min_radius, 5.0, n_radii)
    11 
    12 angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
    13 
    14 temp = []
    15 for i in range(12):
    16     temp.append(angles[i])
    17 temp.append(angles[0])
    18 angles = np.array(temp)
    19 
    20 angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
    21 #angles[:, 1::2] += math.pi/n_angles
    22 
    23 x = (radii*np.cos(angles))#.flatten()
    24 y = (radii*np.sin(angles))#.flatten()
    25 
    26 x1 = x.flatten()
    27 y1 = y.flatten()
    28     
    29 
    30 plt.figure()
    31 
    32 #
    33 plt.scatter(x, y)
    34 # 环线
    35 plt.plot(x, y, 'b')
    36 # 直线
    37 plt.plot(x1,y1)
    38 # 三角线
    39 for i in range(4):
    40     print(i,i+4,i+8)
    41     print(x.shape,y.shape)
    42     tempx = []
    43     tempx.append(x[i][4])
    44     tempx.append(x[i+4][4])
    45     tempx.append(x[i+8][4])
    46     tempx.append(x[i][4])
    47     tempy = []
    48     tempy.append(y[i][4])
    49     tempy.append(y[i+4][4])
    50     tempy.append(y[i+8][4])
    51     tempy.append(y[i][4])
    52     x2 = np.array(tempx)
    53     y2 = np.array(tempy)
    54     print(x2.shape,y2.shape)
    55     plt.plot(x2,y2,'--',lw=0.5)
    56     
    57 plt.title('八卦图',fontproperties="SimHei")
    58 
    59 plt.show()
  • 相关阅读:
    实验一
    requests/lxml的简单用例
    使用python的cookielib加载已保存的cookie维持登录状态
    计算机系统要素
    python实现部分实例
    ch2
    迷了迷了,外国人都看不懂的英语
    图形学名词解释
    ch17
    ServletConfig
  • 原文地址:https://www.cnblogs.com/hhh5460/p/4324964.html
Copyright © 2011-2022 走看看