MATLAB Answers

Anna Haup
0

How can I display greek letters as boxplot labels?

Anna Haup
さんによって質問されました 2019 年 7 月 19 日
最新アクティビティ dpb
さんによって コメントされました 2019 年 7 月 19 日
Dear all,
I am trying to plot several box plots and label each of them. Each of those labels also contains a greek character. When I use a normal line plot, I can easily change the labels to include greek characters, but with box plots the greek chracters are not displayed, but rather the tex command used to generate them. This is what I have tried:
Attempt 1:
figure
boxplot([[1:2:10]',[1:2:10]'],'Labels',{'A \lambda ', 'B \rho'})
h = findobj(gca, 'type', 'text');
set(h, 'Interpreter', 'tex');
%Attempt 2:
figure
boxplot([[1:2:10]',[1:2:10]'])
set(gca,'xticklabel',{'A \lambda', 'B \rho'},'fontsize', 14)
Neither attempt has worked.

  0 件のコメント

サインイン to comment.

製品

2 件の回答

Adam Danz
回答者: Adam Danz
2019 年 7 月 19 日
編集済み: Adam Danz
2019 年 7 月 19 日
 採用された回答

Use ASCII codes
figure
boxplot([(1:2:10)',(1:2:10)'])
set(gca,'xticklabel',{['A ' char(955)], ['B ' char(961)]},'fontsize', 14)
% lambda rho
% or with capital letters
set(gca,'xticklabel',{['A ' char(923)], ['B ' char(929)]},'fontsize', 14)c
List of greek character ASCII codes

  0 件のコメント

サインイン to comment.


dpb
回答者: dpb
2019 年 7 月 19 日

Axes labels aren't text objects; you didn't diagnose the result of your probe:
...
h = findobj(gca, 'type', 'text');
>> h
h =
0×0 empty GraphicsPlaceholder array.
>>
there wasn't any such animal found (nor would it have been the label you were after even if had found one).
Instead
figure
hAx=gca;
boxplot([[1:2:10]',[1:2:10]'],'Labels',{'A \lambda ', 'B \rho'})
hAx.XAxis.TickLabelInterpreter='tex';
Why it isn't 'tex' by default I don't know...I'd submit as an enhancement request if not a bug.

  5 件のコメント

dpb
2019 年 7 月 19 日
Ayup...just tested and as advertised the [X/Y/Z]TickLabelInterpreter property is TeX by default for a new axes; that boxplot doesn't follow convention seems a poor quality of implementation choice...
>> get(groot,'factoryAxesTickLabelInterpreter')
ans =
'tex'
>>
Anna Haup
2019 年 7 月 19 日
Agreed, I was very confused when it didn't behave like other plotting functions. Hence my slightly fumbled attempts at forcing it to work. Thank you both dpb and Adam Danz for your help!
dpb
2019 年 7 月 19 日
It also doesn't help much that for some reason TMW didn't expose the interpreter property at the axes property level--you have to go to the XAxis object handle to get to it. The label text, font, etc., are exposed but not the interpreter with which to render it--"that's just rude!"

サインイン to comment.



Translated by