2016-12-13 102 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() 
相關問題