{"id":5408,"date":"2020-10-07T19:44:21","date_gmt":"2020-10-07T14:14:21","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=5408"},"modified":"2020-10-07T19:44:23","modified_gmt":"2020-10-07T14:14:23","slug":"advanced-data-visualization-using-matplot","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/advanced-data-visualization-using-matplot\/","title":{"rendered":"Advanced data visualization using matplot"},"content":{"rendered":"\n<p>In the previous article, we examined the basic concepts of <a href=\"https:\/\/www.h2kinfosys.com\/blog\/introduction-to-data-visualization\/\">data visualization<\/a> utilizing matplot. Now we will learn how to plot all the different kinds of possible graphs for analyzing data using matplot.&nbsp;<\/p>\n\n\n\n<p>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\u00a0 pyplot which aids in plotting a figure\u00a0in matplot<\/p>\n\n\n\n<p>\u2022 <strong>plt.plot( ) <\/strong>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.&nbsp;<\/p>\n\n\n\n<p>\u2022 <strong>plot.xlabel<\/strong>, <strong>plt.ylabel <\/strong>for labeling x and y-axis respectively.&nbsp;<\/p>\n\n\n\n<p>\u2022 <strong>plt.xticks<\/strong>, <strong>plt.yticks <\/strong>for labeling x and y-axis observation tick points respectively.&nbsp;<\/p>\n\n\n\n<p>\u2022 <strong>plt.legend( ) <\/strong>for signifying the observation variables in matplot.\u00a0<\/p>\n\n\n\n<p>\u2022 <strong>plt.title( ) <\/strong>for setting the title of the plot.&nbsp;<\/p>\n\n\n\n<p>\u2022 <strong>plot.show( ) <\/strong>for displaying the plot.&nbsp;<\/p>\n\n\n\n<p>Now we go through the list of the plots we are going to learn now <strong>Here are the Visualization We\u2019ll Design using matplotlib<\/strong><strong>&nbsp; <\/strong>\u2022 Scatter Plot&nbsp;<\/p>\n\n\n\n<p>\u2022 Line Plot&nbsp;<\/p>\n\n\n\n<p>\u2022 Bar Graph&nbsp;<\/p>\n\n\n\n<p>\u2022 Histogram&nbsp;<\/p>\n\n\n\n<p>\u2022 Box Plot&nbsp;<\/p>\n\n\n\n<p>\u2022 Pie Chart<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Scatter Plot <\/strong><strong>&nbsp;<\/strong><\/h2>\n\n\n\n<p>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.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to use a Scatter Plot<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p>\u2022 When you have paired numerical data&nbsp;<\/p>\n\n\n\n<p>\u2022 When your dependent variable may have multiple values for each &nbsp;value of your independent variable&nbsp;<\/p>\n\n\n\n<p>\u2022 When trying to determine whether the two variables are related.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Line Plot<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h2>\n\n\n\n<p>A line chart or line plot is a type of chart that displays information as a&nbsp; series of data points called &#8216;markers&#8217; 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 &nbsp;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&nbsp; cases, they are known as run charts&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to use a Line Plot<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p><strong>\u2022 <\/strong>When we want to show trends chronologically.&nbsp;&nbsp;<\/p>\n\n\n\n<p>\u2022 When we want to clearly display relationships with continuous periodical data.&nbsp;<\/p>\n\n\n\n<p>\u2022 When we want to visualize data changes at a glance<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Bar Graph <\/strong><strong>&nbsp;<\/strong><\/h2>\n\n\n\n<p>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.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to use a Bar Graph<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p>\u2022 Bar charts have a discrete domain of categories and are usually scaled so that all the data can fit on the chart. &nbsp;<\/p>\n\n\n\n<p>\u2022 When there is no natural ordering of the categories being compared, &nbsp;bars on the chart may be arranged in any order. &nbsp;<\/p>\n\n\n\n<p>\u2022 Bar charts arranged from highest to lowest incidence are called&nbsp; Pareto charts.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Histogram <\/strong><strong>&nbsp;<\/strong><\/h2>\n\n\n\n<p>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 &nbsp;shape and spread of continuous sample data&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to Use a Histogram<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p>\u2022 Summarize large data sets graphically&nbsp;<\/p>\n\n\n\n<p>\u2022 Compare measurements to specifications &nbsp;<\/p>\n\n\n\n<p>\u2022 Communicate information to the team&nbsp;<\/p>\n\n\n\n<p>\u2022 Assist in decision making<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Box Plot<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h2>\n\n\n\n<p>In descriptive statistics, a boxplot is a method for graphically depicting groups of numerical data through their quartiles. Box plots may also \u00a0have lines extending from the boxes indicating variability outside the \u00a0upper and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Quartile\" rel=\"nofollow noopener\" target=\"_blank\">lower quartiles<\/a>, hence the terms box-and-whisker plot and\u00a0 box-and-whisker diagram\u00a0<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to use a Box Plot<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p>\u2022 Box Plot is ideal for comparing distributions because the center, &nbsp;spread, and overall range are immediately apparent. &nbsp;<\/p>\n\n\n\n<p>\u2022 A Box Plot is a way of summarizing a set of data measured on an interval scale. &nbsp;<\/p>\n\n\n\n<p>\u2022 Box Plot is often used in exploratory data analysis&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Pie Chart<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h2>\n\n\n\n<p>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 &nbsp;resemblance to a pie which has been sliced, there are variations on the&nbsp; way it can be presented&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>When to use a Pie Chart<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<p>\u2022 Useful for displaying data that is classified into nominal or ordinal &nbsp;categories.&nbsp;<\/p>\n\n\n\n<p>\u2022 Generally used to show percentage or proportional data. <strong>Scatter plot&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<p>General syntax for plotting scatter plot&nbsp;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">scatter('xlabel', 'ylabel', data=obj)&nbsp;&nbsp;\na = np.random.randint(10,50,10)&nbsp;&nbsp;\nb = np.random.randint(10,50,10)&nbsp;\n\nplt.scatter(a,b)&nbsp;&nbsp;\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Output:<\/strong><strong>&nbsp;&nbsp;<\/strong><\/h4>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Y6yT4s9mIGo3kSC-0ujIvZHQkYGgPxKJ8vOwsxWoFYL_ShyuKw_APCO1R3cJlXDgcZNERskntxeZCp-8DZJ6s2FG4Mxq-l11x2CNjxGcv2NVZzIAgR3ZVXL0CxPbKLf0UzFgRub9\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Line plot&nbsp;&nbsp;<\/strong>General syntax for plotting scatter plot&nbsp;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plot('xlabel', 'ylabel', data=obj)&nbsp;&nbsp;\na = np.random.randint(10,50,10)&nbsp; plt.plot(a)&nbsp;<\/pre>\n\n\n\n<p><strong>Output:<\/strong><strong>&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/TVR5L7pmgP-9WWW6RDq38p7sm54lE0hdaIq6UoLekU-DczAukEjdtOslI42uJyZUjRuNWSkhKzDOJRUlf_4fbthWgiXOnNtiS1A3WJGPnfy-xI7DziNk9xne9tH8t_sp8KmLxnNV\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Bar Graph&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">x=[2,5,8,10]&nbsp;&nbsp;\ny=[11,12,16,9]&nbsp;&nbsp;\nx2=[3,9,6,11]&nbsp;&nbsp;\ny2=[6,15,9,7]&nbsp;&nbsp;\nplt.bar(x,y)&nbsp;&nbsp;\nplt.bar(x2,y2,color=\u2018g')&nbsp;&nbsp;\nplt.title('Bar Graphs\u2019)&nbsp;&nbsp;\nplt.xlabel(\u2018x-axis')&nbsp;&nbsp;\nplt.ylabel(\u2018y-axis')&nbsp;<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p><strong>&nbsp;&nbsp;<img fetchpriority=\"high\" decoding=\"async\" width=\"509\" height=\"371\" src=\"https:\/\/lh5.googleusercontent.com\/_RkRetrbe-q4QJgqTYYm0MILReGovgPAELhWsLKOIwUTNM33_UaMYyw6trtui6c2M_kJdLakmiZS4WnrCV6MPCBeZQPkWB2jqW_g8AuYbBYiGRqYJWloWajH4CZD36qIal2x5qsV\" alt=\"\" title=\"\"><\/strong><\/p>\n\n\n\n<p><strong>Histogram&nbsp;&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = np.random.randint(10,50,10)&nbsp; plt.hist(a)&nbsp;&nbsp;\nplt.title(\u2018Histogram\u2019)\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><strong>&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/vlLr8OtyyByG0pp9NCjIX-qQhjvQGz-7Cq9oeCEDomY3y2lCzDftfmwTi9xbogAXcmUNgezc98wXvPEBP30ICRTXFeL9-FvhXXEIoReeJOjw-kSOTGjEA8J7VWHI8-r-SlDrCbP2\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Boxplot :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = [np.random.normal(0, std,100) for std in &nbsp;range(1,4)]<\/pre>\n\n\n\n<p><strong>Output:<\/strong><strong>&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/6B4iBfOH_fXs8Af_WUp3wthiSIUhr7cPBtwS2KguLvQMaUR3SgJv9Y7fXPrYxWeJhYPvWKkM4lNGXwHjsK0gKdAqI32OelKHw3wr2iIGO6jsukPd8UPKQtBtGeNOX6mGMduSQe8f\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Pie Chart&nbsp;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">lables = \u2018python','c++','c','java'&nbsp;&nbsp;\nsizes = [ 215,130,245,210 ]&nbsp;&nbsp;\ncolors = &nbsp;\n['yellowgreen','lightcoral','lightskyblue','gold']&nbsp; explode = (0.1 , 0.2 , 0 , 0.1)&nbsp;&nbsp;\nplt.pie(sizes ,explode=explode,labels=lables ,colors= colors,shadow=True,autopct='%1.1f%%')&nbsp;&nbsp;\nplt.axis('equal')&nbsp;&nbsp;\nplt.show()&nbsp;&nbsp;<\/pre>\n\n\n\n<p><strong>Output:<\/strong><strong>&nbsp;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/eKN57vZ2HYmJ4_cmjaO8fVR4akhMUBhyOGgVEEx4QxykeHTe_y22HZbQXybztAVQft3NKWuU_LSCNv8FX9LE7kjhN1wVKgnlxlkzCnJzKOrYTLguRwY_xSKa8VD6MZLRZ6im0UcS\" alt=\"\" title=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>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.&nbsp; Before getting into the list of available plots in matplot we will just revise the necessary functions for plotting. Generally, while plotting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5435,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[],"class_list":["post-5408","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-using-python-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/5408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=5408"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/5408\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/5435"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=5408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=5408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=5408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}