All IT Courses 50% Off
Data Science using Python Tutorials

Advanced data visualization using matplot

In the previous article, we examined the basic concepts of data visualization utilizing matplot. Now we will learn how to plot all the different kinds of possible graphs for analyzing data using matplot. 

Before getting into the list of available plots in matplot we will just revise the necessary functions for plotting. Generally, while plotting we will follow the same steps for every plot. Matplotlib has a module called  pyplot which aids in plotting a figure in matplot

plt.plot( ) for plotting line plot. Similarly for other plots other functions are used . All plotting functions require data and it is provided in the function through parameters. 

plot.xlabel, plt.ylabel for labeling x and y-axis respectively. 

plt.xticks, plt.yticks for labeling x and y-axis observation tick points respectively. 

plt.legend( ) for signifying the observation variables in matplot. 

plt.title( ) for setting the title of the plot. 

plot.show( ) for displaying the plot. 

Now we go through the list of the plots we are going to learn now Here are the Visualization We’ll Design using matplotlib  • Scatter Plot 

• Line Plot 

• Bar Graph 

• Histogram 

• Box Plot 

• Pie Chart

Scatter Plot  

A scatter plot also called a scattergram, or scatter diagram is a type of plot or mathematical diagram using Cartesian coordinates to display values for typically two variables for a set of data. If the points are coded (color/shape/size), one additional variable can be displayed. The data are displayed as a collection of points, each having the value of one variable determining the position on the horizontal axis and the value of the other variable determining the position on the vertical axis. 

When to use a Scatter Plot  

• When you have paired numerical data 

• When your dependent variable may have multiple values for each  value of your independent variable 

• When trying to determine whether the two variables are related.

Line Plot  

A line chart or line plot is a type of chart that displays information as a  series of data points called ‘markers’ connected by straight line segments. It is a basic type of chart common in many fields. It is similar to a scatter plot except that the measurement points are ordered typically by their x-axis value and joined with straight line segments. A  line chart is often used to visualize a trend in data over intervals of time a time series thus the line is often drawn chronologically. In these  cases, they are known as run charts 

When to use a Line Plot  

When we want to show trends chronologically.  

• When we want to clearly display relationships with continuous periodical data. 

• When we want to visualize data changes at a glance

Bar Graph  

A bar chart or bar graph is a chart or graph that presents categorical data with rectangular bars with heights or lengths proportional to the values they represent. The bars can be plotted vertically or horizontally. A vertical bar chart is sometimes called a column chart. A bar graph shows comparisons among discrete categories. One axis of the chart shows the specific categories being compared, and the other axis represents a measured value. Some bar graphs present bars clustered in groups of more than one, showing the values of more than one measured variable. 

When to use a Bar Graph  

• Bar charts have a discrete domain of categories and are usually scaled so that all the data can fit on the chart.  

• When there is no natural ordering of the categories being compared,  bars on the chart may be arranged in any order.  

• Bar charts arranged from highest to lowest incidence are called  Pareto charts. 

Histogram  

A histogram is a graphical display of data using bars of different heights. In a histogram, each bar group numbers into ranges. Taller bars show that more data falls in that range. A histogram displays the  shape and spread of continuous sample data 

When to Use a Histogram  

• Summarize large data sets graphically 

• Compare measurements to specifications  

• Communicate information to the team 

• Assist in decision making

Box Plot  

In descriptive statistics, a boxplot is a method for graphically depicting groups of numerical data through their quartiles. Box plots may also  have lines extending from the boxes indicating variability outside the  upper and lower quartiles, hence the terms box-and-whisker plot and  box-and-whisker diagram 

When to use a Box Plot  

• Box Plot is ideal for comparing distributions because the center,  spread, and overall range are immediately apparent.  

• A Box Plot is a way of summarizing a set of data measured on an interval scale.  

• Box Plot is often used in exploratory data analysis 

Pie Chart  

A pie chart or a circle chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportions. In a pie chart, the arc length of each slice and consequently its central angle and area are proportional to the quantity it represents. While it is named for its  resemblance to a pie which has been sliced, there are variations on the  way it can be presented 

When to use a Pie Chart  

• Useful for displaying data that is classified into nominal or ordinal  categories. 

• Generally used to show percentage or proportional data. Scatter plot  

General syntax for plotting scatter plot  

scatter('xlabel', 'ylabel', data=obj)  
a = np.random.randint(10,50,10)  
b = np.random.randint(10,50,10) 

plt.scatter(a,b)  

Output:  

Advanced data visualization using matplot

Line plot  General syntax for plotting scatter plot  

plot('xlabel', 'ylabel', data=obj)  
a = np.random.randint(10,50,10)  plt.plot(a) 

Output: 

Advanced data visualization using matplot

Bar Graph  

x=[2,5,8,10]  
y=[11,12,16,9]  
x2=[3,9,6,11]  
y2=[6,15,9,7]  
plt.bar(x,y)  
plt.bar(x2,y2,color=‘g')  
plt.title('Bar Graphs’)  
plt.xlabel(‘x-axis')  
plt.ylabel(‘y-axis') 

Output:

  Advanced data visualization using matplot

Histogram  

a = np.random.randint(10,50,10)  plt.hist(a)  
plt.title(‘Histogram’)

Output: 

Advanced data visualization using matplot

Boxplot :

a = [np.random.normal(0, std,100) for std in  range(1,4)]

Output: 

Advanced data visualization using matplot

Pie Chart 

lables = ‘python','c++','c','java'  
sizes = [ 215,130,245,210 ]  
colors =  
['yellowgreen','lightcoral','lightskyblue','gold']  explode = (0.1 , 0.2 , 0 , 0.1)  
plt.pie(sizes ,explode=explode,labels=lables ,colors= colors,shadow=True,autopct='%1.1f%%')  
plt.axis('equal')  
plt.show()  

Output: 

Advanced data visualization using matplot
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close