Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert infinity symbol to X axis of Matlab Bar graph?

How can I add the infinity symbol to X axis of Matlab Bar graph?

Naturally it is possible to insert the infinity symbol i.e. '\infty' for xlabel, as seen in the last line of the inserted code.
But, I want to add the infinity sign in the x axis bar not in the x axis label.
How can I do that? For the sake of detailed clarification, the following script is added bellow:

data=[1 2 3; 1 3 4; 3 1 2];
bar(data)
set(gca,'YLim',[0 3])
set(gca,'YTick',[0:0.5:3])
set(gca, 'YTickLabel',num2str(get(gca,'YTick')','%02.1f%%'))
set(gca,'Xtick',1:3,'XTickLabel',{'\infty' ; '20 dB'; '15 dB'})
xlabel('\infty dB') % x-axis label

Image showing problem

like image 898
mohsen Avatar asked Sep 29 '22 10:09

mohsen


1 Answers

How about this solution, using format_tick function from File Exchange?:

data=[1 2 3; 1 3 4; 3 1 2];
bar(data)
set(gca,'YLim',[0 3])
set(gca,'YTick',[0:0.5:3])
set(gca, 'YTickLabel',num2str(get(gca,'YTick')','%02.1f%%'))
set(gca,'Xtick',1:3)
format_ticks(gca, {'$\infty$' ; '20 dB'; '15 dB'})

enter image description here

I left out the xlabel because it interfers with the Xtick, but probably that can be easily moved to lower position.

EDIT: To fix the overlap of Xtick and xlabel add this to the end of the code:

xlabh = get(gca,'XLabel');
set(xlabh,'Position',get(xlabh,'Position') - [0 .1 0])

enter image description here

like image 168
rozsasarpi Avatar answered Oct 05 '22 08:10

rozsasarpi