Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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
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()') ])