python資料視覺效果matplotlib的使用

來源:互聯網
上載者:User

標籤:python   matplotlib   資料視覺效果   

# -*- coding:UTF-8 -*-import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.ticker import MultipleLocatorfrom pylab import mplimport sysreload(sys)sys.setdefaultencoding(‘utf8‘)xmajorLocator = MultipleLocator(10* 1) #將x軸主刻度標籤設定為10* 1的倍數ymajorLocator = MultipleLocator(0.1* 1) #將y軸主刻度標籤設定為0.1 * 1的倍數# 設定中文字型mpl.rcParams[‘font.sans-serif‘] = [‘SimHei‘]# 匯入檔案資料#data = np.loadtxt(‘test44.txt‘, delimiter=None, dtype=float )#data = [[1,2],[3,4],[5,6]]data = [[1,5,10,20,30,40,50,60,70,80,90,100],[0.0201,0.0262,0.0324,0.0295,0.0221,0.0258,0.0254,0.0299,0.0275,0.0299,0.0291,0.0328],[0.0193,0.0254,0.0234,0.0684,0.0693,0.0803,0.1008,0.098,0.0947,0.0934,0.1971,0.2123],[0.0209,0.1176,0.2143,0.2295,0.4176,0.5258,0.6471,0.6484,0.8193,0.829,0.832,0.943]]data = np.array(data)# 截取數組資料x = data[0] #時間y = data[1] # 類別一的Y值y2 = data[2] #類別二的Y值y3 = data[3] #類別三的Y值plt.figure(num=1, figsize=(8, 6))ax = plt.subplot(111)ax.xaxis.set_major_locator(xmajorLocator)ax.yaxis.set_major_locator(ymajorLocator)ax.xaxis.grid(True, which=‘major‘) #x座標軸的網格使用主刻度ax.yaxis.grid(True, which=‘major‘) #x座標軸的網格使用主刻度plt.xlabel(‘時間/t‘,fontsize=‘xx-large‘)#Valid font size are large, None, medium, smaller, small, x-large, xx-small, larger, x-small, xx-largeplt.ylabel(‘y-label‘,fontsize=‘xx-large‘)plt.title(‘Title‘,fontsize=‘xx-large‘)plt.xlim(0, 110)plt.ylim(0, 1)line1, = ax.plot(x, y, ‘g.-‘,label="類別一",)line2, = ax.plot(x,y2,‘b*-‘,label="類別二",)line3, = ax.plot(x,y3,‘rD-‘,label="類別三",)ax.legend((line1, line2,line3),(‘類別一‘,‘類別二‘,‘類別三‘),loc=5) # loc可為1、2、3、4、5、6,分別為不同的位置plt.show()

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/8A/14/wKiom1glhNzzOH6RAAC-KZBibC8139.jpg-wh_500x0-wm_3-wmp_4-s_167757986.jpg" title="QQ20161111154134.jpg" alt="wKiom1glhNzzOH6RAAC-KZBibC8139.jpg-wh_50" />

本文出自 “lefteva” 部落格,請務必保留此出處http://lefteva.blog.51cto.com/11892835/1871878

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.