Search code examples
matlablatexfigurecolorbar

How do I change the font of colorbar to latex?


I have a MATLAB figure with a colorbar. I am trying to change the font of the ticks of the colorbar to LateX. I've tried this,

hBar = colorbar;set(hBar, 'FontName', 'interpreter', 'latex');

But MATLAB gives this error,

"Error using matlab.graphics.illustration.ColorBar/set Invalid parameter/value pair arguments."


Solution

  • If you want to change the interpreter for the tick labels to LaTeX, you have to set the TickLabelInterpreter property of the colorbar:

    hBar = colorbar;
    set(hBar, 'TickLabelInterpreter', 'latex');
    
    % Or...
    
    colorbar('TickLabelInterpreter', 'latex');
    

    Also note this excerpt from the documentation in relation to the font:

    The displayed text uses the default LaTeX font style. The FontName, FontWeight, and FontAngle properties do not have an effect. To change the font style, use LaTeX markup within the text.