dsci_524_ezplot.plot_line

Functions

plot_line(df, x, y[, title, xlabel, ylabel, ...])

Create a line plot using data from a pandas DataFrame.

Module Contents

dsci_524_ezplot.plot_line.plot_line(df, x, y, title=None, xlabel=None, ylabel=None, x_decimals=None, y_decimals=None)[source]

Create a line plot using data from a pandas DataFrame.

Parameters:
  • df (pandas.DataFrame) – Input DataFrame containing the data to plot

  • x (str) – Column name for x-axis values

  • y (str) – Column name for y-axis values

  • title (str, optional) – Title of the plot (default: None)

  • xlabel (str, optional) – Label for x-axis (default: x column name)

  • ylabel (str, optional) – Label for y-axis (default: y column name)

  • x_decimals (int, optional) – Number of decimal places for x-axis values (default: None)

  • y_decimals (int, optional) – Number of decimal places for y-axis values (default: None)

Returns:

  • matplotlib.figure.Figure

    The figure object containing the plot

  • matplotlib.axes.Axes

    The axes object containing the plot elements

Return type:

tuple

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({'year': [2020, 2021, 2022], 'sales': [100, 150, 200]})
>>> fig, ax = plot_line(df, 'year', 'sales', 'Annual Sales', 'Year', 'Sales',
...                     x_decimals=0, y_decimals=2)