# -*- 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 multiples ymajorlocator = multiplelocator (0.1* 1) #将y轴主刻度标签设置为0.1 * 1 multiple # Set the Chinese font mpl.rcparams[' font.sans-serif '] = [' simhei ']# import file Data #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) # intercept array numberAccording to x = data[0] #时间y the Y value of = data[1] # category one 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 (' time/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= "category One",) Line2, = ax.plot (x,y2, ' b*-', label= "category II",) Line3, = ax.plot (x,y3, ' rd-', label= "category three",) Ax.legend ((Line1, line2,line3), (' Category I ', ' Category II ', ' Category Three '), loc=5) # loc can be 1, 2, 3, 4, 5, 6, respectively, for different bitsPlace 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 "/>
This article is from the "Lefteva" blog, make sure to keep this source http://lefteva.blog.51cto.com/11892835/1871878
The use of Python data visualization matplotlib