python numpy矩阵索引_Matplotlib plot numpy矩阵为0索引

我准备一个numpy矩阵,然后使用matplotlib绘制矩阵,例如:>>> import numpy

>>> import matplotlib.pylab as plt

>>> m = [[0.0, 1.47, 2.43, 3.44, 1.08, 2.83, 1.08, 2.13, 2.11, 3.7], [1.47, 0.0, 1.5, 2.39, 2.11, 2.4, 2.11, 1.1, 1.1, 3.21], [2.43, 1.5, 0.0, 1.22, 2.69, 1.33, 3.39, 2.15, 2.12, 1.87], [3.44, 2.39, 1.22, 0.0, 3.45, 2.22, 4.34, 2.54, 3.04, 2.28], [1.08, 2.11, 2.69, 3.45, 0.0, 3.13, 1.76, 2.46, 3.02, 3.85], [2.83, 2.4, 1.33, 2.22, 3.13, 0.0, 3.83, 3.32, 2.73, 0.95], [1.08, 2.11, 3.39, 4.34, 1.76, 3.83, 0.0, 2.47, 2.44, 4.74], [2.13, 1.1, 2.15, 2.54, 2.46, 3.32, 2.47, 0.0, 1.78, 4.01], [2.11, 1.1, 2.12, 3.04, 3.02, 2.73, 2.44, 1.78, 0.0, 3.57], [3.7, 3.21, 1.87, 2.28, 3.85, 0.95, 4.74, 4.01, 3.57, 0.0]]

>>> matrix = numpy.matrix(m)

>>> matrix

matrix([

[ 0. , 1.47, 2.43, 3.44, 1.08, 2.83, 1.08, 2.13, 2.11, 3.7 ],

[ 1.47, 0. , 1.5 , 2.39, 2.11, 2.4 , 2.11, 1.1 , 1.1 , 3.21],

[ 2.43, 1.5 , 0. , 1.22, 2.69, 1.33, 3.39, 2.15, 2.12, 1.87],

[ 3.44, 2.39, 1.22, 0. , 3.45, 2.22, 4.34, 2.54, 3.04, 2.28],

[ 1.08, 2.11, 2.69, 3.45, 0. , 3.13, 1.76, 2.46, 3.02, 3.85],

[ 2.83, 2.4 , 1.33, 2.22, 3.13, 0. , 3.83, 3.32, 2.73, 0.95],

[ 1.08, 2.11, 3.39, 4.34, 1.76, 3.83, 0. , 2.47, 2.44, 4.74],

[ 2.13, 1.1 , 2.15, 2.54, 2.46, 3.32, 2.47, 0. , 1.78, 4.01],

[ 2.11, 1.1 , 2.12, 3.04, 3.02, 2.73, 2.44, 1.78, 0. , 3.57],

[ 3.7 , 3.21, 1.87, 2.28, 3.85, 0.95, 4.74, 4.01, 3.57, 0. ]

])

>>> fig = plt.figure()

>>> ax = fig.add_subplot(1,1,1)

>>> ax.set_aspect('equal')

>>> plt.imshow(matrix, interpolation='nearest', cmap=plt.cm.ocean)

>>> plt.colorbar()

>>> plt.show()

情节如下:

这很好,除了我希望轴从1到10,而不是从0到9(来自python的0索引)

有什么简单的方法可以做到这一点吗?

非常感谢!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值