Hello. I would like to be able to do an implicit_plot, but only inside a particular region (much like is allowed with implicit_plot3d, with its region option). I seem to be having trouble using Sage's revision control system (which is why this patch is not in the standard form), but that is another issue.
I have attached the patch, which is really very simple. Let me know if there is anything else I can do to help get this functionality added (like maybe send this as an attachment, which I do not see an obvious way to do). diff --git a/sage/plot/contour_plot.py b/sage/plot/contour_plot.py --- a/sage/plot/contour_plot.py +++ b/sage/plot/contour_plot.py @@ -203,7 +203,7 @@ @suboptions('colorbar', orientation='vertical', format=None, spacing=None) @suboptions('label', fontsize=9, colors='blue', inline=None, inline_spacing=3, fmt="%1.2f") -@options(plot_points=100, fill=True, contours=None, linewidths=None, linestyles=None, labels=False, frame=True, axes=False, colorbar=False, legend_label=None) +@options(plot_points=100, fill=True, contours=None, linewidths=None, linestyles=None, labels=False, frame=True, axes=False, colorbar=False, legend_label=None, region=None) def contour_plot(f, xrange, yrange, **options): r""" ``contour_plot`` takes a function of two variables, `f(x,y)` @@ -299,6 +299,11 @@ - ``legend_label`` -- the label for this item in the legend + - ``region`` - (default: None) If region is given, it must be a Python + callable. Only segments of the surface where region(x,y) returns a + number >0 will be included in the plot. (Note that returning a Python + boolean is acceptable, since True == 1 and False == 0). + EXAMPLES: Here we plot a simple function of two variables. Note that @@ -467,13 +472,29 @@ """ from sage.plot.plot import Graphics from sage.plot.misc import setup_for_eval_on_grid - g, ranges = setup_for_eval_on_grid([f], [xrange, yrange], options['plot_points']) - g = g[0] + + region = options.pop('region') + ev = [f] if region is None else [f,region] + + F, ranges = setup_for_eval_on_grid(ev, [xrange, yrange], options['plot_points']) + g = F[0] xrange,yrange=[r[:2] for r in ranges] xy_data_array = [[g(x, y) for x in xsrange(*ranges[0], include_endpoint=True)] for y in xsrange(*ranges[1], include_endpoint=True)] + if region is not None: + import numpy + + xy_data_array = numpy.ma.asarray(xy_data_array,dtype=float) + + m = F[1] + + mask = numpy.asarray([[m(x, y)<=0 for x in xsrange(*ranges[0], include_endpoint=True)] + for y in xsrange(*ranges[1], include_endpoint=True)],dtype=bool) + + xy_data_array[mask] = numpy.ma.masked + g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options, ignore=['xmin', 'xmax'])) g.add_primitive(ContourPlot(xy_data_array, xrange, yrange, options)) -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org