Skip to content
Snippets Groups Projects
Unverified Commit 81e3700a authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

add `--x-lim` and `--y-lim` to `gplt plot`

parent a66c8f05
Branches
Tags 0.4.0
No related merge requests found
......@@ -29,6 +29,8 @@ if __name__ == "__main__":
plot_parser.add_argument("--y-label", "-y", type=str, help="the y label of the plot")
plot_parser.add_argument("--x-scale", "-X", type=str, choices=["linear", "log"], default="linear", help="the x scale of the plot")
plot_parser.add_argument("--y-scale", "-Y", type=str, choices=["linear", "log"], default="linear", help="the y scale of the plot")
plot_parser.add_argument("--x-lim", type=float, nargs=2, help="limit the x axis of the plot")
plot_parser.add_argument("--y-lim", type=float, nargs=2, help="limit the y axis of the plot")
plot_parser.add_argument("--fullscreen", action="store_true")
plot_parser.add_argument("--save", "-s", type=str, help="a path to save the figure to")
plot_parser.add_argument("--aspect-ratio", type=int, nargs=2, default=[16, 9], help="the aspect ratio of the saved image")
......@@ -69,6 +71,8 @@ if __name__ == "__main__":
plot_layout="constrained" if args.fullscreen else None,
x_scale=args.x_scale,
y_scale=args.y_scale,
x_lim=args.x_lim,
y_lim=args.y_lim,
save=args.save,
save_aspect_ratio=args.aspect_ratio,
save_dpi=args.dpi,
......
......@@ -90,6 +90,8 @@ def plot(
plot_layout: str = "constrained",
x_scale: str = "linear",
y_scale: str = "linear",
x_lim: Tuple[float, float] = None,
y_lim: Tuple[float, float] = None,
):
fig, ax = plt.subplots(layout=plot_layout)
......@@ -123,6 +125,12 @@ def plot(
else:
ax.plot(xs, ys, label=g["name"], **style)
if x_lim is not None:
ax.set_xlim(x_lim)
if y_lim is not None:
ax.set_ylim(y_lim)
if style["color"] is None:
ax.fill_between(xs, down, up, alpha=error_alpha)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment