Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Visualize Product vs Region Sales | Automating Reports and Visual Insights
Python Automation for Reports and Visual Insights
Section 1. Chapter 20
single

single

bookChallenge: Visualize Product vs Region Sales

Swipe to show menu

Task

Swipe to start coding

Create a function plot_product_region_sales(data) that accepts a DataFrame with product, region, and sales columns and returns a seaborn grouped bar chart comparing sales across regions.

  • Use sns.catplot() with kind="bar" to create the chart, with region on the x-axis, sales on the y-axis, and bars grouped by product using the hue parameter.
  • Set the x-axis label to "Region" and the y-axis label to "Sales Amount" using chart.set_axis_labels().
  • Add a legend with the title "Product" using chart.add_legend(title="Product").
  • Add a chart title that includes both the words "Product" and "Region" using chart.fig.suptitle().
  • Call plt.tight_layout() to adjust the layout.
  • Return the chart object at the end of the function.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 20
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt