2016-12-13 73 views
1

我想用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]]} 
+0

你需要告诉的哪一部分你的'对象“应该在图上的哪个位置,而对象的哪一部分是”标签“。还有什么你已经尝试完成这一点,问题在哪里? – ImportanceOfBeingErnest

回答

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() 
相关问题