Q.(Program 4-13) Taking the same data as Program 4-12 (discount = [10, 20, 30, 40, 50], saleInRs = [40000, 45000, 48000, 50000, 100000]), customise the scatter chart: display the size of each bubble as 10 times the discount, and change the colour to red, linewidth to 3, marker to '*' and edgecolor to blue.
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 →Customise a scatter plot by setting bubble size proportional to discount, changing marker style to star, colour to red, edge colour to blue, and linewidth to 3.
Why scatter plot customisation matters
A scatter plot visualises the relationship between two continuous variables. In matplotlib, plt.scatter() accepts parameters that control every visual aspect of the markers: their size (s), face colour (c or color), edge colour (edgecolors), edge width (linewidths), and shape (marker). By customising these, you turn a plain scatter into an information-rich chart where a third variable (here, discount) is encoded in bubble size, making patterns immediately visible.
The question asks you to map discount to bubble size (scaled by 10), use a star marker, red fill, blue edge, and edge width of 3. Each parameter has a specific role:
s(size): accepts a scalar or array; here we pass[10×d for d in discount]so each bubble's area reflects its discount.marker='*': switches from the default circle to a star.c='red'orcolor='red': sets the fill colour.edgecolors='blue': sets the edge (stroke) colour.linewidths=3: thickens the edge to 3 points.
The complete program
import matplotlib.pyplot as plt
# Data from Program 4-12
discount = [10, 20, 30, 40, 50]
saleInRs = [40000, 45000, 48000, 50000, 100000]
# Compute bubble sizes: 10 times each discount value
sizes = [10 * d for d in discount]
# Create the customised scatter plot
plt.scatter(discount, saleInRs,
s=sizes,
color='red',
marker='*',
edgecolors='blue',
linewidths=3)
plt.xlabel('Discount (%)')
plt.ylabel('Sale (₹)')
plt.title('Sales vs Discount with Customised Markers')
plt.grid(True, alpha=0.3)
plt.show()
Expected output
The chart displays:
- X-axis: Discount (%), ranging from 10 to 50.
- Y-axis: Sale (₹), ranging from 40,000 to 100,000.
- Markers: Five red stars (
*), each with a thick blue edge (3 pt). - Size progression: The star at discount=10 has size 100 (smallest), the star at discount=50 has size 500 (largest), making the growth in discount visually obvious.
- Grid: Light grey grid for easier reading.
- Title and labels: As shown in the code.
The final point (50, 100000) stands out both by position (top-right) and by its large star size, immediately signalling that higher discounts correlate with higher sales in this dataset.
Key lines explained
sizes = [10 * d for d in discount]
A list comprehension that scales each discount by 10. Matplotlib interprets s as the marker area in points², so this scaling ensures visible size differences.
plt.scatter(discount, saleInRs, s=sizes, …) …
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.