SageMath plot: Axis label only partly in LaTeX style. Why?

For bigger scripts it makes sense to define functions outside of the interact def function. Here it is the function g(), which is defined before the def function. I'd like to use this function name as argument for both plot() and as argument for setting the label of the y-axis.

• This works fine as plot argument: plot( g(a,x), ... )
• For the y-axis I can use g() and get the correct expression, but its shown in bold. How can I manage to get the italic latex style for this y-axis label? Remark: The usual way to set the label of the y-axis ( '$a*x^3$' ) works well, but this is by far not as flexible as using ( eval('g()') ), because g can be changed.

Do you have any hint, how eval('g()') in p.axes_labels can be handled in a way, that the y-axis also has a latex style font?

Here is a working minimal code exmple:

var('a, x')
g(a,x) = a*x^3
@interact
def _(a=slider([-5..5], default=2, label='Param a: ')):
p = plot(g(a,x),(x,-3,3), color='purple')
# p.axes_labels([ '$x$', '$a*x^3$' ])
p.axes_labels([ '$x$', eval('g()') ])
edit retag close merge delete

Sort by » oldest newest most voted You can do this to achieve what you want:

p.axes_labels([ '$x$', '$'+latex(g())+'$' ])
more

1

Thanks a lot -- this works like a charm. I was not aware of this trick: to concatenate the string for the label from several partly strings. But afterwards it's clear and pure Python syntax. Thanks again, this helped to make the real sample for my students look much better.