{"id":2716,"date":"2019-08-12T04:48:54","date_gmt":"2019-08-12T04:48:54","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=2716"},"modified":"2024-03-26T07:31:02","modified_gmt":"2024-03-26T07:31:02","slug":"data-visualization-in-python-using-matplotlib-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","title":{"rendered":"Data visualization in Python using MatPlotLib"},"content":{"rendered":"<h1>#Data visualization in Python using MatPlotLib Tutorial<\/h1>\n<p><strong>Data Visualization in Python using MatPlotLib tutorial<\/strong>, Welcome to the world of Python data visualization tutorial. Are you the one who is looking forward to knowing the introduction to data visualization with python? Or the one who is very keen to explore the Data Visualization in Python using MatPlotLib that is available? Then you\u2019ve landed on the Right path which provides the standard information of <a title=\"online course on python\" href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python Programming language<\/a>.<\/p>\n<p><strong>Data Visualization in Python using MatPlotLib <\/strong>is part of the Data Science with an <a title=\"online python course\" href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">online python course<\/a> offered by <a title=\"online python course with certificate\" href=\"https:\/\/prwatech.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prwatech<\/a>. Here, We will learn about the python data visualization tutorials and the use of Python as a Data Visualization tool. Also, we will learn different types of plots, figure functions, axes functions, marker codes, line styles, and many more that you will need to know when visualizing data in Python and how to use them to better understand your own data.<\/p>\n<p>Do you want to know about introduction to data visualization with python, then just follow the below mentioned <strong>Python Data visualization tutorial for Beginners<\/strong> from <a title=\"online course to learn python\" href=\"https:\/\/prwatech.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prwatech<\/a> and take advanced <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python training<\/a> like a Pro from today itself under 10+ years of hands-on experienced Professionals.<\/p>\n<h2>Introduction to Data Visualization in Python using MatPlotLib<\/h2>\n<p>1. MatPlotLib is one of the most important library, provided by <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">python<\/a> for data visualization.<br \/>\n2. It supports both 2D Dimensional and 3D Dimensional graphics.<br \/>\n3. It makes use of NumPy for mathematical operations.<br \/>\n4. It facilitates an object-oriented API that helps in embedding plots in applications using <a title=\"python training course online\" href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python<\/a> GUI toolkits like PyQt, WxPythonotTkinter.<br \/>\n5. Matplotlib requires a large set of dependencies:<br \/>\n6. Python (&gt;= 2.7 or &gt;= 3.4)<br \/>\n7. NumPy<br \/>\n8. setup tools<br \/>\n9. dateutil<br \/>\n10. pyparsing<br \/>\n11. libpng<br \/>\n12. pytz<br \/>\n13. FreeType<br \/>\n14. cycler<br \/>\n15. six<br \/>\n16. matplotlib.pyplot is a library containing the collection of command style functions that enable Matplotlib to work like MATLAB.<\/p>\n<h3>Types of Plots in MatPlotLib<\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Function name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Bar<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to make a bar plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Barh<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a Horizontal bar plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Boxplot<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create box and whisker plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hist<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a histogram<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Hist2d<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a 2D histogram<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Pie<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a Pie chart<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Polar<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a polar plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Scatter<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create scatter plot of x vs y<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Stackplot<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a stacked area plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Stem<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create a Stem plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Step<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to make a Step plot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Quiver<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to plot a 2D field of arrows<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-weight: 400;\">Image Functions in MatPlotLib<\/span><\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Function name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Imread<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to read an image from a file into an array<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Imsave<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to save an array as in image file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Imshow<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to display an image on the axes<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span style=\"font-weight: 400;\">Axes Function MatPlotLib<\/span><\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Axes<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Add axes to a figure<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Text<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to add a text to the axes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Title<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to set a title to a current axes<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Xlable or Ylabel<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to set the label to x-axis or y-axis<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">X-lim or Y-lim<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to set a limit to x-axis or y-axis<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Xticks or Yticks<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used Get or set the x-limits or y-limit of the current tick locations and labels.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Figure<b> Functions in MatPlotLib<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Function Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Figtext<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It adds text to a figure<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Figure<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to create new figure<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Show<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to display a figure<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Savefig<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to save current figure<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Close<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Used to close a figure<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Figure Class in MatPlotLib<\/h3>\n<p>The matplotlib.figure package contains the Figure class.<br \/>\nIt is a top-level container for all kinds of plot elements.<br \/>\nThe Figure object is instantiated by calling the function<br \/>\n<b>figure()<\/b><span style=\"font-weight: 400;\"> from the pyplot package.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><br \/>\n<strong>Syntax:<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400;\">g1=plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><br \/>\n<strong>Parameters of the figure() are as follows:<\/strong><\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Figsize<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Displays width and height in inches<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Dpi<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dots per inches<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Facecolor<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Figure patch face color<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Edgecolor<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Figure patch edge color<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Linewidth<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Edge line width<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Axes<b> Class in MatplotLib<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. Axes object is a region of the image with the data space.\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\">2. A particular figure may contain many Axes, but a given Axes object can only be in a single Figure.\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\">3. The Axes contains two or three Axis objects respective to its dimensions. The Axes class and its member functions are the basic entry point to working with the Object-Oriented interface.<\/span><br \/>\n<span style=\"font-weight: 400;\">4. Axes object is added to the figure by calling a function add_axes().\u00a0<\/span><br \/>\n<span style=\"font-weight: 400;\">5. It returns the axes object and adds axes at position rect [left, bottom, width, height] where all parameters are infractions of figure width and height.<\/span><br \/>\n<span style=\"font-weight: 400;\">6. legend(): Used to label the data with a specific name.<\/span><br \/>\n<span style=\"font-weight: 400;\">7. syntax: ax.legend(handles, labels, loc)<\/span><br \/>\n<span style=\"font-weight: 400;\">8. Where labels are a sequence of strings and handle the sequence of Line2D or Patch instances. loc can be a string or an integer denoting the legend location.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Location String<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Location code<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Best<\/span><\/td>\n<td><span style=\"font-weight: 400;\">0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Upper right<\/span><\/td>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Upper left<\/span><\/td>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Lower right<\/span><\/td>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Lower left<\/span><\/td>\n<td><span style=\"font-weight: 400;\">4<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Right<\/span><\/td>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Center-left<\/span><\/td>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Center-right<\/span><\/td>\n<td><span style=\"font-weight: 400;\">7<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Lower center<\/span><\/td>\n<td><span style=\"font-weight: 400;\">8<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Upper center<\/span><\/td>\n<td><span style=\"font-weight: 400;\">9<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Center<\/span><\/td>\n<td><span style=\"font-weight: 400;\">10<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>axes.plot():<\/b><\/h3>\n<p>It\u00a0<span style=\"font-weight: 400;\">plots values of an array vs another as lines or markers.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The plot() method can have an optional format string argument to specify a specific color, style, and size of line and marker.<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Character<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Color<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018b\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Blue<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018g\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Green<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018r\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Red<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018k\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Black<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018c\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cyan<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018m\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Magenta<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018y\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Yellow<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018w\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">White<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Marker codes in MatPlotLib<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Character<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018.\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Point marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018o\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Circle marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018x\u2019\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">x marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018D\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Diameter marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018H\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hexagon marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018s\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Square marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018+\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Plus marker<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Line Styles in MatPlotLib<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Character<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018-\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Solid line<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018\u2014&#8217;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dashed line<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018-.\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dash-dot line<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">\u2018:\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dotted line<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Ex)<\/strong> <span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = [1, 5, 10, 17, 25,36,49, 64]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x1 = [1, 16, 30, 42,55, 68, 77,88]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x2 = [1,6,12,18,28, 40, 52, 65]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">l1 = ax.plot(x1,y,&#8217;rs-&#8216;) # solid line with yellow colour and square marker<\/span><\/p>\n<p><span style=\"font-weight: 400;\">l2 = ax.plot(x2,y,&#8217;mo&#8211;&#8216;) # dash line with green colour and circle marker<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.legend(labels = (&#8216;hadoop&#8217;, &#8216;datascience&#8217;), loc = &#8216;lower right&#8217;) # legend placed at lower right<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8220;jobs as per sector&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xlabel(&#8216;medium&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;sales&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2717\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/matplot1.png\" alt=\"Data Visualization With MatPlotLib\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/matplot1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/matplot1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Multiplot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">We can plot multiple graphs into a single canvas using multiple subplots.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0Subplot() function returns axes object at a given grid position.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Syntax:<\/span> <span style=\"font-weight: 400;\">plt.subplot(subplot(nrows, ncols, index)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <span style=\"font-weight: 400;\"> import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig,a =\u00a0 plt.subplots(2,2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(2,8)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[0][0].plot(x,x**2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[0][0].set_title(&#8216;square&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[0][1].plot(x,np.sqrt(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[0][1].set_title(&#8216;square root&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[1][0].plot(x,np.exp(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[1][0].set_title(&#8216;exp&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[1][1].plot(x,np.log10(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a[1][1].set_title(&#8216;log&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2718\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot.png\" alt=\"Data Visualization With MatPlotLib Multiplot Output\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>Subplot2grid() Function<\/h3>\n<p><b><span style=\"font-weight: 400;\">It gives more flexibility in creating an axes object at a particular location of the grid.\u00a0<\/span><\/b><\/p>\n<p><span style=\"font-weight: 400;\">It also allows the axes object to be spanned across multiple rows or cols.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Syntax<\/strong>:<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Plt.subplot2grid(shape, location, rowspan, colspan)<\/span><\/p>\n<p><b>Ex)<\/b> <span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1 = plt.subplot2grid((4,4),(0,0),colspan = 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2 = plt.subplot2grid((4,4),(0,2), rowspan = 3)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3 = plt.subplot2grid((4,4),(1,0),rowspan = 2, colspan = 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1 = plt.subplot2grid((4,4),(0,0),colspan = 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2 = plt.subplot2grid((4,4),(0,2), rowspan = 3)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3 = plt.subplot2grid((4,4),(1,0),rowspan = 2, colspan = 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(1,10)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2.plot(x, x**3)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2.set_title(&#8216;cube&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.plot(x, np.exp(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.set_title(&#8216;exp&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3.plot(x, np.log(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3.set_title(&#8216;log&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.tight_layout()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(1,10)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2.plot(x, x**3)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a2.set_title(&#8216;cube&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.plot(x, np.exp(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.set_title(&#8216;exp&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3.plot(x, np.log(x))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a3.set_title(&#8216;log&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.tight_layout()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2719\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot2d.png\" alt=\"Data Visualization With MatPlotLib Subplot2grid() Function output\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot2d.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/subplot2d-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Grid()<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">The grid() function of the axes object sets the visibility of the grid inside a figure to on or off. You can also display major\/minor (or both) ticks of the grid.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Additionally, color, line style, and linewidth properties can be set in the grid() function.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig, axes = plt.subplots(1,3, figsize = (12,4))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(2,22)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[0].plot(x, x**4, &#8216;g&#8217;,lw=2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[0].grid(True)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[0].set_title(&#8216;default grid&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[1].plot(x, np.exp(x), &#8216;r&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[1].grid(color=&#8217;b&#8217;, ls = &#8216;-.&#8217;, lw = 0.25)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[1].set_title(&#8216;custom grid&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[2].plot(x,x)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">axes[2].set_title(&#8216;no grid&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig.tight_layout()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">OutPut:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2720\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid-1024x341.png\" alt=\"Data Visualization With MatPlotLib Grid() output\" width=\"850\" height=\"283\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid-1024x341.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid-300x100.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid-768x256.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/grid.png 1200w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>Setting Limits in MatPlotLib<\/h3>\n<p><span style=\"font-weight: 400;\">This function used to set x-axis limit and y-axis limit in the graph.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1 = fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(1,90)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.plot(x, np.exp(x),&#8217;r&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.set_title(&#8216;exp&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.set_ylim(0,80000)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a1.set_xlim(0,10)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2721\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/limit.png\" alt=\"Data Visualization With MatPlotLib Setting Limits\" width=\"850\" height=\"719\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/limit.png 641w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/limit-300x254.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><b>Setting Ticks and Tick Labels<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">This method will mark data points at the given positions with ticks.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The xticks() and yticks() functions take the list of the object as an argument.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Similarly, labels corresponding to\u00a0 the tick marks can be set using set_xlabels() and set_ylabels() functions respectively.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import math<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.arange(0, math.pi*4, 0.04)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = fig.add_axes([0.2, 0.4, 0.16, 0.26]) # main axes<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = np.sin(x)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.plot(x, y)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xlabel(&#8216;angle&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;sine&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xticks([0,3,6,9])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xticklabels([&#8216;a&#8217;,&#8217;b&#8217;,&#8217;c&#8217;,&#8217;d&#8217;])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_yticks([-1,0,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2722\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ticklables.png\" alt=\"Data Visualization With MatPlotLib Setting Ticks\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ticklables.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ticklables-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>Bar Plot in MatPlotLib<\/h3>\n<p><span style=\"font-weight: 400;\">Used to present the data using rectangular bars with height and width proportional to the value.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It can be plotted vertically as well as horizontally.<\/span><\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"> ax.bar(x, height, width, bottom, align)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The function makes a bar plot with a bound rectangle of size (x \u2212width = 2; x + width=2; bottom; bottom + height).<\/span><\/p>\n<h3>Parameters of bar() functions<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">x<\/span><\/td>\n<td><span style=\"font-weight: 400;\">the sequence of scalars represents an x coordinates of the bars. align controls if x is the bar center (default) or left edge.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">height<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The sequence of scalars represents the height(s) of the bars.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">width<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The width(s) of the bars default 0.8<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">bottom<\/span><\/td>\n<td><span style=\"font-weight: 400;\">y coordinate(s) of the bars default None.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">align<\/span><\/td>\n<td><span style=\"font-weight: 400;\">{\u2018center\u2019, \u2018edge\u2019}, optional, default \u2018center\u2019<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N = 5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">boysMeans = (120, 135, 130, 135, 127)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">girlsMeans = (125, 132, 134, 120, 125)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ind = np.arange(N) # the x locations for the groups<\/span><\/p>\n<p><span style=\"font-weight: 400;\">width = 0.35<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.bar(ind, boysMeans, width, color=&#8217;r&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.bar(ind, girlsMeans, width,bottom=boysMeans, color=&#8217;b&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;Scores&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;Scores by group and gender&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xticks(ind, (&#8216;G1&#8217;, &#8216;G2&#8217;, &#8216;G3&#8217;, &#8216;G4&#8217;, &#8216;G5&#8217;))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_yticks(np.arange(0, 81, 10))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.legend(labels=[&#8216;boys&#8217;, &#8216;girls&#8217;])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OUTPUT:\u00a0<\/strong><\/p>\n<p><span style=\"font-weight: 400;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2723\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar.png\" alt=\"Data Visualization With MatPlotLib Bar Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/span><\/p>\n<h3>Histogram in MatPlotLib<\/h3>\n<p><span style=\"font-weight: 400;\">A histogram is an accurate representation of the distribution of a numerical data set.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It is an estimation of the probability distribution of a continuous variable.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Follow these steps to construct a histogram:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bin the range of values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Divide the entire range of values into a series of intervals.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Count how many values fall into each interval.<\/span><\/p>\n<h3>\u00a0Parameters<\/h3>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">x<\/span><\/td>\n<td><span style=\"font-weight: 400;\">array or a sequence of arrays<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">bin<\/span><\/td>\n<td><span style=\"font-weight: 400;\">integer or sequence\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">range<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It specifies the lower and upper range of the bins<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">density<\/span><\/td>\n<td><span style=\"font-weight: 400;\">If True, then the first element of the return tuple will be counts normalized to form a probability density<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from matplotlib import pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig,ax = plt.subplots(1,1)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.hist(a, bins = [0,25,50,75,100])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8220;histogram of result&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xticks([0,25,50,75,100])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xlabel(&#8216;marks&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;no. of students&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<h3><strong>Pie Chart in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">A Pie Chart can only display a series of data. Pie charts display the size of items in a data series, proportional to the sum of its items.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The data points in the pie chart are displayed as a percentage of the whole pie.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Matplotlib API has a pie() function that creates a pie chart representing data in an array.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The fractional area of each item in a data set is given by x\/sum(x). If the sum(x)&lt; 1, then the values of x display the fractional area directly and the array will not be normalized. The resulting pie will have an empty wedge of size 1 &#8211; sum(x).<\/span><\/p>\n<p><strong>Parameters<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td colspan=\"2\"><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">x<\/span><\/td>\n<td colspan=\"2\"><span style=\"font-weight: 400;\">array-like<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">label<\/span><\/td>\n<td colspan=\"2\"><span style=\"font-weight: 400;\">A sequence of strings providing labels for each wedge.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Colors<\/span><\/td>\n<td colspan=\"2\"><span style=\"font-weight: 400;\">A sequence of matplotlib color arguments through which the pie chart will cycle. If None, then will use the colors in the currently active cycle.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Autopct<\/span><\/td>\n<td colspan=\"2\"><span style=\"font-weight: 400;\">string used to label the items with their numeric value.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The label will be placed inside a wedge.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The format string will be fmt%pct.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from matplotlib import pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.axis(&#8216;equal&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">langs = [&#8216;Statistics&#8217;, &#8216;Python&#8217;, &#8216;Machine Learning&#8217;, &#8216;SQL&#8217;, &#8216;Big Data&#8217;]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">students = [53,27,25,19,12]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.pie(students, labels = langs,autopct=&#8217;%1.2f%%&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2724\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pie.png\" alt=\"Data Visualization With MatPlotLib Histogram\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pie.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pie-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Scatter Plot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Scatter plots are used to plot data points over a horizontal and a vertical axis in an attempt to display how much one variable is affected by another.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Each row in the data table is represented by a marker the position depends on its values in the columns set on the X and Y axes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A third variable may be set to correspond to the color or size of markers, thus adding yet another dimension to the plot.<\/span><\/p>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">girls_marks = [19, 30, 10, 69, 80, 60, 14, 30, 80, 34]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">boys_marks = [90, 29, 49, 48, 100, 48, 38, 45, 20, 30]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">grades_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig=plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax=fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.scatter(grades_range, girls_marks, color=&#8217;r&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.scatter(grades_range, boys_marks, color=&#8217;b&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xlabel(&#8216;Grades Range&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;Grades Scored&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;scatter plot&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2725\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatter.png\" alt=\"Data Visualization With MatPlotLib Scatter Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatter.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatter-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>Contour Plot in MatPlotLib<\/h3>\n<p><span style=\"font-weight: 400;\">Contour plots it is sometimes called as a Level Plots are a way to display a three-dimensional surface over a two-dimensional plane.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It graphs two predictor variables X, Y on the y-axis and a response variable Z as contours. These contours sometimes are called as z-slices or iso-response values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A contour plot is appropriate when you need to see how a value Z changes as a function of two inputs X and Y, i.e.\u00a0 Z = f(X, Y).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0A contour line or isoline of a function for two variables is a curve along which a function has a constant value.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The independent variables x and y are usually restricted to a regular grid called a mesh grid.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The numpy.meshgrid creates a rectangular grid out of an array of x values and an array of y values.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Matplotlib API also contains contour() and contourf() functions that draw contour lines and filled contours, respectively.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Both functions need 3 parameters x, y, and z.<\/span><\/p>\n<p><strong>EX)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">xlist = np.linspace(-8.0, 10.0, 100)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ylist = np.linspace(-8.0, 10.0, 100)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">X, Y = np.meshgrid(xlist, ylist)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Z = np.sqrt(X**4 + Y**4)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig,ax=plt.subplots(1,1)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cp = ax.contourf(X, Y, Z)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig.colorbar(cp) # Add a colorbar to a plot<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;Filled Contours Plot&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">#ax.set_xlabel(&#8216;x (cm)&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;y (cm)&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2726\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Contour.png\" alt=\"Data Visualization With MatPlotLib Contour Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Contour.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Contour-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Quiver Plot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. A quiver plot displays a velocity vector as arrows with components as (u,v) at the points (x,y).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. quiver(x,y,u,v)<\/span><\/p>\n<p><strong>Parameters<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">x<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The x coordinates of the arrow locations<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">y<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The y coordinates of the arrow locations<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">u<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The x components of the arrow vectors<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">v<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The y components of the arrow vectors<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">c<\/span><\/td>\n<td><span style=\"font-weight: 400;\">The arrow colors<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>EX)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x,y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">z = x*np.exp(-x**2 &#8211; y**2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">v, u = np.gradient(z, .2, .2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig, ax = plt.subplots()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">q = ax.quiver(x,y,u,v)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2727\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Quiver.png\" alt=\"MatPlotLib Data Visualization Quiver Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Quiver.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Quiver-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Box Plot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. A box plot that is also called as a whisker plot displays a summary of a set of data containing the minimum, first quartile, median, third quartile, and maximum.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. In a box plot, we plat a box from the first quartile to the third quartile.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. A vertical line goes through the box from the median. The whiskers go from each quartile to the minimum or a maximum.<\/span><\/p>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">-import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">value1 = [82, 76, 24, 40, 67, 62, 71, 79, 81, 22, 98, 89, 78, 67, 72, 82, 87, 66, 56, 52]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">value2 = [12, 25, 11, 35, 36, 32, 96, 95, 3, 90, 95, 32, 27, 55, 100, 12, 1, 451, 37, 21]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">value3 = [23, 89, 12, 78, 72, 89, 25, 69, 68, 86, 19, 49, 15, 16, 16, 75, 65, 31, 25, 52]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">value4 = [99, 33, 75, 66, 83, 61, 82, 98, 10, 87, 29, 72, 26, 23, 72, 88, 78, 99, 75, 30]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">box_plot_data = [value1, value2, value3, value4]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.boxplot(box_plot_data)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2728\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/box1.png\" alt=\"MatPlotLib Data Visualization Box Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/box1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/box1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>Violin Plot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. Violin plots are just like box plots, except that they also display the probability density of data at different values.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. These plots consist of a marker for the median of the data and a box indicating the interquartile range, similar to standard box plots.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Overlaid over this box plot is a kernel density estimation.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. Like box plots, violin plots are used to display a comparison of a variable distribution or sample distribution across different categories.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. A violin plot is actually more informative than a plain box plot.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6. In fact, while a box plot only shows summary statistics just like mean\/median and interquartile ranges, whereas the violin plot shows the full distribution of the data.<\/span><br \/>\n<strong>EX)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">-import numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">np.random.seed(10)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">collectn_1 = np.random.normal(300, 30, 300)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">collectn_2 = np.random.normal(60, 10, 300)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">collectn_3 = np.random.normal(60, 40, 300)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">collectn_4 = np.random.normal(20, 25, 300)<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># combine these different collections into a list<\/span><\/p>\n<p><span style=\"font-weight: 400;\">data_to_plot = [collectn_1, collectn_2, collectn_3, collectn_4]<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Create a figure instance<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Create an axes instance<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = fig.add_axes([0,0,1,1])<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># Create the boxplot<\/span><\/p>\n<p><span style=\"font-weight: 400;\">bp = ax.violinplot(data_to_plot)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2729\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen.png\" alt=\"MatPlotLib Data Visualization Violin Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3>Three Dimensional Plotting in MatPlotLib<\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. All though Matplotlib was initially designed with only 2D plotting into consideration, still some 3D plotting utilities were built on top of Matplotlib&#8217;s 2D display in its later versions, to provide a set of tools for3D data visualization.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. 3D plots are enabled by importing the mplot3d toolkit, included with the Matplotlib package.<\/span><br \/>\n<strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from mpl_toolkits import mplot3d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = plt.axes(projection=&#8217;3d&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">z = np.linspace(0, 2, 200)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = z * np.sin(40 * z)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = z * np.cos(40 * z)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.plot3D(x, y, z, &#8216;red&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;3D line plot&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2730\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/3ds.png\" alt=\"MatPlotLib Data Visualization Dimensional Plotting\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/3ds.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/3ds-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>3D Contour Plot<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. The ax.contour3D() function generates 3D contour plot.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. It needs all the input data to be in the form of two-dimensional regular grids, with the Z-data evaluated at each point.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Here, we will display a 3D contour diagram of a 3D sinusoidal function.<\/span><\/p>\n<p><strong>EX)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from mpl_toolkits import mplot3d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">def f(x, y):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">return np.sin(np.sqrt(x ** 2 + y ** 2))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.linspace(-4, 4, 40)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = np.linspace(-4, 4, 40)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">X, Y = np.meshgrid(x, y)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Z = f(X, Y)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = plt.axes(projection=&#8217;3d&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.contour3D(X, Y, Z, 50, cmap=&#8217;binary&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_xlabel(&#8216;x&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_ylabel(&#8216;y&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_zlabel(&#8216;z&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;3D contour&#8217;)<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2732\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/counter-1.png\" alt=\"MatPlotLib Data Visualization 3D Contour Plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/counter-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/counter-1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>3D Wireframe plot<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. Wireframe plot takes a grid of elements and place it over the specified three-dimensional surface, and can make the resulting 3D forms quite easy to visualize.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. The plot_wireframe() function is used for this purpose<\/span><br \/>\n<strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from mpl_toolkits import mplot3d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">def f(x, y):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">return np.sin(np.sqrt(x ** 2 + y ** 2))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.linspace(-4, 4, 40)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = np.linspace(-4, 4, 40)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">X, Y = np.meshgrid(x, y)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Z = f(X, Y)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = plt.axes(projection=&#8217;3d&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.plot_wireframe(X, Y, Z, color=&#8217;green&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;wireframe&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2735\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wired-1.png\" alt=\"MatPlotLib Data Visualization 3D Wireframe plot\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wired-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wired-1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><strong>3D Surface plot in MatPlotLib<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a01. Surface plot displays a functional relationship between a designated dependent variable (Y), and two independent variables (X and Z).\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. The plot is a companion plot to the contour plot.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a03. A surface plot is just like a wireframe plot, but each face of the wireframe is a filled polygon.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The plot_surface() function x,y and z as arguments.<\/span><\/p>\n<p><strong>Ex)<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">from mpl_toolkits import mplot3d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">numpy as np<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0matplotlib.pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = np.outer(np.linspace(-4, 4, 40), np.ones(40))<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = x.copy().T # transpose<\/span><\/p>\n<p><span style=\"font-weight: 400;\">z = np.cos(x ** 2 + y ** 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">fig = plt.figure()<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax = plt.axes(projection=&#8217;3d&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.plot_surface(x, y, z,cmap=&#8217;viridis&#8217;, edgecolor=&#8217;none&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ax.set_title(&#8216;Surface plot&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2736 size-full\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sureface-1.png\" alt=\"Data Visualization With MatPlotLib 3D Surface plot\" width=\"640\" height=\"480\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sureface-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sureface-1-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>We hope you understand sets in Data visualization in Python using MatPlotLib Tutorial and types of plots in MatPlotLib concepts. Get success in your career as a <a title=\"python training course online\" href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python developer<\/a> by being a part of the <a title=\"python online training in bangalore\" href=\"https:\/\/prwatech.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Prwatech<\/a>, India&#8217;s leading <a title=\"online course on python\" href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Python training institute in Bangalore<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#Data visualization in Python using MatPlotLib Tutorial Data Visualization in Python using MatPlotLib tutorial, Welcome to the world of Python data visualization tutorial. Are you the one who is looking forward to knowing the introduction to data visualization with python? Or the one who is very keen to explore the Data Visualization in Python using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3333,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,1676],"tags":[385,71,541,544,546,542],"class_list":["post-2716","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-python-data-visualization","tag-data-visualization-in-python-using-matplotlib-tutorial","tag-data-visualization-with-matplotlib","tag-online-python-course-for-beginners","tag-online-python-course-with-certificate","tag-online-python-programming-course","tag-online-python-training-course"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Data visualization in Python using MatPlotLib Tutorial | Prwatech<\/title>\n<meta name=\"description\" content=\"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data visualization in Python using MatPlotLib Tutorial | Prwatech\" \/>\n<meta property=\"og:description\" content=\"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-12T04:48:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-26T07:31:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\",\"name\":\"Data visualization in Python using MatPlotLib Tutorial | Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"datePublished\":\"2019-08-12T04:48:54+00:00\",\"dateModified\":\"2024-03-26T07:31:02+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg\",\"width\":960,\"height\":550,\"caption\":\"Data Visualization With MatPlotLib\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Data visualization in Python using MatPlotLib\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data visualization in Python using MatPlotLib Tutorial | Prwatech","description":"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Data visualization in Python using MatPlotLib Tutorial | Prwatech","og_description":"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.","og_url":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2019-08-12T04:48:54+00:00","article_modified_time":"2024-03-26T07:31:02+00:00","og_image":[{"width":960,"height":550,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","type":"image\/jpeg"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","url":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/","name":"Data visualization in Python using MatPlotLib Tutorial | Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","datePublished":"2019-08-12T04:48:54+00:00","dateModified":"2024-03-26T07:31:02+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Explore Data visualization in Python using MatPlotLib Tutorial concepts and learn introduction to data visualization, from Prwatech.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Data-Visualization-With-MatPlotLib.jpg","width":960,"height":550,"caption":"Data Visualization With MatPlotLib"},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/python\/python-data-visualization\/data-visualization-in-python-using-matplotlib-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Data visualization in Python using MatPlotLib"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=2716"}],"version-history":[{"count":19,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716\/revisions"}],"predecessor-version":[{"id":11105,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2716\/revisions\/11105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media\/3333"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=2716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=2716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=2716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}