Leuthus Leuthus - 2 months ago 8
Python Question

How to set axis values in matplotlib

This is my first attempt to use

matplotlib
and failing... I have lists of data as:

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
should be the x-axis and the
temps
should be the y-axis. Can't figure it how.

`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

Answer

Are you sure that you want a histogram and not a simple bar chart? Something like this:

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

If you really want a histogram then think about (or tell us) by what quantity (a quantitiy is a physical entity, like "year" or "temp" in this case) you want to group the data.