问题
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