This article mainly introduces Python using Pylab Library to achieve the histogram function, combined with instance form analysis of Python data read, traverse and based on the Pylab library to draw histograms of the relevant operation skills, the need for friends can refer to the next
The examples in this article describe Python's ability to draw histograms using the Pylab library. Share to everyone for your reference, as follows:
Python histogram
#!/usr/bin/python#-*-coding:utf-8-*-import pylab as Pldatafile = "DataList.txt" templist = []with open (DataFile, "R") as Data: For everline in data: arreverline = [Float (index) for index in Everline.split ()] templist.append ( Arreverline[0]) pl.hist (templist,100) Pl.xlabel ("Histogram title", fontproperties= ' Simhei ') pl.show ()
DataList.txt Content
14 2 1 0.5 0.5 0 1 0.5 1.5 18.519 2 2 0.5 1 0 1 0.5 0 2119.5 2 1.5 2 0 0.5 2 0 1 2017.5 1.5 1 1.5 2 0 1.5 0 0 18.519.5 2 2 2 0.5 0 1 0 0.5 19.516.5 2 0.5 1 0 0.5 0.5 0 0.5 19.515.5 2 1 1.5 0 0 1 0.5 1 17.513.5 1.5 1 1 2 0 2 0.5 2 2014.5 2 1.5 2 0 0 1 0 2 18.516 2 2 1.5 1 0.5 1 0 2 19.5 ...
Output results