Smoothed Customer Trends - Panipuri
Description
Key Components of the Visualization: Figure Setup: The figure size is set to (12, 6), providing a wide format that enhances readability and allows for better visualization of the data trends. Plotting Smoothed Data: A loop iterates through a predefined list of locations (assumed to be defined earlier in the code, such as "Market," "Mall," and "Station"). For each location, the following steps are executed: The x-axis data, representing the days of the month, is extracted from the DataFrame df_smoothed and converted to a NumPy array using to_numpy(). This ensures efficient handling of the data during plotting. The y-axis data, which contains the smoothed customer counts for each location, is also extracted and converted to a NumPy array. The plt.plot() function is called to create a line plot for each location. Each line is labeled with the corresponding location name followed by "(Smoothed)" to indicate that this data has been processed for clarity. Markers (circular) are added at each data point for better visibility, and a dashed line style (linestyle="--") is used to differentiate the smoothed trends from potential raw data plots. Axis Labels and Title: The x-axis is labeled as "Day", indicating that it represents the days of the month. The y-axis is labeled as "Number of Customers", which denotes the customer counts being visualized. A title, "Smoothed Customer Trends," succinctly describes the content of the plot. Legend and Grid: A legend is included to identify each location's smoothed trend line, enhancing interpretability. A grid is enabled on the plot to facilitate easier reading of values and trends across both axes. Display Plot: Finally, plt.show() is called to render and display the plot visually.
Files
Steps to reproduce
import matplotlib.pyplot as plt plt.figure(figsize=(12, 6)) for loc in locations: plt.plot( df_smoothed["Day"].to_numpy(), # Convert to NumPy array df_smoothed[f"{loc}_Customers"].to_numpy(), # Convert to NumPy array label=f"{loc} (Smoothed)", marker="o", linestyle="--" ) plt.xlabel("Day") plt.ylabel("Number of Customers") plt.title("Smoothed Customer Trends") plt.legend() plt.grid(True) plt.show()