李代数E8 的根系 python绘图
安装前需安装依赖:(针对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绘图的更多相关文章
- python绘图之seaborn 笔记
前段时间学习了梁斌老师的数据分析(升级版)第三讲<探索性数据分析及数据可视化>,由于之前一直比较忙没有来得及总结,趁今天是周末有点闲暇时间,整理一下笔记: 什么是seaborn Seabo ...
- python绘图:matplotlib和pandas的应用
在进行数据分析时,绘图是必不可少的模式探索方式.用Python进行数据分析时,matplotlib和pandas是最常用到的两个库.1.matplotlib库的应用准备工作如下:打开ipython,输 ...
- Python绘图工具Plotly的简单使用
1.Plotly被称为史上最好的绘图工具之一,为了更好的展示金融数据的复杂性. Plotly的官方网站为:https://plot.ly/ python量化的关键是金融数据可视化,无论是传统的K线图, ...
- 【python笔记】使用matplotlib,pylab进行python绘图
一提到python绘图,matplotlib是不得不提的python最著名的绘图库,它里面包含了类似matlab的一整套绘图的API.因此,作为想要学习python绘图的童鞋们就得在自己的python ...
- python绘图 matplotlib教程
mark一个很好的python绘图教程 https://liam0205.me/2014/09/11/matplotlib-tutorial-zh-cn/
- python绘图入门
python绘图入门 学习了:https://zhuanlan.zhihu.com/p/34200452 API:https://matplotlib.org/api/pyplot_api.html ...
- Python 绘图 cookbook
目录 python绘图常见bug matplotlib包加载 解决中文绘图乱码解决方法 解决python中用matplotlib画多幅图时出现图形部分重叠的问题 python绘图常见bug matpl ...
- 分形、分形几何、数据可视化、Python绘图
本系列采用turtle.matplotlib.numpy这三个Python工具,以分形与计算机图像处理的经典算法为实例,通过程序和图像,来帮助读者一步步掌握Python绘图和数据可视化的方法和技巧,并 ...
- python 绘图介绍
1. python 绘图介绍 2. 函数 import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 3.0, 0.01 ...
随机推荐
- css如何让父元素下的所有子元素高度相同
小颖最近做的项目中要实现一个样式 ,小颖怕自己忘记了,写个随笔记下来 需求父元素下有多个子元素,并且子元素过多时要实现自动换行,给每个子元素都加了右边框,而每个子元素里的内容多少不一定,这就会产生右边 ...
- ajax有哪些方法可以实现跨域?他们都有哪些局限性?
1.服务器端代理:在服务器端设置一个代理,由服务器端向跨域下的网站发出请求,再将请求结果返回给前端. 属于后端的技术,实现起来最麻烦. 2.jsonP,只支持get方式调用. 3.XHR2(cors) ...
- Qt常用类——Qpoint
QPoint 类代表一个坐标点,实现在 QtCore 共享库中.它可以认为是一个整型的横坐标和一个整型的纵坐标的组合. 构造 QPoint 类支持以下两种构造方式: QPoint(); // 构造横纵 ...
- vue - 小日历项目制作中的问题与解决思路
效果图: 项目难点: 1. 每个月的日期数是不定的,拢共需要几个格子? 按照教程的做法需要42个.所以遍历数字42,得到42个div做格子. 2. 格子的排版怎么做? 顶部的星期布局使用的flex水平 ...
- JavaScript插件开发
一.前言 通过 "WWW" 原则我们来了解 JavaScript 插件这个东西 第一个 W "What" -- 是什么?什么是插件,我就不照搬书本上的抽象概念了 ...
- 将fasta fastq文件线性化处理
将fasta文件线性化处理 awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;n ...
- 淘宝IP地址库获取到省市IP地址
http://ip.aliyun.com/index.html https://ispip.clang.cn/ https://github.com/Pingze-github/local-ips 1 ...
- IOCP陷阱
1. AcceptEx 10061 客户端循环连接,没有发送数据,一定次数后,连接失败,WSAGetLastError的结果是10061.并且后续无法再次连接. 这是因为其中的一个参数,详细用法参考I ...
- Hibernate的Hql语句使用in关键字
原文地址:https://blog.csdn.net/u013410747/article/details/50954867
- RuntimeError: Model class myapp.models.Test doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
没有添加子应用在settings里面!