180122 特征值与特征向量的几何解释与python代码,附matplotlib绘制多边形

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

  • 蓝色 特征向量(竖着看)
    122
    022

  • 黑色 变换矩阵(左乘)特征向量(竖着看)
    32
    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) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GuokLiu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值