{"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
\"Python<\/figure>\n\n\n\n

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

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

In this exercise, we are using Pandas and Matplotlib to visualize Company Sales Data<\/strong>.<\/p>\n\n\n\n

\"Matplotlib<\/figure>\n\n\n\n

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

company_sales_data<\/a>Download company sales dataset<\/a><\/div>\n\n\n\n

What included in this Matplotlib Exercise?<\/strong><\/p>\n\n\n\n

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

Exercise 1: Read Total profit of all months and show it using a line plot<\/h3>\n\n\n\n

Total profit data provided for each month. Generated line plot must include the following properties: –<\/p>\n\n\n\n

  • X label name = Month Number<\/li>
  • Y label name = Total profit<\/li><\/ul>\n\n\n\n

    The line plot graph should look like this.<\/p>\n\n\n\n

    \"Matplotlib<\/figure><\/div>\n\n\n\n
    Show Solution<\/summary>
    import<\/span> pandas as<\/span> pd\nimport<\/span> matplotlib.pyplot as<\/span> plt  \n\ndf = pd.read_csv(\"D:\\\\Python\\\\Articles\\\\matplotlib\\\\sales_data.csv\"<\/span>)\nprofitList = df ['total_profit'<\/span>].tolist()\nmonthList  = df ['month_number'<\/span>].tolist()\nplt.plot(monthList, profitList, label = 'Month-wise Profit data of last year'<\/span>)\nplt.xlabel('Month number'<\/span>)\nplt.ylabel('Profit in dollar'<\/span>)\nplt.xticks(monthList)\nplt.title('Company profit per month'<\/span>)\nplt.yticks([100000<\/span>, 200000<\/span>, 300000<\/span>, 400000<\/span>, 500000<\/span>])\nplt.show()<\/code><\/span>Code language:<\/span> Python<\/span> (<\/span>python<\/span>)<\/span><\/small><\/pre>