安装前需安装依赖:(针对Centos7)

yum install -y cairo
pip install cairocffi

源代码:https://github.com/neozhaoliang/pywonderland/blob/master/src/misc/e8.py

# -*- coding: utf-8 -*-
"""
~~~~~~~~~~~~~~
The E8 picture
~~~~~~~~~~~~~~
This script draws the picture of E8 projected to its Coxeter plane.
For a detailed discussion of the math see Humphreys's book
"Reflection Groups and Coxeter Groups", section 17, chapter 3.
"""
from itertools import product, combinations
import cairocffi as cairo
import numpy as np COLORS = [(0.894, 0.102, 0.11),
(0.216, 0.494, 0.72),
(0.302, 0.686, 0.29),
(0.596, 0.306, 0.639),
(1.0, 0.5, 0),
(1.0, 1.0, 0.2),
(0.65, 0.337, 0.157),
(0.97, 0.506, 0.75)] # --- step one: compute all roots and edges --- # There are 240 roots in the root system,
# mutiply them by a factor 2 to be handy for computations.
roots = [] # Roots of the form (+-1, +-1, 0, 0, 0, 0, 0, 0),
# signs can be chosen independently and the two non-zeros can be anywhere.
for i, j in combinations(range(8), 2):
for x, y in product([-2, 2], repeat=2):
v = np.zeros(8)
v[i] = x
v[j] = y
roots.append(v) # Roots of the form 1/2 * (+-1, +-1, ..., +-1), signs can be chosen
# indenpendently except that there must be an even numer of -1s.
for v in product([-1, 1], repeat=8):
if sum(v) % 4 == 0:
roots.append(v)
roots = np.array(roots).astype(np.int) # Connect a root to its nearest neighbors,
# two roots are connected if and only if they form an angle of pi/3.
edges = []
for i, r in enumerate(roots):
for j, s in enumerate(roots[i+1:], i+1):
if np.sum((r - s)**2) == 8:
edges.append([i, j]) # --- Step two: compute a basis of the Coxeter plane --- # A set of simple roots listed by rows of 'delta'
delta = np.array([[1, -1, 0, 0, 0, 0, 0, 0],
[0, 1, -1, 0, 0, 0, 0, 0],
[0, 0, 1, -1, 0, 0, 0, 0],
[0, 0, 0, 1, -1, 0, 0, 0],
[0, 0, 0, 0, 1, -1, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 0],
[-.5, -.5, -.5, -.5, -.5, -.5, -.5, -.5],
[0, 0, 0, 0, 0, 1, -1, 0]]) # Dynkin diagram of E8:
# 1---2---3---4---5---6---7
# |
# 8
# where vertex i is the i-th simple root. # The cartan matrix:
cartan = np.dot(delta, delta.transpose()) # Now we split the simple roots into two disjoint sets I and J
# such that the simple roots in each set are pairwise orthogonal.
# It's obvious to see how to find such a partition given the
# Dynkin graph above: I = [1, 3, 5, 7] and J = [2, 4, 6, 8],
# since roots are not connected by an edge if and only if they are orthogonal.
# Then a basis of the Coxeter plane is given by
# u = sum (c[i] * delta[i]) for i in I,
# v = sum (c[j] * delta[j]) for j in J,
# where c is an eigenvector for the minimal
# eigenvalue of the Cartan matrix.
eigenvals, eigenvecs = np.linalg.eigh(cartan) # The eigenvalues returned by eigh() are in ascending order
# and the eigenvectors are listed by columns.
c = eigenvecs[:, 0]
u = np.sum([c[i] * delta[i] for i in [0, 2, 4, 6]], axis=0)
v = np.sum([c[j] * delta[j] for j in [1, 3, 5, 7]], axis=0) # Gram-Schimdt u, v and normalize them to unit vectors.
u /= np.linalg.norm(u)
v = v - np.dot(u, v) * u
v /= np.linalg.norm(v) # --- step three: project to the Coxeter plane ---
roots_2d = [(np.dot(u, x), np.dot(v, x)) for x in roots] # Sort these projected vertices by their modulus in the coxter plane,
# every successive 30 vertices form one ring in the resulting pattern,
# assign these 30 vertices a same color.
vertex_colors = np.zeros((len(roots), 3))
modulus = np.linalg.norm(roots_2d, axis=1)
ind_array = modulus.argsort()
for i in range(8):
for j in ind_array[30*i: 30*(i+1)]:
vertex_colors[j] = COLORS[i] # --- step four: render to png image ---
image_size = 600
# The axis lie between [-extent, extent] x [-extent, extent]
extent = 2.4
linewidth = 0.0018
markersize = 0.05 surface = cairo.ImageSurface(cairo.FORMAT_RGB24, image_size, image_size)
ctx = cairo.Context(surface)
ctx.scale(image_size/(extent*2.0), -image_size/(extent*2.0))
ctx.translate(extent, -extent)
ctx.set_source_rgb(1, 1, 1)
ctx.paint() for i, j in edges:
x1, y1 = roots_2d[i]
x2, y2 = roots_2d[j]
ctx.set_source_rgb(0.2, 0.2, 0.2)
ctx.set_line_width(linewidth)
ctx.move_to(x1, y1)
ctx.line_to(x2, y2)
ctx.stroke() for i in range(len(roots)):
x, y = roots_2d[i]
color = vertex_colors[i]
grad = cairo.RadialGradient(x, y, 0.0001, x, y, markersize)
grad.add_color_stop_rgb(0, *color)
grad.add_color_stop_rgb(1, *color/2)
ctx.set_source(grad)
ctx.arc(x, y, markersize, 0, 2*np.pi)
ctx.fill() surface.write_to_png('E8.png')

