11#!/usr/bin/env python3
22
3- from pathlib import Path
43import argparse
5- import pandas as pd
4+ from pathlib import Path
5+ from typing import List , Tuple
6+
67import matplotlib .pyplot as plt
7- from typing import list , tuple
8+ import pandas as pd
9+
810
9- def read_csv_data (file_path : Path , x_col : str , y_col : str ) -> tuple [ list [float ], list [float ]]:
11+ def read_csv_data (file_path : Path , x_col : str , y_col : str ) -> Tuple [ List [float ], List [float ]]:
1012 """Read data from a CSV file and return specified columns.
11-
13+
1214 Args:
1315 file_path: Path to the CSV file
1416 x_col: Name of the column to use for x-axis
1517 y_col: Name of the column to use for y-axis
16-
18+
1719 Returns:
1820 Tuple of x and y data as lists
1921 """
2022 df = pd .read_csv (file_path )
2123 return df [x_col ].tolist (), df [y_col ].tolist ()
2224
23- def create_plot (x_data : list [float ], y_data : list [float ],
24- x_label : str , y_label : str , title : str ) -> plt .Figure :
25+
26+ def create_plot (
27+ x_data : List [float ], y_data : List [float ], x_label : str , y_label : str , title : str
28+ ) -> plt .Figure :
2529 """Create a plot from the provided data.
26-
30+
2731 Args:
2832 x_data: Data for x-axis
2933 y_data: Data for y-axis
3034 x_label: Label for x-axis
3135 y_label: Label for y-axis
3236 title: Plot title
33-
37+
3438 Returns:
3539 matplotlib Figure object
3640 """
@@ -41,22 +45,30 @@ def create_plot(x_data: list[float], y_data: list[float],
4145 ax .set_title (title )
4246 return fig
4347
48+
4449def main () -> None :
4550 parser = argparse .ArgumentParser (description = "Create plots from CSV data" )
4651 parser .add_argument ("file_path" , type = Path , help = "Path to the CSV file" )
4752 parser .add_argument ("x_column" , type = str , help = "Column name for x-axis" )
4853 parser .add_argument ("y_column" , type = str , help = "Column name for y-axis" )
49- parser .add_argument ("--output" , "-o" , type = Path , default = Path ("plot.png" ),
50- help = "Output file path (default: plot.png)" )
51- parser .add_argument ("--title" , "-t" , type = str , default = "Data Plot" ,
52- help = "Plot title (default: Data Plot)" )
53-
54+ parser .add_argument (
55+ "--output" ,
56+ "-o" ,
57+ type = Path ,
58+ default = Path ("plot.png" ),
59+ help = "Output file path (default: plot.png)" ,
60+ )
61+ parser .add_argument (
62+ "--title" , "-t" , type = str , default = "Data Plot" , help = "Plot title (default: Data Plot)"
63+ )
64+
5465 args = parser .parse_args ()
55-
66+
5667 x_data , y_data = read_csv_data (args .file_path , args .x_column , args .y_column )
5768 fig = create_plot (x_data , y_data , args .x_column , args .y_column , args .title )
5869 fig .savefig (args .output )
5970 plt .close (fig )
6071
72+
6173if __name__ == "__main__" :
62- main ()
74+ main ()
0 commit comments