diff --git a/plots/matplotlib/plot/line-basic/default.py b/plots/matplotlib/plot/line-basic/default.py index 876b686fd1..1c944c8530 100644 --- a/plots/matplotlib/plot/line-basic/default.py +++ b/plots/matplotlib/plot/line-basic/default.py @@ -1,125 +1,25 @@ """ -line-basic: Basic Line Chart -Implementation for: matplotlib -Variant: default -Python: 3.10+ - -Generated by AI workflow. +line-basic: Basic Line Plot +Library: matplotlib """ -from typing import TYPE_CHECKING - import matplotlib.pyplot as plt import pandas as pd -if TYPE_CHECKING: - from matplotlib.figure import Figure - - -def create_plot( - data: pd.DataFrame, - x: str, - y: str, - figsize: tuple[float, float] = (16, 9), - color: str = "steelblue", - linewidth: float = 2.0, - marker: str | None = "o", - markersize: float = 6, - alpha: float = 0.8, - title: str | None = None, - xlabel: str | None = None, - ylabel: str | None = None, - linestyle: str = "-", - **kwargs, -) -> "Figure": - """ - Create a basic line chart visualizing the trend of data points. - - Args: - data: Input DataFrame with required columns - x: Column name for x-axis values - y: Column name for y-axis values - figsize: Figure size as (width, height) tuple (default: (16, 9)) - color: Line color (default: "steelblue") - linewidth: Width of the line (default: 2.0) - marker: Marker style for data points (default: "o") - markersize: Size of markers (default: 6) - alpha: Transparency level (default: 0.8) - title: Plot title (default: None) - xlabel: X-axis label (default: uses column name) - ylabel: Y-axis label (default: uses column name) - linestyle: Line style (default: "-" solid) - **kwargs: Additional parameters passed to plot function - - Returns: - Matplotlib Figure object - - Raises: - ValueError: If data is empty - KeyError: If required columns not found - TypeError: If y column contains non-numeric data - - Example: - >>> data = pd.DataFrame({'month': [1, 2, 3], 'sales': [100, 150, 130]}) - >>> fig = create_plot(data, 'month', 'sales') - """ - # Input validation - if data.empty: - raise ValueError("Data cannot be empty") - - # Check required columns - for col in [x, y]: - if col not in data.columns: - available = ", ".join(data.columns) - raise KeyError(f"Column '{col}' not found. Available columns: {available}") - - # Check if y column is numeric - if not pd.api.types.is_numeric_dtype(data[y]): - raise TypeError(f"Column '{y}' must contain numeric data") - - # Create figure - fig, ax = plt.subplots(figsize=figsize) - - # Plot data - ax.plot( - data[x], - data[y], - color=color, - linewidth=linewidth, - marker=marker, - markersize=markersize, - alpha=alpha, - linestyle=linestyle, - **kwargs, - ) - - # Labels and title - ax.set_xlabel(xlabel or x) - ax.set_ylabel(ylabel or y) - - if title: - ax.set_title(title) - - # Apply styling - ax.grid(True, alpha=0.3) - - # Layout - plt.tight_layout() - - return fig - - -if __name__ == "__main__": - # Sample data for testing - monthly sales data - months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] - sales_values = [100, 120, 115, 130, 145, 160, 155, 170, 180, 175, 190, 210] +# Data +data = pd.DataFrame({"time": [1, 2, 3, 4, 5, 6, 7], "value": [10, 15, 13, 18, 22, 19, 25]}) - data = pd.DataFrame({"month": months, "sales": sales_values}) +# Plot +fig, ax = plt.subplots(figsize=(16, 9)) +ax.plot(data["time"], data["value"], color="#306998", linewidth=2, marker="o", markersize=6) - # Create plot - fig = create_plot(data, "month", "sales", title="Monthly Sales Trend", xlabel="Month", ylabel="Sales ($)") +# Labels and styling +ax.set_xlabel("Time", fontsize=20) +ax.set_ylabel("Value", fontsize=20) +ax.set_title("Basic Line Plot", fontsize=20) +ax.tick_params(axis="both", labelsize=16) +ax.grid(True, alpha=0.3) - # Save for inspection - ALWAYS use 'plot.png' as filename - plt.savefig("plot.png", dpi=300, bbox_inches="tight") - print("Plot saved to plot.png") +plt.tight_layout() +plt.savefig("plot.png", dpi=300, bbox_inches="tight")