[Python] Visualizing data
In Python there are a few ways to visualize data ...
... and i want to show you a very simple one here:
We are going to use "Matplotlib" for that.
"Matplotlib" is a python module, what makes it realy easy to draw diagrams.
The input data can come from a csv file or any other file.
To draw the diagram from above, i have written the following code:
1 2 3 4 5 6 7 | import matplotlib.pyplot as plt year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012] jackpot_hits = [4, 7 ,4, 3, 8, 5, 2, 1, 3, 7, 4, 3, 9] plt.plot(year, jackpot_hits) plt.show() |
Does not seem to be very hard, right?
So what do we do here?
import matplotlib.pyplot as pltHere we import the needed module to be able to draw diagrams.
year = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012] jackpot_hits = [4, 7 ,4, 3, 8, 5, 2, 1, 3, 7, 4, 3, 9]Then we create two lists: "year" and "jackpot_hits".
plt.plot(year, jackpot_hits)Here we create the diagram with the function "plot()", based of the data within the lists. "year" is the diagram's x-axis (horizontal) and "jackpot_hits" the y-axis (vertical).
plt.show()And finally the function "show()" draws the diagram.
And thats it, as easy as that. :)
Comments
Post a Comment