How do you add math symbols in colorbar ticks

夙愿已清 提交于 2019-12-23 08:38:04

问题


I can get the colorbar ticks as

figure;
hbar=colorbar;
ticks=get(hbar,'ytick');

Now how do I set the tick labels at tick(end) to be ?


回答1:


This is tricky. Normally, for axes labels and titles you can use TeX or LaTeX formatting since they are text objects and thus have an 'Interpreter' property:

xlabel('\infty');  %# Label the x axis with an infinity

However, axes objects themselves don't appear to have a way to use Tex or LaTeX formatting for their tick labels. One solution is to download the submission Format Tick Labels from Alexander Hayes on the MathWorks File Exchange, which will replace the axes tick labels with formatted text objects.

Another solution is to change the 'FontName' property of the axes to the 'Symbol' font, the 165th character of which is the infinity symbol. Here's an example:

hBar = colorbar;                           %# Create the colorbar
labels = cellstr(get(hBar,'YTickLabel'));  %# Get the current y-axis tick labels
labels{end} = char(165);                   %# Change the last tick label
set(hBar,'FontName','Symbol',...           %# Change the colorbar axes font
         'YTickLabel',labels);             %#   and update the tick labels

And here's what the colorbar will look like:



来源:https://stackoverflow.com/questions/6463554/how-do-you-add-math-symbols-in-colorbar-ticks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!