How to Plot Polygons in Python
Shapely-Manual
Shapely-Test
3Blue1Brown-线性代数的几何解释
Downloads
Shapely-Windows
Shapely-Mac or Linux
- 红色 基坐标(竖着看)
1 0
0 1 - 绿色 变换矩阵(竖着看)
3 1
0 2 - 蓝色 特征向量(竖着看)
1−2√2
02√2 - 黑色 变换矩阵(左乘)特征向量(竖着看)
3−2√
02√
特征向量与特征值得几何含义:
特征向量:原始向量在进行线性旋转变换(左乘矩阵)后仍留在其所张成的空间的向量。
特征值:即特征向量进行线性变换后,留在原空间中变换的比例。
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 11 18:51:08 2015
@author: Duncan
A simplified version of linearring.py, one of the shapely examples
"""
from matplotlib import pyplot as plt
from shapely.geometry.polygon import Polygon
from descartes import PolygonPatch
import numpy as np
def drawArrow1(B,c="data",):
# fc: filling color
# ec: edge color
if c=='data':
fc='r'
ec='r'
s=0.25
elif c=='transf':
fc='g'
ec='g'
s=0.15
elif c=='eigenv':
fc='b'
ec='b'
s=0.1
else:
fc='k'
ec='k'
s=0.08
ax.arrow(0, 0, B[0], B[1],
length_includes_head=True,# 增加的长度包含箭头部分
head_width=s, head_length=s, fc=fc, ec=ec,label='abc')
# 注意: 默认显示范围[0,1][0,1],需要单独设置图形范围,以便显示箭头
ax.set_xticks(np.linspace(-3,4,8))
ax.set_yticks(np.linspace(-1,4,6))
ax.set_aspect('equal') #x轴y轴等比例
#%%
fig, ax = plt.subplots()
data_origin = np.array([[1,0],[0,1]])
data_transf = np.array([[3,1],[0,2]]).T
data = np.vstack((data_origin,data_transf))
c = ['data','data','transf','transf']
for i,j in zip(data,c):
drawArrow1(i,j)
#%%
D,V = np.linalg.eig(data_transf.T)
c = ['eigenv','eigenv']
for i,j in zip(V.T,c):
print(i,j)
drawArrow1(i,j)
ax.grid()
#%%
dt = np.dot(data_transf.T,V).T
drawArrow1(dt[0],c='after transfer')
drawArrow1(dt[1],c='after transfer')
print(dt)
#%%
ring_mixed = Polygon([(0, 0), V.T[0], V.T[1]])
ring_patch = PolygonPatch(ring_mixed,fc='yellow', ec='yellow', alpha=0.5)
ax.add_patch(ring_patch)
#%%
plt.savefig('arrow.png', transparent = True, bbox_inches = 'tight', pad_inches = 0.25)