2016-10-04 43 views
0

轴值这是我第一次使用matplotlib尝试和失败...我有数据列表如下:如何设置matplotlib

years = [1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014]

temps = [14.11, 7.54, 5.22, 3.81, 2.9, 2.7, 2.4, 1.82, 1.66, 1.52, 1.34, 1.19, 1.12, 1.17, 1.04, 0.87, 0.87, 0.89, 0.76, 0.75, 0.73, 0.72, 0.69, 0.64, 0.62, 0.62, 0.6, 0.64, 0.53, 0.49]

years应该是X-轴和temps应该是y轴。无法想象它如何。

`plt.hist([temps, years], bins=10) 
plt.title('Temp_histogram') 
plt.xlabel('year') 
plt.ylabel('temp') 
plt.grid(True) 
plt.show()` 

enter image description here

+0

难道你已经做过吗?鉴于你的直方图阴谋,我知道你的问题... – MMF

+0

不,我们应该只看到直方图中的温度值波动,而不是直方图中的两者。最后,我希望看到 – Leustad

回答

1

你确定你想要一个柱状图,而不是一个简单的条形图?事情是这样的:

plt.bar(years,temps, 1, color='r') 
plt.title('Temp_histogram') 
plt.xlabel('year') 
plt.ylabel('temp') 
plt.grid(True) 
plt.show() 

enter image description here

如果你真的想那么直方图想想(或告诉我们)的数量?(一quantitiy是一个物理实体,如“年”或“临时”这种情况下)你想分组数据。

+0

年的温度数据直方图好,您的答案有效。谢谢。 – Leustad