Ask Your Question

Revision history [back]

This seems a side effect of the default type for real values.

sage: a = 0.2; a; type(a)
0.200000000000000
<class 'sage.rings.real_mpfr.RealLiteral'>
sage: b = round(a, 1); b; type(b)
0.2
<class 'sage.rings.real_double_element_gsl.RealDoubleElement_gsl'>
sage: c = float(a); c; type(c)
0.2
<class 'float'>

Forcing values to float, or using round, produces what you expect:

TF = lambda L:list(map(float, L))
var('x,y')
f(x,y) = sqrt(x^2 + y^2)
C = contour_plot(f ,(-0.2,0.2), (-0.2,0.2), axes = True, cmap = "Spectral", 
            labels = True,  label_fmt=lambda x: "$%s$"%round(x,2), label_colors="black", 
            label_inline=True,
            label_fontsize=16,
            gridlines=True, axes_labels=["$x$","$y$"],
            ticks = [TF([-0.2,-0.1,0,0.1,0.2]), TF([-0.2,-0.1,0,0.1,0.2])],
            tick_formatter = "latex", fontsize= 16)
C.show()

image description