安装前需安装依赖:(针对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. haproxy 配置文件详解 之 ACL 智能负载均衡

    由于HAProxy 可以工作在七层模型下, 因此,要实现 HAProxy 的强大功能,一定要使用强大灵活的ACL 规则,通过ACL 规则可以实现基于HAProxy 的智能负载均衡系统. HAProxy ...

  2. R程序书写规范

    suppressMessages(library(xxx)) # 导入所需的R包 suppressMessages(library(xxx)) # 导入所需的R包 fucntion02 <- f ...

  3. SUSE12.2 添加ISO为源

    152 2019-05-16 16:40:13 mkdir /mnt/DVD1 153 2019-05-16 16:40:55 mount -o loop /root/SLE-12-SP2-Serve ...

  4. Hadoop集群上搭建Ranger

    There are two types of people in the world. I hate both of them. Hadoop集群上搭建Ranger 在搭建Ranger工程之前,需要完 ...

  5. 2019-2020-1 20181218《Linux内核原理与分析》第一周作业

    目录 问题和参考 有趣/有用的Linux命令 小作业和解答 一些图片 相关学习 本文是学习Linux基础入门(新版)后的总结. 问题和参考 虚拟机莫名崩溃,一天重启了几十次电脑,重装两次系统,心累.想 ...

  6. react-native字体react-native-vector-icons在ios下的使用

    react-native字体react-native-vector-icons在ios下的使用 官网和网上有各种针对ios/android的安装和使用方法:能够使用了,基本就等于安装成功了. reac ...

  7. django orm 外键id返回对应的名称

    原文:https://blog.csdn.net/gghhm/article/details/99652143 当我们在写django的orm模块时,有时候会在用外键关联时,保存的是对应表中的id字段 ...

  8. 数据对象如何定义为Java代码示例

    想将数据保存为这样子: [{ "subject": { "code": "B123", "words": [{ &quo ...

  9. 爬取'Content-Type': 'text/plain;charset=UTF-8' ,发送请求数据方式

    解决方式 直接以字符串的方式发送data就可以得到响应数据 import requests data = 'k1:v1,k2:v2' requests.post(url, data=data)

  10. JMeter工具学习(一)工具使用详细介绍

    备注: JMeter版本4.0 JDK版本1.8 1,JMeter下载 2,下载后直接解压 3,打开解压文件,找到bin目录下的jmeter.bat,双击打开 4,打开jmeter 6,右键Test ...