基本可视化
对数组进行可视化
import numpy as np
%pylab inline
Populating the interactive namespace from numpy and matplotlib
也可以使用:import matplotlib.pyplot as plt
1D作图
plt.plot(np.array([3,4,5]),np.array([3,6,8])) # 绘制图画
[<matplotlib.lines.Line2D at 0x1248310>]
上述的方法是不太好的。
x1 = np.array([4,6,3,5])
y1 = np.array([4,5,-1,8])
plt.plot(x1,y1)
[<matplotlib.lines.Line2D at 0x1309c30>]
x2 = np.linspace(0,3,20)
y2 = np.linspace(0,9,20)
x3 = np.linspace(0,5,20)
y3 = np.linspace(0,8,20)
plt.plot(x2,y2,'-',x3,y3,'o') # 默认格式是“-”
[<matplotlib.lines.Line2D at 0xa9a6910>,
<matplotlib.lines.Line2D at 0xa9a69f0>]
2D作图
image = np.random.rand(30, 30)
plt.imshow(image, cmap=plt.cm.hot)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0xaa75830>
数组的索引和切片
- 数组的索引和切片与python内置的列表切片用法一致。
- 对于多维的数组,索引就像数学中的坐标
- 注意:与matlab不同,python的索引和切片都是从0开始。