1
votes

I have a Matlab plot, in which the multiplier (in my case 10^-3) overlaps the first value. How can I move it? My colorbar

1
so @Alberto did you try my suggestion? - Benoit_11

1 Answers

1
votes

Here is a hack which works but could become a bit cumbersome. The trick is to fetch the YTickLabel of the colorbar, remove them from the plot, then plot them again but this time add a custom text that represents the exponent you want to display (here x 10^-3). The plus side is that you have complete control over the placement of this text.

Here is the code:

clear
clc

clear all; close all; clc;
A = rand(100,100)./(1e2);

figure;    
imagesc(A);

colormap jet; 
hBar= colorbar;

title('Before change','FontSize',18)

%// Get the positions of the axes and colorbar as well as the YTickLabel.
BarPos = get(hBar,'Position');
XL = get(gca,'XLim');
YTL = get(hBar,'YTickLabel');


figure;
imagesc(A);

colormap jet; 
hBar= colorbar;

%// Remove current YTickLabel
set(hBar,'YTickLabel','');

%// Text to add. Note the syntax to print a superscript.
NewText = 'x 10 ^{-3}';

%// Restore YTickLabel. This time the x 10^-3 does not appear.
set(hBar,'YTickLabel',YTL);

%// Add the text
text(XL(2)+15,-5,NewText)

title('After change','FontSize',18)

Output:

enter image description here

Hope that helps!