Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

enriched contour plot

He there, I would like to make a contour plot for a function of two variables that is enriched with the critical points of the function. I can plot each of the graphical objects separately, but when I try to combine them, something goes wrong, looks like the contour plot will always be at the top layer, this hidding the points.

Here is the code I am using (by the way, if somone has better ide to restrict the domain of the plot, that would be nice).

def f(x,y):
    if (x^2 + y^2 <= 1.01) :
        return (x+y)*exp(-x^2 -y^2)
C = contour_plot(f ,(-1,1), (-1,1), cmap = "Spectral", labels = True,  label_fmt=lambda x: "$%s$"%round(x,1), contours = 10, label_colors="black", label_inline=True, label_fontsize=10, fill = True, axes = True, axes_labels=["$x$","$y$"], axes_labels_size=1.5, tick_formatter = "latex", fontsize= 10)
C += parametric_plot([cos(x), sin(x)], (x,0,2*pi), color = "grey", thickness = 1.5)
C +=  point([(-0.5,-0.5), (-1/sqrt(2), -1/sqrt(2)), (0.5,0.5), (1/sqrt(2), 1/sqrt(2)) ], size = 60, color = "black")

In another figure I made, I managed to circumvent the problem by putting a text with $\bullet$... not very elegant. It's quite strange that one can add decorations like vectors or text on top of a contour_plot, but not points.

Kind regards,