设置基本的matplotlib图形很容易:
import matplotlib.pyplot as pltimport numpy as npfig = plt.figure()ax = fig.add_subplot(1, 1, 1)
摘为列
x,
y并
color可能是这个样子:
N = 100data = np.random.random((N, 7))x = data[:,0]y = data[:,1]points = data[:,2:4]# color is the length of each vector in `points`color = np.sqrt((points**2).sum(axis = 1))/np.sqrt(2.0)rgb = plt.get_cmap('jet')(color)最后一行检索
jet颜色图,并将数组
color中的每个float值(0到1之间)映射到3元组RGB值。有可供选择色彩映射列表在这里。还有一种定义自定义颜色图的方法。
制作散点图现在很简单:
ax.scatter(x, y, color = rgb)plt.show()# plt.savefig('/tmp/out.png') # to save the figure to a file


