Ask Your Question
1

enriched contour plot

asked 2021-08-08 17:52:23 +0200

JC gravatar image

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).

var('x,y')
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")
C

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,

JC

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-08-08 22:15:15 +0200

tmonteil gravatar image

If you look at the plot, C, you can see that there are 3 plots:

sage: list(C)
[ContourPlot defined by a 100 x 100 data grid,
 Line defined by 203 points,
 Point set defined by 4 point(s)]

You can change the zorder of the point plot with

C[2].set_zorder(10)

Then you get the points above the other plots.

edit flag offensive delete link more
0

answered 2021-08-08 21:35:15 +0200

rburing gravatar image

You can add zorder=1 to the bounding circle and zorder=2 to the points.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-08-08 17:52:23 +0200

Seen: 132 times

Last updated: Aug 08 '21