Monthly Sales Visualization

Given a series of numbers representing monthly sales over a year, plot them using Matplotlib. Ensure you label your x-axis with months and y-axis with the amount sold. Also, use an appropriate title and gridlines for clarity.

Example 1:

Input: [15000, 18000, 16500, 19500, 17500, 18500, 17000, 21000, 20000, 19000, 19500, 21000]
Output: Line plot showcasing monthly sales with labeled x and y axes and gridlines.

Example 2:

Input: [12000, 13000, 14000, 12500, 13500, 14000, 15000, 15500, 14500, 16000, 17000, 18000]
Output: Line plot showcasing monthly sales with labeled x and y axes and gridlines.

Use Matplotlib’s plot method for drawing the line plot. Don’t forget to label your axes using xlabel and ylabel.

import matplotlib.pyplot as plt

def monthly_sales_plot(sales):
    months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    plt.plot(months, sales)
    plt.xlabel("Months")
    plt.ylabel("Amount Sold")
    plt.title("Monthly Sales Over a Year")
    plt.grid(True)
    plt.show()

# Example usages
monthly_sales_plot([15000, 18000, 16500, 19500, 17500, 18500, 17000, 21000, 20000, 19000, 19500, 21000])
monthly_sales_plot([12000, 13000, 14000, 12500, 13500, 14000, 15000, 15500, 14500, 16000, 17000, 18000])

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!