0
我想画一个使用matplotlib
的直方图。这是我的代码:用matplotlib指定X轴范围?
import matplotlib.pyplot as plt
from pylab import *
class Histogram(object):
@staticmethod
def plot_histogram(dictionary, labelx, labely, show, save, filename): # x and y are list of values
x = [int(year) for year,freq in dictionary.iteritems()]
y = [int(freq) for year,freq in dictionary.iteritems()]
print x,y
plt.bar(x,y,align='center') # A bar chart
plt.xlabel(labelx)
plt.ylabel(labely)
for i in range(len(y)):
plt.hlines(y[i],0,x[i]) # Here you are drawing the horizontal lines
if show:
plt.show()
if save:
pylab.savefig(filename)
if __name__=="__main__":
Histogram.plot_histogram({2015:1, 2014:1,2008:1, 2011:1, 2010:2, 2012:1},"x","y",True, False, "")
输出是:
6年里,我很感兴趣,在一个地方受到限制。我需要拉伸该区域并正确显示。我怎样才能做到这一点?