如何用不同的颜色绘制对象的成员?

时间:2016-12-13 18:36:17

标签: python matplotlib

我想使用matplotlib绘制这个python对象。这个对象有三个不同的标签,我想用不同的颜色绘制每个标签

{1.0: [[-1.9242, 1.0], [-2.0039, 1.0], [-2.0259, 1.0], [-1.8096, 1.0], [-1.9083, 1.0]],
 2.0: [[0.53616, 2.0], [0.56647, 2.0], [0.50042, 2.0], [0.31371, 2.0], [0.61207, 2.0], [0.93016, 2.0], [0.27571, 2.0], [0.14968, 2.0], [0.2886, 2.0], [0.3646, 2.0]], 
 3.0: [[1.1139, 3.0], [1.1449, 3.0], [1.5837, 3.0], [1.7038, 3.0], [1.192, 3.0], [1.6529, 3.0], [1.3052, 3.0], [2.2981, 3.0], [1.3196, 3.0], [1.3439, 3.0], [1.3795, 3.0], [1.5595, 3.0], [1.6977, 3.0], [1.2672, 3.0], [1.4191, 3.0], [1.719, 3.0], [1.6339, 3.0], [1.4335, 3.0], [1.4942, 3.0], [1.574, 3.0]]}

1 个答案:

答案 0 :(得分:3)

您可以发出单独的绘图语句,指定colorc=...

from matplotlib import pyplot as plt

d = {1.0: [[-1.9242, 1.0], [-2.0039, 1.0], [-2.0259, 1.0], [-1.8096, 1.0], [-1.9083, 1.0]],
 2.0: [[0.53616, 2.0], [0.56647, 2.0], [0.50042, 2.0], [0.31371, 2.0], [0.61207, 2.0], [0.93016, 2.0], [0.27571, 2.0], [0.14968, 2.0], [0.2886, 2.0], [0.3646, 2.0]], 
 3.0: [[1.1139, 3.0], [1.1449, 3.0], [1.5837, 3.0], [1.7038, 3.0], [1.192, 3.0], [1.6529, 3.0], [1.3052, 3.0], [2.2981, 3.0], [1.3196, 3.0], [1.3439, 3.0], [1.3795, 3.0], [1.5595, 3.0], [1.6977, 3.0], [1.2672, 3.0], [1.4191, 3.0], [1.719, 3.0], [1.6339, 3.0], [1.4335, 3.0], [1.4942, 3.0], [1.574, 3.0]]}
plt.scatter(*zip(*d[1.]), c='b')
plt.scatter(*zip(*d[2.]), c='r')
plt.scatter(*zip(*d[3.]), c='g')
plt.show()