Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for invalid range in contour_plot and derivatives #35113

Merged
merged 9 commits into from
Mar 26, 2023
14 changes: 11 additions & 3 deletions src/sage/plot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup_for_eval_on_grid(funcs,
ValueError: At least one variable range has more than 3 entries: each should either have 2 or 3 entries, with one of the forms (xmin, xmax) or (x, xmin, xmax)

sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], plot_points=5)
(<sage...>, [(1.0, -1.0, 0.5), (-1.0, 1.0, 0.5)])
(<sage...>, [(-1.0, 1.0, 0.5), (-1.0, 1.0, 0.5)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(x,-1,1)], plot_points=5)
Traceback (most recent call last):
...
Expand All @@ -106,9 +106,9 @@ def setup_for_eval_on_grid(funcs,
...
ValueError: plot start point and end point must be different
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(y,-1,1)], return_vars=True)
(<sage...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [x, y])
(<sage...>, [(-1.0, 1.0, 2.0), (-1.0, 1.0, 2.0)], [x, y])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], return_vars=True)
(<sage...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [y, x])
(<sage...>, [(-1.0, 1.0, 2.0), (-1.0, 1.0, 2.0)], [y, x])

TESTS:

Expand Down Expand Up @@ -139,6 +139,14 @@ def setup_for_eval_on_grid(funcs,
else:
vars, free_vars = unify_arguments(funcs)

# check for invalid range (xmin > xmax or ymin > ymax) and swap
if len(ranges) > 1:
for i in range(len(ranges)):
if ranges[i][-2] > ranges[i][-1]:
ranges[i] = list(ranges[i])
ranges[i][-1], ranges[i][-2] = ranges[i][-2], ranges[i][-1]
ranges[i] = tuple(ranges[i])

jnash10 marked this conversation as resolved.
Show resolved Hide resolved
# pad the variables if we don't have enough
nargs = len(ranges)
if len(vars) < nargs:
Expand Down