{"id":1827,"date":"2019-01-21T21:41:23","date_gmt":"2019-01-21T16:11:23","guid":{"rendered":"https:\/\/pynative.com\/?p=1827"},"modified":"2021-03-09T18:12:14","modified_gmt":"2021-03-09T12:42:14","slug":"python-matplotlib-exercise","status":"publish","type":"post","link":"https:\/\/pynative.com\/python-matplotlib-exercise\/","title":{"rendered":"Python Matplotlib Exercise"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"795\" height=\"423\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png\" alt=\"Python Matplotlib Exercise\" class=\"wp-image-1850\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png 795w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise-300x160.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise-768x409.png 768w\" sizes=\"auto, (max-width: 795px) 100vw, 795px\" \/><\/figure>\n\n\n\n<p>This Matplotlib exercise project helps Python developers learn and practice data visualization using Matplotlib by solving multiple questions and problems.<\/p>\n\n\n\n<p><strong>Matplotlib<\/strong> is a Python 2D plotting library that produces high-quality charts and figures, which helps us visualize extensive data to understand better. Pandas is a handy and useful data-structure tool for analyzing large and complex data.<\/p>\n\n\n\n<p>In this exercise, we are using Pandas and Matplotlib to <strong>visualize Company Sales Data<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"258\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/company_sales_data.png\" alt=\"Matplotlib Exercise company sales data\" class=\"wp-image-1839\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/company_sales_data.png 725w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/company_sales_data-300x107.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/figure>\n\n\n\n<p>Use the following CSV file for this exercise. Read this file using Pandas or NumPy or using in-built matplotlib function.<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/company_sales_data.csv\">company_sales_data<\/a><a href=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/company_sales_data.csv\" class=\"wp-block-file__button\" download>Download company sales  dataset<\/a><\/div>\n\n\n\n<p><strong>What included in this Matplotlib Exercise?<\/strong><\/p>\n\n\n\n<p>This exercise contains ten questions. The solution is provided for each issue. Each question includes a specific Matplotlib topic you need to learn. When you complete each question, you get more familiar with Data data visualization using matplotlib.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-1-read-total-profit-of-all-months-and-show-it-using-a-line-plot\">Exercise 1:&nbsp;Read Total profit of all months and show it using a line plot<\/h3>\n\n\n\n<p>Total profit data provided for each month. Generated line plot must include the following properties: &#8211;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>X label name = Month Number<\/li><li>Y label name = Total profit<\/li><\/ul>\n\n\n\n<p>The line plot graph should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_1_plot_company_profit.png\" alt=\"Matplotlib Exercise 1: Read Total profit of all months and show it using a line plot\" class=\"wp-image-1830\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_1_plot_company_profit.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_1_plot_company_profit-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_1_plot_company_profit-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code1\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nprofitList = df &#91;<span class=\"hljs-string\">'total_profit'<\/span>].tolist()\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\nplt.plot(monthList, profitList, label = <span class=\"hljs-string\">'Month-wise Profit data of last year'<\/span>)\nplt.xlabel(<span class=\"hljs-string\">'Month number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Profit in dollar'<\/span>)\nplt.xticks(monthList)\nplt.title(<span class=\"hljs-string\">'Company profit per month'<\/span>)\nplt.yticks(&#91;<span class=\"hljs-number\">100000<\/span>, <span class=\"hljs-number\">200000<\/span>, <span class=\"hljs-number\">300000<\/span>, <span class=\"hljs-number\">400000<\/span>, <span class=\"hljs-number\">500000<\/span>])\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code1', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-2-get-total-profit-of-all-months-and-show-line-plot-with-the-following-style-properties\">Exercise 2: Get total profit of all months and show line plot with the following Style properties<\/h3>\n\n\n\n<p>Generated line plot must include following Style properties: &#8211;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Line Style dotted and Line-color should be red<\/li><li>Show legend at the lower right location.<\/li><li>X label name = Month Number<\/li><li>Y label name = Sold units number<\/li><li>Add a circle marker.<\/li><li>Line marker color as read<\/li><li>Line width should be 3<\/li><\/ul>\n\n\n\n<p>The line plot graph should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_2_plot_style_properties.png\" alt=\"Matplotlib Exercise 2: Get Total profit of all months and show line plot with the following Style properties\" class=\"wp-image-1831\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_2_plot_style_properties.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_2_plot_style_properties-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_2_plot_style_properties-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code2\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nprofitList = df &#91;<span class=\"hljs-string\">'total_profit'<\/span>].tolist()\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\n\nplt.plot(monthList, profitList, label = <span class=\"hljs-string\">'Profit data of last year'<\/span>, \n      color=<span class=\"hljs-string\">'r'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, markerfacecolor=<span class=\"hljs-string\">'k'<\/span>, \n      linestyle=<span class=\"hljs-string\">'--'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\n      \nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Profit in dollar'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'lower right'<\/span>)\nplt.title(<span class=\"hljs-string\">'Company Sales data of last year'<\/span>)\nplt.xticks(monthList)\nplt.yticks(&#91;<span class=\"hljs-number\">100000<\/span>, <span class=\"hljs-number\">200000<\/span>, <span class=\"hljs-number\">300000<\/span>, <span class=\"hljs-number\">400000<\/span>, <span class=\"hljs-number\">500000<\/span>])\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code2', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-3-read-all-product-sales-data-and-show-it-using-a-multiline-plot\">Exercise 3: Read all product sales data and show it&nbsp; using a multiline plot<\/h3>\n\n\n\n<p>Display the number of units sold per month for each product using multiline plots. (i.e., Separate Plotline for each product ).<\/p>\n\n\n\n<p>The graph should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_3_multiline_plots.png\" alt=\"Matplotlib Exercise 3: Read all product sales data and show it\u00a0 using a multiline plot\" class=\"wp-image-1832\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_3_multiline_plots.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_3_multiline_plots-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_3_multiline_plots-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code3\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\nfaceCremSalesData   = df &#91;<span class=\"hljs-string\">'facecream'<\/span>].tolist()\nfaceWashSalesData   = df &#91;<span class=\"hljs-string\">'facewash'<\/span>].tolist()\ntoothPasteSalesData = df &#91;<span class=\"hljs-string\">'toothpaste'<\/span>].tolist()\nbathingsoapSalesData   = df &#91;<span class=\"hljs-string\">'bathingsoap'<\/span>].tolist()\nshampooSalesData   = df &#91;<span class=\"hljs-string\">'shampoo'<\/span>].tolist()\nmoisturizerSalesData = df &#91;<span class=\"hljs-string\">'moisturizer'<\/span>].tolist()\n\nplt.plot(monthList, faceCremSalesData,   label = <span class=\"hljs-string\">'Face cream Sales Data'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\nplt.plot(monthList, faceWashSalesData,   label = <span class=\"hljs-string\">'Face Wash Sales Data'<\/span>,  marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\nplt.plot(monthList, toothPasteSalesData, label = <span class=\"hljs-string\">'ToothPaste Sales Data'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\nplt.plot(monthList, bathingsoapSalesData, label = <span class=\"hljs-string\">'ToothPaste Sales Data'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\nplt.plot(monthList, shampooSalesData, label = <span class=\"hljs-string\">'ToothPaste Sales Data'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\nplt.plot(monthList, moisturizerSalesData, label = <span class=\"hljs-string\">'ToothPaste Sales Data'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\n\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Sales units in number'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'upper left'<\/span>)\nplt.xticks(monthList)\nplt.yticks(&#91;<span class=\"hljs-number\">1000<\/span>, <span class=\"hljs-number\">2000<\/span>, <span class=\"hljs-number\">4000<\/span>, <span class=\"hljs-number\">6000<\/span>, <span class=\"hljs-number\">8000<\/span>, <span class=\"hljs-number\">10000<\/span>, <span class=\"hljs-number\">12000<\/span>, <span class=\"hljs-number\">15000<\/span>, <span class=\"hljs-number\">18000<\/span>])\nplt.title(<span class=\"hljs-string\">'Sales data'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code3', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-4-read-toothpaste-sales-data-of-each-month-and-show-it-using-a-scatter-plot\">Exercise 4: Read toothpaste sales data of each month and show it using a scatter plot<\/h3>\n\n\n\n<p>Also, add a grid in the plot. gridline style should &#8220;&#8211;&#8220;.<\/p>\n\n\n\n<p>The scatter plot should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_4_show_scatter_plot.png\" alt=\"Matplotlib Exercise 4: Read toothpaste sales data of each month and show it using a scatter plot\" class=\"wp-image-1833\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_4_show_scatter_plot.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_4_show_scatter_plot-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_and_pandas_exercise_4_show_scatter_plot-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code4\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\ntoothPasteSalesData = df &#91;<span class=\"hljs-string\">'toothpaste'<\/span>].tolist()\nplt.scatter(monthList, toothPasteSalesData, label = <span class=\"hljs-string\">'Tooth paste Sales data'<\/span>)\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Number of units Sold'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'upper left'<\/span>)\nplt.title(<span class=\"hljs-string\">' Tooth paste Sales data'<\/span>)\nplt.xticks(monthList)\nplt.grid(<span class=\"hljs-literal\">True<\/span>, linewidth= <span class=\"hljs-number\">1<\/span>, linestyle=<span class=\"hljs-string\">\"--\"<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code4', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-5-read-face-cream-and-facewash-product-sales-data-and-show-it-using-the-bar-chart\">Exercise 5: Read face cream and facewash product sales data and show it using the bar chart<\/h3>\n\n\n\n<p>The bar chart should display the number of units sold per month for each product. Add a separate bar for each product in the same chart.<\/p>\n\n\n\n<p>The bar chart should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_5_show_bar_chart.png\" alt=\"Matplotlib Exercise 5: Read face cream and facewash product sales data and show it using the bar chart\" class=\"wp-image-1834\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_5_show_bar_chart.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_5_show_bar_chart-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_5_show_bar_chart-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code5\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\nfaceCremSalesData   = df &#91;<span class=\"hljs-string\">'facecream'<\/span>].tolist()\nfaceWashSalesData   = df &#91;<span class=\"hljs-string\">'facewash'<\/span>].tolist()\n\nplt.bar(&#91;a<span class=\"hljs-number\">-0.25<\/span> <span class=\"hljs-keyword\">for<\/span> a <span class=\"hljs-keyword\">in<\/span> monthList], faceCremSalesData, width= <span class=\"hljs-number\">0.25<\/span>, label = <span class=\"hljs-string\">'Face Cream sales data'<\/span>, align=<span class=\"hljs-string\">'edge'<\/span>)\nplt.bar(&#91;a+<span class=\"hljs-number\">0.25<\/span> <span class=\"hljs-keyword\">for<\/span> a <span class=\"hljs-keyword\">in<\/span> monthList], faceWashSalesData, width= <span class=\"hljs-number\">-0.25<\/span>, label = <span class=\"hljs-string\">'Face Wash sales data'<\/span>, align=<span class=\"hljs-string\">'edge'<\/span>)\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Sales units in number'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'upper left'<\/span>)\nplt.title(<span class=\"hljs-string\">' Sales data'<\/span>)\n\nplt.xticks(monthList)\nplt.grid(<span class=\"hljs-literal\">True<\/span>, linewidth= <span class=\"hljs-number\">1<\/span>, linestyle=<span class=\"hljs-string\">\"--\"<\/span>)\nplt.title(<span class=\"hljs-string\">'Facewash and facecream sales data'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code5', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-6-read-sales-data-of-bathing-soap-of-all-months-and-show-it-using-a-bar-chart-save-this-plot-to-your-hard-disk\">Exercise 6: Read sales data of bathing soap of all months and show it using a bar chart. Save this plot to your hard disk<\/h3>\n\n\n\n<p>The bar chart should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_6_save_plot_to_hard_disk.png\" alt=\"Matplotlib Exercise 6: Read sales data of bathing soap of all months and show it using a bar chart. Save this plot to your hard disk\" class=\"wp-image-1836\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_6_save_plot_to_hard_disk.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_6_save_plot_to_hard_disk-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_6_save_plot_to_hard_disk-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code6\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\nbathingsoapSalesData   = df &#91;<span class=\"hljs-string\">'bathingsoap'<\/span>].tolist()\nplt.bar(monthList, bathingsoapSalesData)\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Sales units in number'<\/span>)\nplt.title(<span class=\"hljs-string\">' Sales data'<\/span>)\nplt.xticks(monthList)\nplt.grid(<span class=\"hljs-literal\">True<\/span>, linewidth= <span class=\"hljs-number\">1<\/span>, linestyle=<span class=\"hljs-string\">\"--\"<\/span>)\nplt.title(<span class=\"hljs-string\">'bathingsoap sales data'<\/span>)\nplt.savefig(<span class=\"hljs-string\">'D:\\Python\\Articles\\matplotlib\\sales_data_of_bathingsoap.png'<\/span>, dpi=<span class=\"hljs-number\">150<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code6', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-7-read-the-total-profit-of-each-month-and-show-it-using-the-histogram-to-see-the-most-common-profit-ranges\">Exercise 7: Read the total profit of each month and show it using the histogram to see the most common profit ranges<\/h3>\n\n\n\n<p>The histogram should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_7_histogram.png\" alt=\"Matplotlib Exercise 7: Read the total profit of each month and show it using the histogram to see most common profit ranges\" class=\"wp-image-1835\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_7_histogram.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_7_histogram-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_panadas_exercise_7_histogram-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code7\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nprofitList = df &#91;<span class=\"hljs-string\">'total_profit'<\/span>].tolist()\nlabels = &#91;<span class=\"hljs-string\">'low'<\/span>, <span class=\"hljs-string\">'average'<\/span>, <span class=\"hljs-string\">'Good'<\/span>, <span class=\"hljs-string\">'Best'<\/span>]\nprofit_range = &#91;<span class=\"hljs-number\">150000<\/span>, <span class=\"hljs-number\">175000<\/span>, <span class=\"hljs-number\">200000<\/span>, <span class=\"hljs-number\">225000<\/span>, <span class=\"hljs-number\">250000<\/span>, <span class=\"hljs-number\">300000<\/span>, <span class=\"hljs-number\">350000<\/span>]\nplt.hist(profitList, profit_range, label = <span class=\"hljs-string\">'Profit data'<\/span>)\nplt.xlabel(<span class=\"hljs-string\">'profit range in dollar'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Actual Profit in dollar'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'upper left'<\/span>)\nplt.xticks(profit_range)\nplt.title(<span class=\"hljs-string\">'Profit data'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code7', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-8-calculate-total-sale-data-for-last-year-for-each-product-and-show-it-using-a-pie-chart\">Exercise 8: Calculate total sale data for last year for each product and show it using a Pie chart<\/h3>\n\n\n\n<p><strong>Note<\/strong>: In Pie chart display Number of units sold per year for each product in percentage.<\/p>\n\n\n\n<p>The Pie chart should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exerise_8_show_pie_chart.png\" alt=\"Matplotlib Exercise 8: Calculate total sale data for last year for each product and show it using a Pie chart\" class=\"wp-image-1838\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exerise_8_show_pie_chart.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exerise_8_show_pie_chart-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exerise_8_show_pie_chart-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code8\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\n\nlabels = &#91;<span class=\"hljs-string\">'FaceCream'<\/span>, <span class=\"hljs-string\">'FaseWash'<\/span>, <span class=\"hljs-string\">'ToothPaste'<\/span>, <span class=\"hljs-string\">'Bathing soap'<\/span>, <span class=\"hljs-string\">'Shampoo'<\/span>, <span class=\"hljs-string\">'Moisturizer'<\/span>]\nsalesData   = &#91;df &#91;<span class=\"hljs-string\">'facecream'<\/span>].sum(), df &#91;<span class=\"hljs-string\">'facewash'<\/span>].sum(), df &#91;<span class=\"hljs-string\">'toothpaste'<\/span>].sum(), \n         df &#91;<span class=\"hljs-string\">'bathingsoap'<\/span>].sum(), df &#91;<span class=\"hljs-string\">'shampoo'<\/span>].sum(), df &#91;<span class=\"hljs-string\">'moisturizer'<\/span>].sum()]\nplt.axis(<span class=\"hljs-string\">\"equal\"<\/span>)\nplt.pie(salesData, labels=labels, autopct=<span class=\"hljs-string\">'%1.1f%%'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'lower right'<\/span>)\nplt.title(<span class=\"hljs-string\">'Sales data'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code8', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-9-read-bathing-soap-facewash-of-all-months-and-display-it-using-the-subplot\">Exercise 9: Read Bathing soap facewash of all months and display it using the Subplot<\/h3>\n\n\n\n<p>The Subplot should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_9_show_sub_plot.png\" alt=\"Matplotlib Exercise 9: Read Bathing soap facewash of all months and display it using the Subplot\" class=\"wp-image-1837\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_9_show_sub_plot.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_9_show_sub_plot-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotlib_pandas_exercise_9_show_sub_plot-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code9\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\nbathingsoap   = df &#91;<span class=\"hljs-string\">'bathingsoap'<\/span>].tolist()\nfaceWashSalesData   = df &#91;<span class=\"hljs-string\">'facewash'<\/span>].tolist()\n\nf, axarr = plt.subplots(<span class=\"hljs-number\">2<\/span>, sharex=<span class=\"hljs-literal\">True<\/span>)\naxarr&#91;<span class=\"hljs-number\">0<\/span>].plot(monthList, bathingsoap, label = <span class=\"hljs-string\">'Bathingsoap Sales Data'<\/span>, color=<span class=\"hljs-string\">'k'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\naxarr&#91;<span class=\"hljs-number\">0<\/span>].set_title(<span class=\"hljs-string\">'Sales data of  a Bathingsoap'<\/span>)\naxarr&#91;<span class=\"hljs-number\">1<\/span>].plot(monthList, faceWashSalesData, label = <span class=\"hljs-string\">'Face Wash Sales Data'<\/span>, color=<span class=\"hljs-string\">'r'<\/span>, marker=<span class=\"hljs-string\">'o'<\/span>, linewidth=<span class=\"hljs-number\">3<\/span>)\naxarr&#91;<span class=\"hljs-number\">1<\/span>].set_title(<span class=\"hljs-string\">'Sales data of  a facewash'<\/span>)\n\nplt.xticks(monthList)\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Sales units in number'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code9', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-exercise-question-10-read-all-product-sales-data-and-show-it-using-the-stack-plot\">Exercise Question 10: Read all product sales data and show it using the stack plot<\/h3>\n\n\n\n<p>The Stack plot should look like this.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"600\" src=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotbib_pandas_exercise10_show_stack_plot.png\" alt=\"Matplotlib Exercise 10: Read all product sales data and show it using the stack plot\" class=\"wp-image-1829\" srcset=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotbib_pandas_exercise10_show_stack_plot.png 900w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotbib_pandas_exercise10_show_stack_plot-300x200.png 300w, https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/matplotbib_pandas_exercise10_show_stack_plot-768x512.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-genesis-blocks-gb-accordion gb-block-accordion\"><details><summary class=\"gb-accordion-title\">Show Solution<\/summary><div class=\"gb-accordion-text\"><div class=\"hljstoolbar\"><pre id=\"code10\"  id=\"norun\" class=\"wp-block-code language-python\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt  \n\ndf = pd.read_csv(<span class=\"hljs-string\">\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nmonthList  = df &#91;<span class=\"hljs-string\">'month_number'<\/span>].tolist()\n\nfaceCremSalesData   = df &#91;<span class=\"hljs-string\">'facecream'<\/span>].tolist()\nfaceWashSalesData   = df &#91;<span class=\"hljs-string\">'facewash'<\/span>].tolist()\ntoothPasteSalesData = df &#91;<span class=\"hljs-string\">'toothpaste'<\/span>].tolist()\nbathingsoapSalesData   = df &#91;<span class=\"hljs-string\">'bathingsoap'<\/span>].tolist()\nshampooSalesData   = df &#91;<span class=\"hljs-string\">'shampoo'<\/span>].tolist()\nmoisturizerSalesData = df &#91;<span class=\"hljs-string\">'moisturizer'<\/span>].tolist()\n\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'m'<\/span>, label=<span class=\"hljs-string\">'face Cream'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'c'<\/span>, label=<span class=\"hljs-string\">'Face wash'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'r'<\/span>, label=<span class=\"hljs-string\">'Tooth paste'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'k'<\/span>, label=<span class=\"hljs-string\">'Bathing soap'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'g'<\/span>, label=<span class=\"hljs-string\">'Shampoo'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\nplt.plot(&#91;],&#91;],color=<span class=\"hljs-string\">'y'<\/span>, label=<span class=\"hljs-string\">'Moisturizer'<\/span>, linewidth=<span class=\"hljs-number\">5<\/span>)\n\nplt.stackplot(monthList, faceCremSalesData, faceWashSalesData, toothPasteSalesData, \n              bathingsoapSalesData, shampooSalesData, moisturizerSalesData, \n              colors=&#91;<span class=\"hljs-string\">'m'<\/span>,<span class=\"hljs-string\">'c'<\/span>,<span class=\"hljs-string\">'r'<\/span>,<span class=\"hljs-string\">'k'<\/span>,<span class=\"hljs-string\">'g'<\/span>,<span class=\"hljs-string\">'y'<\/span>])\n\nplt.xlabel(<span class=\"hljs-string\">'Month Number'<\/span>)\nplt.ylabel(<span class=\"hljs-string\">'Sales unints in Number'<\/span>)\nplt.title(<span class=\"hljs-string\">'Alll product sales data using stack plot'<\/span>)\nplt.legend(loc=<span class=\"hljs-string\">'upper left'<\/span>)\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><button class=\"hljs-copy-button\" onclick=\"copy_code('code10', this);\"><i class=\"far fa-copy1\" aria-hidden=\"true\"><\/i><\/button><\/div><\/div><\/details><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This Matplotlib exercise project helps Python developers learn and practice data visualization using Matplotlib by solving multiple questions and problems. Matplotlib is a Python 2D plotting library that produces high-quality charts and figures, which helps us visualize extensive data to understand better. Pandas is a handy and useful data-structure tool for analyzing large and complex [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[22,8],"tags":[30],"class_list":{"0":"post-1827","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python","7":"category-python-exercises-with-solutions","8":"tag-python-exercises","9":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Matplotlib Exercise<\/title>\n<meta name=\"description\" content=\"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pynative.com\/python-matplotlib-exercise\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Matplotlib Exercise\" \/>\n<meta property=\"og:description\" content=\"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pynative.com\/python-matplotlib-exercise\/\" \/>\n<meta property=\"og:site_name\" content=\"PYnative\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-21T16:11:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-03-09T12:42:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png\" \/>\n<meta name=\"author\" content=\"Vishal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@PyNative\" \/>\n<meta name=\"twitter:site\" content=\"@PyNative\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/\"},\"author\":{\"name\":\"Vishal\",\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"headline\":\"Python Matplotlib Exercise\",\"datePublished\":\"2019-01-21T16:11:23+00:00\",\"dateModified\":\"2021-03-09T12:42:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/\"},\"wordCount\":548,\"commentCount\":25,\"publisher\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"image\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/python_matplotlib_exercise.png\",\"keywords\":[\"Python Exercises\"],\"articleSection\":[\"Python\",\"Python Exercises\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/\",\"url\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/\",\"name\":\"Python Matplotlib Exercise\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/python_matplotlib_exercise.png\",\"datePublished\":\"2019-01-21T16:11:23+00:00\",\"dateModified\":\"2021-03-09T12:42:14+00:00\",\"description\":\"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#primaryimage\",\"url\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/python_matplotlib_exercise.png\",\"contentUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/python_matplotlib_exercise.png\",\"width\":795,\"height\":423,\"caption\":\"Python Matplotlib Exercise\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pynative.com\\\/python-matplotlib-exercise\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pynative.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Exercises\",\"item\":\"https:\\\/\\\/pynative.com\\\/python-exercises-with-solutions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Matplotlib Exercise\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pynative.com\\\/#website\",\"url\":\"https:\\\/\\\/pynative.com\\\/\",\"name\":\"PYnative\",\"description\":\"Python Programming\",\"publisher\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/pynative.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/pynative.com\\\/#\\\/schema\\\/person\\\/64b55d5bde2265918c5a9931de4de71f\",\"name\":\"Vishal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"url\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"contentUrl\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\",\"width\":968,\"height\":1065,\"caption\":\"Vishal\"},\"logo\":{\"@id\":\"https:\\\/\\\/pynative.com\\\/wp-content\\\/uploads\\\/2019\\\/01\\\/vishalHule.jpg\"},\"description\":\"Founder of PYnative.com. I am a Python developer and I love to write articles to help developers. | All the best for your future Python endeavors!\",\"sameAs\":[\"https:\\\/\\\/pynative.com\"]}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Matplotlib Exercise","description":"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.","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:\/\/pynative.com\/python-matplotlib-exercise\/","og_locale":"en_US","og_type":"article","og_title":"Python Matplotlib Exercise","og_description":"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.","og_url":"https:\/\/pynative.com\/python-matplotlib-exercise\/","og_site_name":"PYnative","article_published_time":"2019-01-21T16:11:23+00:00","article_modified_time":"2021-03-09T12:42:14+00:00","og_image":[{"url":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png","type":"","width":"","height":""}],"author":"Vishal","twitter_card":"summary_large_image","twitter_creator":"@PyNative","twitter_site":"@PyNative","twitter_misc":{"Written by":"Vishal","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#article","isPartOf":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/"},"author":{"name":"Vishal","@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"headline":"Python Matplotlib Exercise","datePublished":"2019-01-21T16:11:23+00:00","dateModified":"2021-03-09T12:42:14+00:00","mainEntityOfPage":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/"},"wordCount":548,"commentCount":25,"publisher":{"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"image":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png","keywords":["Python Exercises"],"articleSection":["Python","Python Exercises"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pynative.com\/python-matplotlib-exercise\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/","url":"https:\/\/pynative.com\/python-matplotlib-exercise\/","name":"Python Matplotlib Exercise","isPartOf":{"@id":"https:\/\/pynative.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#primaryimage"},"image":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#primaryimage"},"thumbnailUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png","datePublished":"2019-01-21T16:11:23+00:00","dateModified":"2021-03-09T12:42:14+00:00","description":"Python Matplotlib exercise project is to help Python developer to learn and practice Data data visualization using Matplotlib by solving multiple questions and problems.","breadcrumb":{"@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pynative.com\/python-matplotlib-exercise\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#primaryimage","url":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png","contentUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/python_matplotlib_exercise.png","width":795,"height":423,"caption":"Python Matplotlib Exercise"},{"@type":"BreadcrumbList","@id":"https:\/\/pynative.com\/python-matplotlib-exercise\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pynative.com\/"},{"@type":"ListItem","position":2,"name":"Python Exercises","item":"https:\/\/pynative.com\/python-exercises-with-solutions\/"},{"@type":"ListItem","position":3,"name":"Python Matplotlib Exercise"}]},{"@type":"WebSite","@id":"https:\/\/pynative.com\/#website","url":"https:\/\/pynative.com\/","name":"PYnative","description":"Python Programming","publisher":{"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pynative.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/pynative.com\/#\/schema\/person\/64b55d5bde2265918c5a9931de4de71f","name":"Vishal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","url":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","contentUrl":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg","width":968,"height":1065,"caption":"Vishal"},"logo":{"@id":"https:\/\/pynative.com\/wp-content\/uploads\/2019\/01\/vishalHule.jpg"},"description":"Founder of PYnative.com. I am a Python developer and I love to write articles to help developers. | All the best for your future Python endeavors!","sameAs":["https:\/\/pynative.com"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Vishal","author_link":"https:\/\/pynative.com\/author\/vishal\/"},"_links":{"self":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts\/1827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/comments?post=1827"}],"version-history":[{"count":0,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/posts\/1827\/revisions"}],"wp:attachment":[{"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/media?parent=1827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/categories?post=1827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pynative.com\/wp-json\/wp\/v2\/tags?post=1827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}