{"id":3925,"date":"2020-08-24T11:28:44","date_gmt":"2020-08-24T05:58:44","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=3925"},"modified":"2024-01-01T14:55:20","modified_gmt":"2024-01-01T09:25:20","slug":"matplotlib-bar","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/matplotlib-bar\/","title":{"rendered":"Matplotlib Bar | Creating Bar Charts Using Bar Function"},"content":{"rendered":"\n<p>We, humans, are great at understanding the visuals rather than going through numerical data. It becomes very easy for us to find insights from a <strong>graph, a pie chart, or any other visual<\/strong>. We make different types of graphs for different types of data. For example, if we have lots of data <a href=\"http:\/\/www.pythonpool.com\/matplotlib-2d-histogram\/\" target=\"_blank\" rel=\"noreferrer noopener\">about the <strong>distribution of salary in a company, so will we will make a histogram<\/strong><\/a>. But if we have data on fruits and vegetables sold for the years 2015, 2016, 2017, we will make a <strong>bar chart<\/strong>.<\/p>\n\n\n\n<p><strong>Matplotlib Bar is a method in Python which allows you to plot traditional bar graphs. These bar graphs can be colorized, resized, and can be customized heavily. In today\u2019s article, we will learn more about how to create a bar chart in python using the matplotlib bar function.&nbsp;<\/strong><\/p>\n\n\n\n<p>To better understand BarCharts, let us see how we can represent certain data in a bar chart.&nbsp;<\/p>\n\n\n\n<p>Suppose we have data on the number of students who study various technologies.&nbsp;&nbsp;<\/p>\n\n\n\n<p><strong>Technologies = [&#8216;Data Science&#8217;, &#8216;Cyber Security&#8217;, &#8216;Web Development&#8217;, &#8216;Android Development&#8217;, &#8216;Data Analyst&#8217;]&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>No. Of students in these technologies = [78,49,112,129,59]&nbsp;<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"375\" height=\"347\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1.png\" alt=\"matplotlib bar\" class=\"wp-image-3926\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1.png 375w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1-300x278.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/figure><\/div>\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Syntax_of_Matplotlib_Bar\" >Syntax of Matplotlib Bar&nbsp;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Parameters\" >Parameters-&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Return_Type\" >Return Type:&nbsp;<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Making_Bars_in_Python_using_Matplotlib_Bar_Function\" >Making Bars in Python using Matplotlib Bar Function&nbsp;<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Making_our_First_Bar_Graph_in_Python\" >Making our First Bar Graph in Python&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#How_to_change_the_colors_of_the_bar_and_border-color\" >How to change the colors of the bar and border-color<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#How_to_build_multi-column_bar_graphs\" >How to build multi-column bar graphs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#How_to_make_stacked_bar_charts_using_matplotlib_bar\" >How to make stacked bar charts using matplotlib bar<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Horizontal_Bar_Graph_using_Matplotlib_barh\" >Horizontal Bar Graph using Matplotlib barh<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Making_Bar_Chart_using_Pandas_Data_Frame\" >Making Bar Chart using Pandas Data Frame<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Must_Read\" >Must Read:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-syntax-of-matplotlib-bar\"><span class=\"ez-toc-section\" id=\"Syntax_of_Matplotlib_Bar\"><\/span>Syntax of Matplotlib Bar&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To use matplotlib and its bar function, we must first install the matplotlib module using \u2013 <strong>pip install matplotlib.<\/strong>&nbsp;&nbsp;<\/p>\n\n\n\n<p>The bar() is a function of pyplot submodule, we have to <strong>import pyplot<\/strong> submodule along with matplotlib module like this-&nbsp;<\/p>\n\n\n\n<p><strong><em>import matplotlib.pyplot&nbsp;<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>bar( x, height, width=0.8, bottom=None, align=&#8217;center&#8217;, **kwargs)&nbsp;<\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-parameters\"><span class=\"ez-toc-section\" id=\"Parameters\"><\/span>Parameters-&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>X<\/strong>: In this parameter, we have to give the values to the x-axis. Like in the above example, we would list all the technologies in the \u2018x\u2019 parameter. The value can be a list or floating-point value.&nbsp;<\/li>\n\n\n\n<li><strong>Height<\/strong>: In this parameter, we give the heights of the values on the x-axis. We can say that it is the y-axis of the graph.&nbsp;<\/li>\n\n\n\n<li><strong>Width:<\/strong> Here, we can mention the width of each bar. By default, the value is 0.8. To make the bar thin, use values less than 0.8, and for the thicker bar, use values greater than 0.8.&nbsp;<\/li>\n\n\n\n<li>&nbsp;<strong>Bottom<\/strong>: In this parameter, we give the lowermost value, or you can say the starting value of the y-axis.&nbsp;<\/li>\n\n\n\n<li><strong>Align<\/strong>: Here we tell where we want to start the names in x-axis from. By default, the value is \u2018centre.\u2019 Another option is \u2018edge.\u2019 We will understand it better using an example.&nbsp;<\/li>\n\n\n\n<li><strong>Kwargs<\/strong>&#8211; In this parameter, we can use parameters like color, edge color, and many more.&nbsp;<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-return-type\"><span class=\"ez-toc-section\" id=\"Return_Type\"><\/span>Return Type:&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><em>This function returns a BARCONTAINER.&nbsp;<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-making-bars-in-python-using-matplotlib-bar-function\"><span class=\"ez-toc-section\" id=\"Making_Bars_in_Python_using_Matplotlib_Bar_Function\"><\/span>Making Bars in Python using Matplotlib Bar Function&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-making-our-first-bar-graph-in-python\"><span class=\"ez-toc-section\" id=\"Making_our_First_Bar_Graph_in_Python\"><\/span>Making our First Bar Graph in Python&nbsp;<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Let us make the graph of the technologies vs. the number of students studying that technology.&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# imporitng the pyplot submodule of matplotlib module and\n# giving the alias\/nickname as plt.\nimport matplotlib.pyplot as plt\n# initializing the x-axis data\ntechnologies=&#x5B;'Data Science', 'Cyber Security', 'Web Development', 'Android Development', 'Data Analyst'] \n# initializing the y-axis data\nnumber_of_students=&#x5B;78,49,112,129,59]\n# Giving the bar function x axis as technologies\n# and height as number_of_students\nplt.bar(x=technologies,height=number_of_students)\n# As the name of technologies are too long,\n# let us rotate the title of x axis by 90 degree.\nplt.xticks(rotation=90)\n# without the plt.show(), the bar will not be created\nplt.show()\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" width=\"375\" height=\"347\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1-1.png\" alt=\"matplotlib bar\" class=\"wp-image-3927\" style=\"width:375px;height:347px\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1-1.png 375w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_1-1-300x278.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-change-the-colors-of-the-bar-and-border-color\"><span class=\"ez-toc-section\" id=\"How_to_change_the_colors_of_the_bar_and_border-color\"><\/span>How to change the colors of the bar and border-color<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We can also change the color of the bar which is by default blue. We can either use color=&#8217;r&#8217; or color=&#8217;red&#8217;. Also, we can add border color to make the bar more differentiable. We can also give the hex code values of particular values in the color parameter.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\ntechnologies=&#x5B;'Data Science', 'Cyber Security', 'Web Development', 'Android Development', 'Data Analyst'] \nnumber_of_students=&#x5B;78,49,112,129,59]\n# Adding color and border-color using color and edge color parameters\nplt.bar(x=technologies,height=number_of_students,color=&quot;#00FFFF&quot;,edgecolor=&quot;r&quot;)\nplt.xticks(rotation=90)\n# without the plt.show(), the bar will not be created\nplt.show()\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"375\" height=\"347\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_3.png\" alt=\"change the colors of the bar\" class=\"wp-image-3947\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_3.png 375w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_3-300x278.png 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-build-multi-column-bar-graphs\"><span class=\"ez-toc-section\" id=\"How_to_build_multi-column_bar_graphs\"><\/span>How to build multi-column bar graphs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Multiple bar charts in the same graphs are generally used when we have to compare two or more types. <strong>Like Male and Female.<\/strong> We can use the align parameter to change the position of the x-ticks.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np \nimport matplotlib.pyplot as plt \n%matplotlib inline\n\n# set width of bar \nwidth = 0.3\n# set the y axis of bar \nMale = &#x5B;22,43,30,29,35] \nFemale = &#x5B;27,23,40,39,22] \n\n# Set position of bar on X axis \nfemale_bar = np.arange(len(Female)) \nmale_bar = &#x5B;x + width for x in female_bar] \n\n# Make the plot and set different colors for different genders\n# We can also add edgecolor which will give bordercolor between # # the bar \nplt.bar(female_bar, Female, color ='y', width =width, edgecolor ='blue', label ='Female',align='edge') \nplt.bar(male_bar, Male, color ='r', width = width, edgecolor ='blue', label ='Male',align='edge') \n\n# Adding Xlabel\nplt.xlabel('Years') \n# Adding Ylabel\nplt.ylabel('Number of people per gender') \n# Adding the years in x axis\nplt.xticks(&#x5B;r + width for r in range(len(Female))], &#x5B;'2015', '2016', '2017', '2018', '2019']) \nplt.legend()\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"382\" height=\"262\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar4.png\" alt=\"build multi-column bar graphs\" class=\"wp-image-3948\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar4.png 382w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar4-300x206.png 300w\" sizes=\"(max-width: 382px) 100vw, 382px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-make-stacked-bar-charts-using-matplotlib-bar\"><span class=\"ez-toc-section\" id=\"How_to_make_stacked_bar_charts_using_matplotlib_bar\"><\/span>How to make stacked bar charts using matplotlib bar<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Stack bar charts are those bar charts that have one or more bars on top of each other<\/strong>. They are generally used when <em>we need to combine multiple values into something greater.<\/em><\/p>\n\n\n\n<p>Let us make a stacked bar <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chart\" target=\"_blank\" rel=\"noreferrer noopener\">chart<\/a> which we represent the sale of some product for the month of January and February. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nJAN = &#x5B;70,80,56,29]\nFEB = &#x5B;33,46,90,49]\nwidth=0.5\nx_axis=len(JAN)\nplt.bar(range(x_axis), JAN,color=&quot;red&quot;,label=&quot;JANUARY&quot;)\nplt.bar(range(x_axis), FEB, bottom=JAN,color=&quot;green&quot;,label=&quot;FEBRUARY&quot;)\nplt.xlabel(&quot;Year-Wise sale per Year&quot;)\nplt.ylabel(&quot;Total Sale&quot;)\nplt.xticks(&#x5B;r for r in range(len(JAN))], &#x5B; '2016', '2017', '2018', '2019']) \nplt.legend()\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"390\" height=\"262\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/stackbar.png\" alt=\"make stacked bar charts\" class=\"wp-image-3929\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/stackbar.png 390w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/stackbar-300x202.png 300w\" sizes=\"(max-width: 390px) 100vw, 390px\" \/><\/figure><\/div>\n\n\n<p>Here, what we have done is that we have stacked a bar over another bar. plt.bar(range(x_axis), FEB, bottom=JAN,color=&#8221;green&#8221;,label=&#8221;FEBRUARY&#8221;)&#8217;- This line means that, we have put the bar of FEBRUARY over the bar of JANUARY.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-horizontal-bar-graph-using-matplotlib-barh\"><span class=\"ez-toc-section\" id=\"Horizontal_Bar_Graph_using_Matplotlib_barh\"><\/span>Horizontal Bar Graph using Matplotlib barh<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We can also make a horizontal bar graph using matplotlib.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport matplotlib.pyplot as plt\n%matplotlib inline\ntechnologies=&#x5B;'Data Science', 'Cyber Security', 'Web Development', 'Android Development', 'Data Analyst'] \nnumber_of_students=&#x5B;78,49,112,129,59]\n# for horizontal bar graph use barh \nplt.barh(technologies,number_of_students,color=&quot;yellow&quot;)\n<\/pre><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"465\" height=\"248\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/barh.png\" alt=\"matplotlib bar\" class=\"wp-image-3930\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/barh.png 465w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/barh-300x160.png 300w\" sizes=\"(max-width: 465px) 100vw, 465px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-making-bar-chart-using-pandas-data-frame\"><span class=\"ez-toc-section\" id=\"Making_Bar_Chart_using_Pandas_Data_Frame\"><\/span>Making Bar Chart using Pandas Data Frame<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Do you know that we can also create a bar chart using the pandas&#8217; library? Suppose if we have a data frame, we can directly create different types of plots like <strong>scatter, bar, line using a single function<\/strong>. In the background, pandas also use matplotlib to create graphs. Let us see how we will do so.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nage=&#x5B;47,44,29,24,26,40,46,41,28,34,36,33,42,43,38]\nemployee_of_these_age=&#x5B;30,22,24,12,20,34,12,11,31,24,26,29,21,16,21]\ndataset=pd.DataFrame()\n# create a dataset using these data\ndataset&#x5B;'age']=age\ndataset&#x5B;'employee_of_these_age']=employee_of_these_age\n\n# Use the plot function, in x axis give the age and \n# in y axis give the number of people of those age\n# Use bar as kind to create a bar chart\ndataset.plot(x='age',y='employee_of_these_age',kind='bar')\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"368\" height=\"265\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_2.png\" alt=\"Pandas Data Frame\" class=\"wp-image-3949\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_2.png 368w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/bar_2-300x216.png 300w\" sizes=\"(max-width: 368px) 100vw, 368px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading has-vivid-red-color has-text-color\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/www.pythonpool.com\/python-lowercase\/\">How to Convert String to Lowercase in<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/square-root-in-python\/\">How to Calculate Square Root<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/python-user-input\/\">User Input | Input () Function | Keyboard Input<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/www.pythonpool.com\/python-book\/\">Best Book to Learn Python<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Matplotlib Bar<\/strong> Graphs are very important as they help data scientists and data analysts to take insights from the data real quick. By going through the data without any visualization, it gets very to receive insights from it. We can use the matplotlib bar function to make bar graphs in python. <\/p>\n\n\n\n<p>Try to run the programs on your side and let us know if you have any queries.<\/p>\n\n\n\n<p><strong><em>Happy Coding!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We, humans, are great at understanding the visuals rather than going through numerical data. It becomes very easy for us to find insights from a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Matplotlib Bar | Creating Bar Charts Using Bar Function\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#more-3925\" aria-label=\"More on Matplotlib Bar | Creating Bar Charts Using Bar Function\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":3956,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2071],"tags":[2124,2111,2117,2120,2122,2119,2126,2114,2123,2110,2118,2125,2121,2112,2113,2116,2115],"class_list":["post-3925","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-matplotlib","tag-bar-chart-matplotlib","tag-bar-graph-matplotlib","tag-bar-plot-matplotlib","tag-matplotlib-bar","tag-matplotlib-bar-chart","tag-matplotlib-bar-chart-example","tag-matplotlib-bar-chart-labels","tag-matplotlib-bar-graph","tag-matplotlib-bar-graph-example","tag-matplotlib-bar-plot","tag-matplotlib-horizontal-bar-chart","tag-matplotlib-multiple-bar-chart","tag-matplotlib-plot-bar","tag-matplotlib-stacked-bar","tag-matplotlib-stacked-bar-chart","tag-python-matplotlib-bar-chart","tag-stacked-bar-chart-matplotlib","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Matplotlib Bar | Creating Bar Charts Using Bar Function - Python Pool<\/title>\n<meta name=\"description\" content=\"To create bar charts in python, we can make use of matplotlib bar function. Bar charts are used for comparing different items.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matplotlib Bar | Creating Bar Charts Using Bar Function\" \/>\n<meta property=\"og:description\" content=\"We, humans, are great at understanding the visuals rather than going through numerical data. It becomes very easy for us to find insights from a graph, a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-24T05:58:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-01T09:25:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ashwini Mandani\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashwini Mandani\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\"},\"author\":{\"name\":\"Ashwini Mandani\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\"},\"headline\":\"Matplotlib Bar | Creating Bar Charts Using Bar Function\",\"datePublished\":\"2020-08-24T05:58:44+00:00\",\"dateModified\":\"2024-01-01T09:25:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\"},\"wordCount\":853,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png\",\"keywords\":[\"bar chart matplotlib\",\"bar graph matplotlib\",\"bar plot matplotlib\",\"matplotlib bar\",\"matplotlib bar chart\",\"matplotlib bar chart example\",\"matplotlib bar chart labels\",\"matplotlib bar graph\",\"matplotlib bar graph example\",\"matplotlib bar plot\",\"matplotlib horizontal bar chart\",\"matplotlib multiple bar chart\",\"matplotlib plot bar\",\"matplotlib stacked bar\",\"matplotlib stacked bar chart\",\"python matplotlib bar chart\",\"stacked bar chart matplotlib\"],\"articleSection\":[\"Matplotlib\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\",\"url\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\",\"name\":\"Matplotlib Bar | Creating Bar Charts Using Bar Function - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png\",\"datePublished\":\"2020-08-24T05:58:44+00:00\",\"dateModified\":\"2024-01-01T09:25:20+00:00\",\"description\":\"To create bar charts in python, we can make use of matplotlib bar function. Bar charts are used for comparing different items.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/matplotlib-bar\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png\",\"width\":1350,\"height\":650,\"caption\":\"matplotlib bar\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/matplotlib-bar\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Matplotlib Bar | Creating Bar Charts Using Bar Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056\",\"name\":\"Ashwini Mandani\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g\",\"caption\":\"Ashwini Mandani\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Matplotlib Bar | Creating Bar Charts Using Bar Function - Python Pool","description":"To create bar charts in python, we can make use of matplotlib bar function. Bar charts are used for comparing different items.","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:\/\/www.pythonpool.com\/matplotlib-bar\/","og_locale":"en_US","og_type":"article","og_title":"Matplotlib Bar | Creating Bar Charts Using Bar Function","og_description":"We, humans, are great at understanding the visuals rather than going through numerical data. It becomes very easy for us to find insights from a graph, a","og_url":"https:\/\/www.pythonpool.com\/matplotlib-bar\/","og_site_name":"Python Pool","article_published_time":"2020-08-24T05:58:44+00:00","article_modified_time":"2024-01-01T09:25:20+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png","type":"image\/png"}],"author":"Ashwini Mandani","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Ashwini Mandani","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/"},"author":{"name":"Ashwini Mandani","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056"},"headline":"Matplotlib Bar | Creating Bar Charts Using Bar Function","datePublished":"2020-08-24T05:58:44+00:00","dateModified":"2024-01-01T09:25:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/"},"wordCount":853,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png","keywords":["bar chart matplotlib","bar graph matplotlib","bar plot matplotlib","matplotlib bar","matplotlib bar chart","matplotlib bar chart example","matplotlib bar chart labels","matplotlib bar graph","matplotlib bar graph example","matplotlib bar plot","matplotlib horizontal bar chart","matplotlib multiple bar chart","matplotlib plot bar","matplotlib stacked bar","matplotlib stacked bar chart","python matplotlib bar chart","stacked bar chart matplotlib"],"articleSection":["Matplotlib"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/matplotlib-bar\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/","url":"https:\/\/www.pythonpool.com\/matplotlib-bar\/","name":"Matplotlib Bar | Creating Bar Charts Using Bar Function - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png","datePublished":"2020-08-24T05:58:44+00:00","dateModified":"2024-01-01T09:25:20+00:00","description":"To create bar charts in python, we can make use of matplotlib bar function. Bar charts are used for comparing different items.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/matplotlib-bar\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/Theatre-Actor-Portfolio-Website-3.png","width":1350,"height":650,"caption":"matplotlib bar"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/matplotlib-bar\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Matplotlib Bar | Creating Bar Charts Using Bar Function"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/8a75fb48eb1f3dc952df65a8c28ac056","name":"Ashwini Mandani","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f765ed1940ac0ae1d30ce4cb2f1452c1e83143b07354d25a42c1cd118980e269?s=96&d=wavatar&r=g","caption":"Ashwini Mandani"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=3925"}],"version-history":[{"count":8,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3925\/revisions"}],"predecessor-version":[{"id":31568,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/3925\/revisions\/31568"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/3956"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=3925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=3925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=3925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}