필터 지우기
필터 지우기

How to place a dot on a greek letter in a datatip? (interpreter not working)

조회 수: 6 (최근 30일)
Adri
Adri 2019년 4월 7일
편집: Adri 2020년 6월 13일
I am trying to create a in a datatip, in a bar plot. However, everything works fine except the "\dot" command which is not recognized by the interpreter. Notice that the tick labels and the plain worked just fine. See the picture below. Adding the "$...$" or the double "$$...$$" doesn't solve the problem. So why is the "\dot" command not recognized by the latex interpreter in the datatip?
Here is a piece of code which reproduces the issue:
figure
bar(rand(3,3))
set(gca,'TickLabelInterpreter','latex',...
'XTick',[1 2 3],...
'XTickLabel',{'$C_{L\dot{\alpha}}$','$C_{L\alpha}$','$C_{L\dot{\alpha}}$'}); % This works fine
set(datacursormode,'updatefcn',@mydatatip)
function output_txt = mydatatip(~,event_obj)
% Display data cursor position in a data tip
% obj Currently not used (replaced by ~)
% event_obj Handle to event object
% output_txt Data tip text, returned as a character vector or a cell array of character vectors
pos = event_obj.Position;
%********* Define the content of the data tip here *********%
tipname = {'$C_{L\dot{\alpha}}$','C_{L\alpha}','C_{L\dot{\alpha}}'}; % Adding $$ doens't help (the first and last label)
% Display the y value:
output_txt = {[tipname{round(pos(1))},formatValue(pos(2),event_obj)]};
%***********************************************************%
function formattedValue = formatValue(value,event_obj)
% If you do not want TeX formatting in the data tip, uncomment the line below.
% event_obj.Interpreter = 'none';
if strcmpi(event_obj.Interpreter,'latex')
valueFormat = ' \color[rgb]{0 0.5 1}\bf';
removeValueFormat = '\color[rgb]{.15 .15 .15}\rm';
else
valueFormat = ': ';
removeValueFormat = '';
end
formattedValue = [valueFormat num2str(value,4) removeValueFormat];
end
end % End mydatatip
I have tried the solution posted here with no success:
and also this one from 2017, again with no success:
Any help is appreciated!
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 4월 7일
I see that when you use datacursormode() that one of the permitted options is 'Interpreter', 'latex' . Is that something you have tried ?
Adri
Adri 2019년 4월 8일
Nope, but I tried it and it solved the problem. Thank you!

댓글을 달려면 로그인하십시오.

채택된 답변

Adri
Adri 2019년 4월 8일
The answer is to set the latex interpreter in
set(datacursormode,'updatefcn',@mydatatip,'interpreter','latex')
and not in "mydatatip" function. The dollar signs $$ are needed, of course. Thank you Walter for the help!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by