1 | initial version |
(I'd tried to write the following lines as comments to @Emmanuel Charpentier's answer, but I had problems with formatting)
In the preceding answer, I think that the correct syntax is lambda x,z: (x^2+z^2...
. Perhaps it is clearer to define before the region to be included. In order to color the excluded region, you can also plot it with region_plot
and then combine everything in a single figure. Try, for example, the following complete example:
# Variables
var("x,y")
# f is a function with poles in (0,0), (1,0), (0,1), (1,1)
f(x,y) = 1/(x^2+y^2) + 1/((x-1)^2+y^2) + 1/(x^2+(y-1)^2) + 1/((x-1)^2+(y-1)^2)
# Region where contour lines should be plotted
def region_to_include(x,y):
return x^2+y^2>0.1 and x^2+(y-1)^2>0.1 and (x-1)^2+y^2>0.1 and (x-1)^2+(y-1)^2>0.1
# As an alternative:
#def region_to_include(x,y):
# return (x^2+y^2-0.1) * (x^2+(y-1)^2-0.1) * ((x-1)^2+y^2-0.1) * ((x-1)^2+(y-1)^2-0.1)
# Region to be excluded
def region_to_exclude(x,y):
return not region_to_include(x,y)
# Contour plot on the desired region
c = contour_plot(f(x,y), (x,-1,2), (y,-1,2), region=region_to_include,
contours= 30, plot_points=200, cmap=colormaps.jet, colorbar=True)
# Plot of the region to be excluded
r = region_plot(region_to_exclude, (x,-1,2), (y,-1,2),
plot_points=300, incol="gray", bordercol="black", borderwidth=3)
# Final plot
show(c + r, frame=True, axes=False)
See this SageCell