python使用matplotlib繪圖

來源:互聯網
上載者:User

標籤:python   matplotlib   

今天太晚了,參考連結先放在這裡,明天再根據自己的實際情況整體一下,http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html

實際上遇到的原始碼作為例子貼上。

# show your cluster only available with 2-D data #centroids為k個類別,其中儲存著每個類別的質心#clusterAssment為樣本的標記,第一列為此樣本的類別號,第二列為到此類別質心的距離 def showCluster(dataSet, k, centroids, clusterAssment):      numSamples, dim = dataSet.shape      if dim != 2:          print ("Sorry! I can not draw because the dimension of your data is not 2!")          return 1      mark = [‘or‘, ‘ob‘, ‘og‘, ‘ok‘, ‘^r‘, ‘+r‘, ‘sr‘, ‘dr‘, ‘<r‘, ‘pr‘]      if k > len(mark):          print ("Sorry! Your k is too large! please contact wojiushimogui")          return 1     # draw all samples      for i in range(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      for i in range(k):  #畫每個類的質心點        plt.plot(centroids[i, 0], centroids[i, 1], mark[i], markersize = 12)      plt.show() 

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

python使用matplotlib繪圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.