Let's learn how to use graphs and charts in Python. The first question is: Why do we need graphs and charts?? The answer- to visualize the data. Humans can understand the patterns and trends much more easily when presented with a graph or chart rather than dealing with the raw numbers.
Let's start with the graphs and charts in python.
| code |
Here is the simple code used to plot a graph of 7 numbers.
| output |
The output of the above code.
Let's try with a different problem. The one I used in my previous blog. The problem is on radish survey from open tech school.
Here we have to plot a bar graph of the different variety of radishes present in the dataset.
| code |
I have used my previous code to load the data and count the votes for each variety of radishes.
Merged the code for the graph with it.
I have used two modules -
One is "pyplot". It is used wit Matplotlib to plot the graph.
The other one is NumPy which lots of numeric functions for Python.
Then I have used loop to process the dictionary into a format which is readable for matplotlib.
The next step is indexing of the X values in the graph. It is done with the help of the dictionary "count", where each entry is read. It helps to spread the graph evenly across the X-axis.
The last step is to plot the graph. plot.xtics() is used to to add labels to the X-axis like, the names of the varities of the radishes e.g. "White Icicle".
So, from the chart, we can summarize all our findings easily without even looking at the raw numbers of the output.
This is all what I have learnt about charts in python till now and will continue to explore and keep on learning.


