mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 17:00:41 +00:00
Add output option for chart scripts
This commit is contained in:
1 parent
956ebf31f8
commit
53eedd1929
5 files changed
+37
No files matched your search
@@ -83,6 +83,12 @@ def main(argv: list[str] | None = None) -> plt.Figure:
|
||||
help="end date YYYY-MM-DD",
|
||||
)
|
||||
p.add_argument("--db", type=str, default="data/fred.db", help="path to SQLite DB")
|
||||
p.add_argument(
|
||||
"--output",
|
||||
type=str,
|
||||
default=None,
|
||||
help="optional path to save the figure (PNG or PDF)",
|
||||
)
|
||||
args = p.parse_args(argv)
|
||||
|
||||
start_dt = datetime.fromisoformat(args.start)
|
||||
@@ -91,6 +97,8 @@ def main(argv: list[str] | None = None) -> plt.Figure:
|
||||
data = fetch_series_multi(args.series, start_dt, end_dt, args.db)
|
||||
fig = plot_series(data)
|
||||
|
||||
if args.output:
|
||||
fig.savefig(args.output)
|
||||
if argv is None:
|
||||
fig.show()
|
||||
return fig
|
||||
|
||||
Reference in new issue
Block a user