Python Matplotlib Exercise - 01
Nguồn: https://pynative.com
Lưu ý:
- Các bài tập dưới đây để luyện tập kỹ năng sử dụng thư viện Matplotlib để visualize mức cơ bản.
- Các em nên tự làm trước
- Trường hợp cần giúp đỡ, truy cập vào website nguồn ở trên để xem solution.
- Data dùng để thực hành là Company_Sale_Data được gửi kèm theo file bài tập này.
Exercise 1: Read Total profit of all months and show it using a line plot
Total profit data provided for each month. Generated line plot must include the following properties: –
• X label name = Month Number
• Y label name = Total profit
The line plot graph should look like this.
Exercise 2: Get total profit of all months and show line plot with the following Style properties
Generated line plot must include following Style properties: –
• Line Style dotted and Line-color should be red
• Show legend at the lower right location.
• X label name = Month Number
• Y label name = Sold units number
• Add a circle marker.
• Line marker color as read
• Line width should be 3
The line plot graph should look like this.
1|Page
Exercise 3: Read all product sales data and show it using a multiline plot
Display the number of units sold per month for each product using multiline plots. (i.e., Separate Plotline for each
product ).
The graph should look like this.
2|Page
Exercise 4: Read toothpaste sales data of each month and show it using a scatter plot
Also, add a grid in the plot. gridline style should “–“.
The scatter plot should look like this.
Exercise 5: Read face cream and facewash product sales data and show it using the bar chart
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.
The bar chart should look like this.
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
3|Page
The bar chart should look like this:
Exercise 7: Read the total profit of each month and show it using the histogram to see the most common profit
ranges
The histogram should look like this:
Exercise 8: Calculate total sale data for last year for each product and show it using a Pie chart
Note: In Pie chart display Number of units sold per year for each product in percentage.
The Pie chart should look like this.
4|Page
Exercise 9: Read Bathing soap facewash of all months and display it using the Subplot
Read Bathing soap facewash of all months and display it using the Subplot
The Subplot should look like this:
Exercise 10: Read all product sales data and show it using the stack plot
The Stack plot should look like this.
5|Page
Exercise 11: Trả lời các câu trắc nghiệm và tự luận trong phần bài tập 5.1, 5.2 (Trang 133, 134)
6|Page