

{"id":79300,"date":"2020-07-27T10:58:50","date_gmt":"2020-07-27T05:28:50","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=79300"},"modified":"2021-05-09T13:13:30","modified_gmt":"2021-05-09T07:43:30","slug":"numpy-matplotlib-tutorial","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/","title":{"rendered":"Introduction to NumPy Matplotlib for Beginners"},"content":{"rendered":"<p>Python is a really useful tool for data science implementations. We prefer it because of the wide range of libraries and packages available in Python.<\/p>\n<p>NumPy along with Matplotlib is a fundamental feature of Python. It helps to ease data interpretation and visualization. We implement the plotting functions in NumPy with the use of Matplotlib.<\/p>\n<h2>NumPy Matplotlib Tutorial<\/h2>\n<p>Let us firstly see what is Matplotlib?<\/p>\n<p>We use Matplotlib to ease the analysis of statistical data. Matplotlib is a visualization tool and hence provides a visual analysis of the data.<\/p>\n<p>Matplotlib is an effective replacement for the MatLab tool. It contains all the requirements for replacements. It is also effective when put to use with other GUI toolkits. We can use it alongside Tkinter and pyqt packages.<\/p>\n<p>We can access matplotlib by importing its subpackage pyplot.<\/p>\n<p><strong>from matplotlib import pyplot as plt<\/strong><\/p>\n<p>The pyplot() function is very useful for demonstrating 2-D array plots.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nfrom matplotlib import pyplot as plt \r\n \r\nx = np.arange(10) \r\ny = 2 * x + 4\r\n \r\nplt.xlabel(\"x axis\") \r\nplt.ylabel(\"y axis\") \r\nplt.plot(x,y) \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79810\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one.png\" alt=\"Matplotlib\" width=\"563\" height=\"399\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one.png 563w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one-300x213.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one-150x106.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/one-520x369.png 520w\" sizes=\"auto, (max-width: 563px) 100vw, 563px\" \/><\/a><\/p>\n<h2>Matplotlib Basics<\/h2>\n<p>These are some basic functions available in Matplotlib :<\/p>\n<h3>1. Labels<\/h3>\n<p>We use this function to provide label tags for the x and y-axis of the graph. We use <strong>plt.xlabel() <\/strong>and <strong>plt.ylabel() <\/strong>for labeling x and y-axis respectively.<\/p>\n<h3>2. Title<\/h3>\n<p>We use <strong>plt.title()<\/strong> to provide a title to the plot.<\/p>\n<h3>3. Ticks<\/h3>\n<p>It provides us with the choice of label position. It is to make the plots user friendly. We use the <strong>plt.xticks() <\/strong>for x-axis and <strong>plt.yticks()<\/strong> for y-axis.<\/p>\n<h3>4. Plot size<\/h3>\n<p>We use the <strong>plt.figure()<\/strong> function to set the plot size. We can change the default size by providing a tuple value for the length of rows and columns.<\/p>\n<h3>5. Subplot<\/h3>\n<p>We can make subplots in an existing plot. We use the <strong>plt.subplot()<\/strong> function in this case. Three arguments namely:<strong> nrows()<\/strong>, <strong>ncols()<\/strong>, and <strong>index()<\/strong>are provided for the number of rows, columns, and the index values of each respectively.<\/p>\n<h3>6. Subplots<\/h3>\n<p>This is similar to subplots but is easier to understand. It has separate values for the figure and the axes.<\/p>\n<p>These functions map to the simple line plot. The <strong>plt.plot()<\/strong> function gives the basic line plot. It takes 2 arrays as input. We use the <strong>plt.show()<\/strong> method to display the graph. We have a range of plots available for graphical representation in matplotlib.<\/p>\n<p><strong>Matplotlib Formatting Characters for plot<\/strong><\/p>\n<table style=\"height: 1683px;\" width=\"481\">\n<tbody>\n<tr>\n<td><strong>Sr No.<\/strong><\/td>\n<td><strong>Character\u00a0<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\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;\">2<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018&#8211;\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dashed line<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">3<\/span><\/td>\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;\">4<\/span><\/td>\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<tr>\n<td><span style=\"font-weight: 400;\">5<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018.\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Point marker\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">6<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018,\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Pixel marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">7<\/span><\/td>\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;\">8<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018v\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Triangle down marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">9<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018^\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Triangle up marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">10<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018&lt;\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Triangle left marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">11<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018&gt;\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Triangle right marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">12<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u20181\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tri down marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">13<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u20182\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tri up marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">14<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u20183\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tri left marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">15<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u20184\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tri right marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">16<\/span><\/td>\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;\">17<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018p\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Pentagon marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">18<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018*\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Star marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">19<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018h\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hexagon1 marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">20<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018H\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hexagon2 marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">21<\/span><\/td>\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<tr>\n<td><span style=\"font-weight: 400;\">22<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018x\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">23<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018d\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Thin diamond marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">24<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018D\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Diamond marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">25<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018|\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Vline marker<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">26<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u2018_\u2019<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Hline marker<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Matplotlib Color abbreviations<\/strong><\/p>\n<table style=\"height: 561px;\" width=\"481\">\n<tbody>\n<tr>\n<td><strong>Sr no.<\/strong><\/td>\n<td><strong>Abbreviation<\/strong><\/td>\n<td><strong>color<\/strong><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">1<\/span><\/td>\n<td><span style=\"font-weight: 400;\">&#8216;b&#8217;<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Blue<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">2<\/span><\/td>\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;\">3<\/span><\/td>\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;\">4<\/span><\/td>\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;\">5<\/span><\/td>\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;\">6<\/span><\/td>\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;\">7<\/span><\/td>\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;\">8<\/span><\/td>\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<h2>Different Types of Plots in Matplotlib<\/h2>\n<p>There are different varieties of graphs available in matplotlib for providing a better understanding of the data set.<\/p>\n<h3>1. Bar graph in matplotlib<\/h3>\n<p>It is a very useful type of plot when we have categories of the data. We use it to depict the values in each category by the height of the bars. We can use<strong> plt.bar()<\/strong> function for bar graph and <strong>plt.barh()<\/strong> for horizontal bar graph.<\/p>\n<p>There can be horizontal and vertical bar graphs. The horizontal bar graphs denote the width and index position. The vertical graphs denote a bottom argument.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import matplotlib.pyplot as plt\r\nplot = plt.figure()\r\nchars = ['A','B','C']\r\nvalues = [7,9,3]\r\nplt.bar(chars,values)\r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79812\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1.png\" alt=\"bar plot in matplotlib\" width=\"711\" height=\"356\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1.png 711w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1-300x150.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1-150x75.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code-1-520x260.png 520w\" sizes=\"auto, (max-width: 711px) 100vw, 711px\" \/><\/a><\/p>\n<h3>2. Histogram in Matplotlib<\/h3>\n<p>Histograms are useful when depicting the distribution of a single variable. It helps in the visualization of the variation of a single variable. The histogram can be plot using the <strong>plt.hist()<\/strong> function. We can customize Histograms accordingly using different arguments.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np\r\nimport matplotlib.pyplot as plt\r\n \r\nx = [20,40,60,90,40,50,20,70,30,20,10,90]\r\nnum_bins= 5\r\nplt.hist(x,num_bins)\r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code2-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79813\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code2-1.png\" alt=\"histogram in matplotlib\" width=\"442\" height=\"357\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code2-1.png 442w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code2-1-300x242.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code2-1-150x121.png 150w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><\/p>\n<h3>3. Scatter Plot in Matplotlib<\/h3>\n<p>It is also a useful type of plot. It is mainly useful when we want to perform data comparison. We use it mainly for making different comparisons amongst the observations. We use<strong> plt.scatter()<\/strong>for this plot.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import matplotlib.pyplot as plt\r\narr1= [44,56,73,89,20,45,31]\r\narr2 = [10, 20, 30, 40, 50, 60, 70]\r\nfig=plt.figure()\r\nplt.scatter(arr2,arr1,color='r')\r\nplt.show()\r\n \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79817\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code3.png\" alt=\"scatter plot in matplotlib\" width=\"458\" height=\"341\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code3.png 458w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code3-300x223.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/code3-150x112.png 150w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/a><\/p>\n<h3>4. Box Plot in Matplotlib<\/h3>\n<p>We use it to represent a summary of the data. It displays five things \u2013 the minimum value, the first quartile, the median, the third quartile, and the maximum value. We can plot it using the <strong>plt.boxplot() <\/strong>function.<\/p>\n<h3>5. Sine wave Plot in Matplotlib<\/h3>\n<p>We use matplotlib to plot trigonometric functions. We can plot the sine wave using plotting functions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nimport matplotlib.pyplot as plt  \r\n \r\n \r\nx = np.arange(0, 2 * np.pi, 0.2) \r\ny = np.sin(x) \r\nplt.title(\"sine wave \") \r\n \r\n# Plotting the sine wave\r\n \r\nplt.plot(x, y) \r\nplt.show() \r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/five.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79816\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/five.png\" alt=\"\" width=\"397\" height=\"429\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/five.png 397w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/five-278x300.png 278w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/five-139x150.png 139w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<h3>6. Subplot() in Matplotlib<\/h3>\n<p>We use subplot for plotting two different graphs. We can plot two different graphs in one figure. Here we take an example to plot both sine and cos graphs together.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nimport matplotlib.pyplot as plt  \r\n \r\nx = np.arange(0, 5 * np.pi, 0.5) \r\ny_sin = np.sin(x) \r\ny_cos = np.cos(x)  \r\nplt.subplot(2, 2, 2)\r\nplt.plot(x, y_sin) \r\n \r\n   \r\nplt.subplot(2, 2, 2) \r\nplt.plot(x, y_cos) \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/pasted-image-0-14.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79912\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/pasted-image-0-14.png\" alt=\"\" width=\"188\" height=\"130\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/pasted-image-0-14.png 188w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/pasted-image-0-14-150x104.png 150w\" sizes=\"auto, (max-width: 188px) 100vw, 188px\" \/><\/a><\/p>\n<h2>Customization of Graphs in Matplotlib<\/h2>\n<p>We can perform customization on graphs to make it more presentable and user friendly. We can make it more attractive by adding colors and lines.<\/p>\n<h3>1. Color<\/h3>\n<p>We can specify the color of the graph as an argument. We can pass the name of the color as a string.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nfrom matplotlib import pyplot as plt \r\n \r\nx = np.arange(10) \r\ny = 2 * x + 4\r\n \r\nplt.xlabel(\"x axis\") \r\nplt.ylabel(\"y axis\") \r\nplt.plot(x,y, color='red') \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/two.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79811\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/two.png\" alt=\"bar graph in matplotlib\" width=\"401\" height=\"388\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/two.png 401w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/two-300x290.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/two-150x145.png 150w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/a><\/p>\n<h3>2. Marker in Matplotlib<\/h3>\n<p>Markers represent the points of the plot. We can change the type of marker by passing a string parameter specifying the type.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nfrom matplotlib import pyplot as plt \r\n \r\nx = np.arange(10) \r\ny = 2 * x + 4\r\n \r\nplt.xlabel(\"x axis\") \r\nplt.ylabel(\"y axis\") \r\nplt.plot(x,y, marker='x') \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/three.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79814\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/three.png\" alt=\"marker in matplotlib\" width=\"450\" height=\"410\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/three.png 450w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/three-300x273.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/three-150x137.png 150w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<h3>3. Linestyle in Matplotlib<\/h3>\n<p>We can define the type of line of the plot. We can pass it the type as a string argument.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import numpy as np \r\nfrom matplotlib import pyplot as plt \r\n \r\nx = np.arange(10) \r\ny = 2 * x + 4\r\n \r\nplt.xlabel(\"x axis\") \r\nplt.ylabel(\"y axis\") \r\nplt.plot(x,y, linestyle=':') \r\nplt.show()\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/four.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79815\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/four.png\" alt=\"matplotlib\" width=\"472\" height=\"395\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/four.png 472w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/four-300x251.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/four-150x126.png 150w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Matplotlib is a very useful feature of the NumPy library. It is meant to ease data interpretation. The functions available allows for visual interpretation of the data. The visual representation makes the use of data more user-friendly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is a really useful tool for data science implementations. We prefer it because of the wide range of libraries and packages available in Python. NumPy along with Matplotlib is a fundamental feature of&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":79809,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22401],"tags":[22784],"class_list":["post-79300","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-numpy","tag-numpy-matplotlib"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Introduction to NumPy Matplotlib for Beginners - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn Numpy Matplotlib Tutorial to learn basics of Matplotlib. Learn various types of matplotlib charts like histogram, bar chart, scatter plot,box plot etc\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to NumPy Matplotlib for Beginners - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn Numpy Matplotlib Tutorial to learn basics of Matplotlib. Learn various types of matplotlib charts like histogram, bar chart, scatter plot,box plot etc\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-27T05:28:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-09T07:43:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to NumPy Matplotlib for Beginners - DataFlair","description":"Learn Numpy Matplotlib Tutorial to learn basics of Matplotlib. Learn various types of matplotlib charts like histogram, bar chart, scatter plot,box plot etc","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to NumPy Matplotlib for Beginners - DataFlair","og_description":"Learn Numpy Matplotlib Tutorial to learn basics of Matplotlib. Learn various types of matplotlib charts like histogram, bar chart, scatter plot,box plot etc","og_url":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-07-27T05:28:50+00:00","article_modified_time":"2021-05-09T07:43:30+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Introduction to NumPy Matplotlib for Beginners","datePublished":"2020-07-27T05:28:50+00:00","dateModified":"2021-05-09T07:43:30+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/"},"wordCount":913,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg","keywords":["NumPy Matplotlib"],"articleSection":["NumPy Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/","url":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/","name":"Introduction to NumPy Matplotlib for Beginners - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg","datePublished":"2020-07-27T05:28:50+00:00","dateModified":"2021-05-09T07:43:30+00:00","description":"Learn Numpy Matplotlib Tutorial to learn basics of Matplotlib. Learn various types of matplotlib charts like histogram, bar chart, scatter plot,box plot etc","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/07\/Types-of-Matplotlib-Plots-in-NumPy.jpg","width":1200,"height":628,"caption":"Numpy Matplotlib Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/numpy-matplotlib-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"NumPy Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/numpy\/"},{"@type":"ListItem","position":3,"name":"Introduction to NumPy Matplotlib for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=79300"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79300\/revisions"}],"predecessor-version":[{"id":93199,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/79300\/revisions\/93199"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/79809"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=79300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=79300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=79300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}