1. Home
  2. Docs
  3. Advanced Python
  4. Data Visualization
  5. Data Visualization with m...
  6. Other Visualization Plot

Other Visualization Plot

scatter() function plots one dot for each observation

Needs two arrays of same length for the values of x-axis and one for value on yaxis

plt.scatter(x,y) // x and y represents the arrays of same length

To specify the color name of the plots

plt.scatter(x,y,color=‘colorname’)

To change the size of the dots with the s argument. Array of sizes can alsoe be passed

plt.scatter(x,y,size=sz)

Where sz is the array of numbers that depicts the size of each observation

To adjust the transparency of the dots use alpha argument

plt.scatter(x,y,alpha=0.5)

The sale of electric bulb on different days of a week is shown below

daysnumber of electric bulbs (Week 1)number of electric bulbs (Week 2)
Monday1210
Tuesday168
Wednesday814
Thursday109
Friday148
Saturday820
Sunday1822
  • a) Represent the above data with the help of scatter plot for week1 and week2 on same plot
  • b) Give the label for x as days and y as sales
  • c) Give separate color for scatter of week 1 data
  • d) set the transparency of observation to 0.5 for scatter of week 1 data
import matplotlib.pyplot as plt
import pandas as pd
sales = pd.DataFrame({'Days':['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                     'Week1':[12,16,8,10,14,8,18],
                     'Week2':[10,8,14,9,8,20,22]}
                    )
colors = np.array(['red','green','magenta','yellow','orange','blue','cyan'])
plt.scatter(sales['Days'],sales['Week1'],c=colors,alpha=0.5)
plt.scatter(sales['Days'],sales['Week2'])
plt.xlabel('Days')
plt.ylabel('Sales')
plt.title('Sales Data')
plt.plot()
[]

Bar Chart

Intends to compare categorical data across one or two dimensions

The sale of electric bulb on different days of a week is shown below

daysnumber of electric bulbs (Week 1)number of electric bulbs (Week 2)
Monday1210
Tuesday168
Wednesday814
Thursday109
Friday148
Saturday820
Sunday1822
  • a) Represent the above data with the help of bar plot for week1 and week2 as multi bar
  • b) Give the label for x as days and y as sales
  • c) Give separate color for scatter of week 1 data and week 2
  • d) Set the width of the bar as 0.4
import matplotlib.pyplot as plt
import pandas as pd
sales = pd.DataFrame({'Days':['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                     'Week1':[12,16,8,10,14,8,18],
                     'Week2':[10,8,14,9,8,20,22]}
                    )
r = np.arange(7)
plt.bar(r-0.2,sales['Week1'],color='red',width=0.4)
plt.bar(r+0.2,sales['Week2'],color='blue',width=0.4)
plt.xticks(r,sales['Days'])
plt.show()

Histogram

  • It is a graphical representation of a grouped frequency distribution with continuous classes
  • It is an area diagram and can be defined as a set of rectangles with bases along with the intervals between class boundaries
  • Used when the data is numerical
HistogramBar Graph
The frequency is shown by the area of each rectangleThe height shows the frequency and width has no significance
It shows rectangles touching each otherIt consists of rectangles separated from each other with equal spaces

The life time of certain kind of bulb is given below

Life Timenumber of bulbs
25012
37016
4708
4209
52010
56010
22514
9008
43018
33015
31513
  • a) Represent the above data with the help of Histogram: The data should be interpreted as how many bulbs are in the range of [200-300,300-400, 400-500, 500-600, 600-700, 700-800, 800-900, 900-1000]
  • b) Give the label for x as days and y as sales
import matplotlib.pyplot as plt
import pandas as pd
l1 = [250,370,470,420,520,560,225,900,430,330,315]
l2 = [12,16,8,9,10,10,14,8,18,15,13]
bulb = pd.DataFrame({'Life Time':l1,'number of bulbs':l2}
                   )
plt.hist(bulb['Life Time'],bins=[200,300,400,500,600,700,800,900,1000])
plt.title("Result")
plt.xlabel('Life Time')
plt.ylabel('number of bulbs')
plt.show()

Pie Chart

  • Pie chart draws one piece called wedge for each value in the array
  • By default, the plotting of first wedge starts from x coordinate, and moves counter clock wise
  • Size of each wedge is determined by comparing the value with all other values by using: x/ sum(x)

The daily sales (in rupees) of a bakery shop is shown as

ItemsSales in Rupees
Biscuit40
Wheat Bread20
Fruit cake12
choco cake9
Honey cake13
  • a) Represent the above data with the help of pie chart:
  • b) Stand out the item which have maximum sales
  • c) specify the colors for each item
  • d) Show the legend
  • e) start the wedge for an item in 90 degree
  • f) Add the labels to each wedge
  • g) set shadow for each wedge
import matplotlib.pyplot as plt
import pandas as pd
data1 = pd.DataFrame({'Items':['Biscuit','Wheat Bread','Fruit cake','choco cake','Honey cake'],
                     'Sales in Rupees':[40,20,12,9,13]})
plt.pie(data1['Sales in Rupees'],labels=data1['Items'],explode=[0.3,0,0,0,0], colors=['red','green','orange','yellow','cyan'],startangle=90, shadow=True)
plt.legend(loc='lower right')
plt.show()

Box plot

  • A box plot is a graphical way that summarizes the important aspects of the distribution of numeric data
  • Otherwise called as box and Whisker plot
  • Box plot can be drawn either vertically or horizontally
  • The length of the box plot indicates the spread of the data
  • Useful when comparing between several datasets
  • Ordered data are divided into a lower and an upper half by the median.
  • The median of the lower half is the lower quartile.
  • The median of the upper half is the upper quartile.
  • The lower extreme is the least data value.
  • The upper extreme is the greatest data value.

The sale of electric bulb on different days of a week is shown below

daysnumber of electric bulbs (Week 1)number of electric bulbs (Week 2)
Monday1210
Tuesday168
Wednesday814
Thursday109
Friday148
Saturday820
Sunday1822
  • a) Represent the above data with the help of box plot for week1 and week2
  • b) Give the label for x as Groups and y as Summary
import matplotlib.pyplot as plt
import pandas as pd
sales = pd.DataFrame({'Days':['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
                     'Week1':[12,16,8,10,14,8,18],
                     'Week2':[10,8,14,9,8,20,22]}
                    )
plt.boxplot([sales['Week1'],sales['Week2']])

plt.xlabel("Groups")
plt.ylabel("Summary")
plt.show()

Views: 3

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Fashion Styles
1 year ago

I抳e read some good stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to make such a fantastic informative site.