Skip to content
Programs · Program 4-12

Q.(Program 4-12) Prayatna sells designer bags and wallets. During the sales season, he gave discounts ranging from 10% to 50% over a period of 5 weeks. He recorded his sales for each type of discount in an array. Draw a scatter plot to show a relationship between the discount offered and sales made, given: discount = [10, 20, 30, 40, 50] and saleInRs = [40000, 45000, 48000, 50000, 100000] (title 'Sales Vs Discount', x axis 'Discount offered', y axis 'Sales in Rs').

Yanam CbseNCERTSubjective· 3mImportance★★★★★est
34% · 15/44 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This solution uses the matplotlib.pyplot library in Python to create a scatter plot visualizing the relationship between discount offered and sales made, as specified by the given data and plot labels.

When we want to understand the relationship or correlation between two numerical variables, a scatter plot is an excellent visualization tool. Each point on a scatter plot represents a pair of values for the two variables, allowing us to visually identify patterns, trends, or outliers. In this problem, we need to see how saleInRs changes with discount, making a scatter plot the perfect choice.

The matplotlib.pyplot library in Python is the standard for creating static, animated, and interactive visualizations. We will use its scatter() function to plot the individual data points and other functions to add a title and axis labels for clarity.

import matplotlib.pyplot as plt

# 1. Define the data for discount and sales
# The 'discount' list represents the independent variable (x-axis).
discount = [10, 20, 30, 40, 50]
# The 'saleInRs' list represents the dependent variable (y-axis).
saleInRs = [40000, 45000, 48000, 50000, 100000]

# 2. Create the scatter plot
# plt.scatter() takes two arguments: the x-coordinates and the y-coordinates of the points.
plt.scatter(discount, saleInRs)

# 3. Set the title and axis labels for better readability
# plt.title() sets the main title of the plot.
plt.title('Sales Vs Discount')
# plt.xlabel() sets the label for the x-axis.
plt.xlabel('Discount offered')
# plt.ylabel() sets the label for the y-axis.
plt.ylabel('Sales in Rs')

# 4. Display the plot
# plt.show() renders the plot window. Without this, the plot might not be displayed.
plt.show()

Explanation of Key Lines:

  • import matplotlib.pyplot as plt: This line imports the pyplot module from the matplotlib library, which is essential for creating plots. We use plt as a common alias for convenience.
  • discount = [10, 20, 30, 40, 50] and saleInRs = [40000, 45000, 48000, 50000, 100000]: These lines define the data points for our plot. discount will be plotted on the x-axis, and saleInRs on the y-axis. Each corresponding element from these lists forms a single point on the scatter plot (e.g., (10, 40000), (20, 45000), etc.).
  • plt.scatter(discount, saleInRs): This is the core function call that generates the scatter plot. It takes the discount values as x-coordinates and saleInRs values as y-coordinates, plotting each pair as a distinct point.
  • plt.title('Sales Vs Discount'): This function adds a descriptive title to the plot, making it clear what the plot represents. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.