DATA:lab Forums General Please help me resolve the CSS issue Reply To: Please help me resolve the CSS issue

  • Satya Mukherjee

    Administrator
    October 2, 2024 at 4:08 pm

    I have modified the code. Try now

    # Generating forecast for the current year based on the average sales of the last 5 years
    sales_forecast = np.mean(historical_sales, axis=0)
    
    # Plotting the forecast and actual sales
    months_labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    
    # Create a DataFrame to hold both forecast and actual sales data
    data = pd.DataFrame({
        'Month': months_labels,
        'Forecast Sales (1000s)': sales_forecast,
        'Actual Sales (1000s)': np.append(actual_sales_jan_to_sept, [np.nan]*3)  # Actual sales for Jan to Sept, NaN for Oct-Dec
    })
    
    # Plotting the forecast and actual sales as area plots
    plt.figure(figsize=(10, 6))
    
    # Plot forecast sales as an area plot
    plt.fill_between(data['Month'], data['Forecast Sales (1000s)'], color='lightblue', alpha=0.6, label='Forecast Sales')
    
    # Plot actual sales as an area plot
    plt.fill_between(data['Month'], data['Actual Sales (1000s)'], color='orange', alpha=0.7, label='Actual Sales (Jan - Sep)')
    
    # Adding labels and title
    plt.title('Sales Forecast vs Actual Sales (2024)', fontsize=16)
    plt.xlabel('Month', fontsize=12)
    plt.ylabel('Sales (in 1000s)', fontsize=12)
    plt.legend()
    
    # Show the plot
    plt.tight_layout()
    plt.show()