Python uses matplotlib drawing

Source: Internet
Author: User

Today is too late, refer to the link first put here, tomorrow, according to their actual situation as a whole, http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html

Actually encountered the source code as an example affixed.

# Show your cluster only available with 2-d data#centroids为k个类别, which holds the centroid of each category#clusterAssment为样本的标记, the first column is the category number for this sample, and the second is the distance to the centroid of this category def showcluster(DataSet, K, Centroids, clusterassment):NumSamples, Dim = Dataset.shapeifDim! =2:Print("sorry! I can not draw because the dimension of your data are not 2! ")return 1Mark = [' or ',' OB ',' og ',' OK ',' ^r ',' +r ',' SR ',' Dr ',' <r ',' PR ']ifK > Len (Mark):Print("sorry! Your K is too large! Please contact Wojiushimogui ")return 1     # Draw All Samples     forIinchRange (numsamples): markindex = Int (clusterassment[i,0])#为样本指定颜色Plt.plot (Dataset[i,0], Dataset[i,1], Mark[markindex]) mark = [' Dr ',' Db ',' Dg ',' Dk ',' ^b ',' +b ',' SB ',' DB ',' <b ',' PB ']# Draw the Centroids     forIinchRange (k):#画每个类的质心点Plt.plot (Centroids[i,0], Centroids[i,1], mark[i], markersize = A) Plt.show ()

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Python uses matplotlib drawing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.