Filled Area Chart

Given a series of numbers representing stock prices over a month, plot a filled area chart under the curve, showcasing the stock price movement. Use gradient fill for the area.

Example Output:

First, plot the line chart for the stock prices using plot function. Then, fill the area beneath the curve with the fill_between method, using the days on the x-axis and the stock prices on the y-axis. The gradient effect can be achieved by playing around with the color and alpha attributes.

import matplotlib.pyplot as plt
import numpy as np

def filled_area_chart(stock_prices):
    fig, ax = plt.subplots()
    days = np.arange(1, len(stock_prices) + 1)
    ax.plot(days, stock_prices, color="blue")
    ax.fill_between(days, stock_prices, color="skyblue", alpha=0.4)
    ax.set_ylabel("Stock Price")
    ax.set_title("Stock Price Movement Over a Month")

# Example usage
prices = [100, 105, 103, 108, 107, 106, 109, 110, 108, 107, 109, 112, 111, 115]


© Let’s Data Science


Unlock AI & Data Science treasures. Log in!