擅长:python、mysql、java
<p>可以使用所需图例创建虚拟散点图,如下所示:</p>
<pre><code>pl.scatter(X[:,0], X[:,1], c = labels)
for item in labels:
#dummy plot just to create the legend
pl.scatter([], [], c = item, label = item)
#loc = 0 is for the best position of the legend
#scatterpoints = 1 will only show one point in the legend instead of multiple points
plt.legend(loc = 0, scatterpoints = 1)
pl.show()
</code></pre>