结果:

李代数E8 的根系 python绘图的更多相关文章

  1. python绘图之seaborn 笔记

    前段时间学习了梁斌老师的数据分析(升级版)第三讲<探索性数据分析及数据可视化>,由于之前一直比较忙没有来得及总结,趁今天是周末有点闲暇时间,整理一下笔记: 什么是seaborn Seabo ...

  2. python绘图:matplotlib和pandas的应用

    在进行数据分析时,绘图是必不可少的模式探索方式.用Python进行数据分析时,matplotlib和pandas是最常用到的两个库.1.matplotlib库的应用准备工作如下:打开ipython,输 ...

  3. Python绘图工具Plotly的简单使用

    1.Plotly被称为史上最好的绘图工具之一,为了更好的展示金融数据的复杂性. Plotly的官方网站为:https://plot.ly/ python量化的关键是金融数据可视化,无论是传统的K线图, ...

  4. 【python笔记】使用matplotlib,pylab进行python绘图

    一提到python绘图,matplotlib是不得不提的python最著名的绘图库,它里面包含了类似matlab的一整套绘图的API.因此,作为想要学习python绘图的童鞋们就得在自己的python ...

  5. python绘图 matplotlib教程

    mark一个很好的python绘图教程 https://liam0205.me/2014/09/11/matplotlib-tutorial-zh-cn/

  6. python绘图入门

    python绘图入门 学习了:https://zhuanlan.zhihu.com/p/34200452 API:https://matplotlib.org/api/pyplot_api.html ...

  7. Python 绘图 cookbook

    目录 python绘图常见bug matplotlib包加载 解决中文绘图乱码解决方法 解决python中用matplotlib画多幅图时出现图形部分重叠的问题 python绘图常见bug matpl ...

  8. 分形、分形几何、数据可视化、Python绘图

    本系列采用turtle.matplotlib.numpy这三个Python工具,以分形与计算机图像处理的经典算法为实例,通过程序和图像,来帮助读者一步步掌握Python绘图和数据可视化的方法和技巧,并 ...

  9. python 绘图介绍

    1. python 绘图介绍 2. 函数 import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 3.0, 0.01 ...

随机推荐

  1. 动态规划大合集II

    1.前言 大合集总共14道题,出自江哥之手(这就没什么好戏了),做得让人花枝乱颤.虽说大部分是NOIP难度,也有简单的几道题目,但是还是做的很辛苦,有几道题几乎没思路,下面一道道边看边分析一下. 2. ...

  2. 用poolmon来查找内存泄露

    用poolmon来查找内存泄露 poolmon C:\WinDDK\7600.16385.1\tools\Other\i386\poolmon.exegflags     C:\WinDDK\7600 ...

  3. 快速搭建Linux-0.11实验环境

    搭这个实验环境主要是为了学习Linux-0.11的代码,那就需要修改代码再次编译来验证自己的想法.主要的实验环境来自实验楼,但是在那上面毕竟不方便,所以就以实验楼上的为基础在自己的虚拟机上搭建一个环境 ...

  4. mysql 基本操作 一

    1.mysql 管理语句 1)展示数据库列表 mysql> show databases; +--------------------+ | Database | +-------------- ...

  5. 记一次node节点异常排查

    一.背景 公司进行kubernetes服务重启演练,集群重启后所有服务正常,仅node2节点处于notready状态 二.排查过程 查看对应节点的详细信息,发现kubelet一直处于starting状 ...

  6. 关于jsruntime 的概念

    In the JSAPI, JSRuntime is the top-level object that represents an instance of the JavaScript engine ...

  7. mapReduce 大数据离线分析

    数据分析一般分为两种,一种是在线一种是离线 流程: 一般都是对于日志文件的采集和分析 场景实例(某个电商网站产生的用户访问日志(access.log)进行离线处理与分析的过程) 1.需求: 基于Map ...

  8. 【数据结构与算法】线性表操作(C语言)

    #include <stdio.h> #include <stdlib.h> #define OK 1 #define NO 0 #define MAXSIZE 20 type ...

  9. 百度前端技术学院task16源代码

    欢迎访问我的github:huanshen 做这道题目的时候遇到了很多困难. 1.怎么给空对象添加数据,愣是不知道从哪里下手:遍历对象,一个个输出操作: 2.中英文的正则表达式不知道,赶紧去百度: 3 ...

  10. jwt的简单使用

    目录 简介 java版本 golang版本 简介 使用jwt对数据进行存储加密,分为java和golang版本. java版本 maven配置 <dependency> <group ...