mirror of
https://github.com/PR0M3TH3AN/python_charts.git
synced 2026-10-27 08:50:39 +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
|
||||
|
||||
@@ -250,6 +250,12 @@ def main() -> None:
|
||||
default="data/fred.db",
|
||||
help="path to local FRED SQLite file",
|
||||
)
|
||||
p.add_argument(
|
||||
"--output",
|
||||
type=str,
|
||||
default=None,
|
||||
help="optional path to save the figure (PNG or PDF)",
|
||||
)
|
||||
args = p.parse_args()
|
||||
|
||||
start_dt = datetime.fromisoformat(args.start)
|
||||
@@ -258,6 +264,8 @@ def main() -> None:
|
||||
unrate, oil = fetch_series(start_dt, end_dt, args.db)
|
||||
validate_series(unrate, oil)
|
||||
fig = plot_lagged(unrate, oil, args.offset, start_dt, end_dt, args.extend_years)
|
||||
if args.output:
|
||||
fig.savefig(args.output)
|
||||
fig.show()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user