Saturday, 8 August 2015

Creating Charts Using Python

 In this blog i will explain how to create charts in python. "matplot" is the library in python that is used to create charts. matplotlib also outputs charts in other formats like images
 


The above screenshot shows us the simple graph constructed in Ipython notebook by using  matplot library.
                                Now consider Radish survey,we will draw a bar plot for number of votes each radish variety achieved.We are importing two modulus -pyplot is one way to plot graph data with matplotlib, It's modelled on the way charting works in another popular commercial program. Mat-lab Numpy is a module providing lots of numeric functions in python 
The above screen shot shows the bar graph for radish survey,the varieties of radish are placed on the x axis of graph and votes are placed on the y axis of the plot. 

Radish survey

In this blog,am performing a  radish survey by using strings.Considering myself as a greengrocer i have to find out the following objectives:
1.To find out which is the most popular radish variety
2.To find out which is the least popular
3.To check whether anyone voted twice in the survey

            For finding out the popular radish variety we have to consider the survey that have been done and import them.The text file that is containing the survey has name,hypen and the name of the variety of radish. To split the data we use the split() function in python so that the data is divided,after the split function.



                       After splitting the votes,we have to inspect the votes that are carried out in the  survey.To know the specific people who have voted for a particular radish variety.Counting votes for each radish variety is a bit time consuming ,you have to know all the names in advance and you have to loop through the file multiple times. You'll need a data structure where you can associate a radish variety with the number of counted for it.A dictionary will be preferable for it

                        In the above screen shot it is shown about the people who have particularly voted for "White Icicle"in the radish survey.  To check whether anyone voted twice in the survey,you will need to make a list of names of everyone who has voted and each time you see a new name,check if its already in the list of names starting with an empty list of names.This is how the radish survey is done.
                        -