Creation of a colorbar with quantized solid block-like colors and 180º rotation of the colobar label

8 visualizaciones (últimos 30 días)
Hello everyone,
I am dealing with the following type of figure
u1=figure(i)
imagesc(pulse_duration.*(10^(12)),amplitude_field.*(mu0*10^3),matrix')
clr1=colorbar('YTickLabel',{'0','\pi/2','\pi','3\pi/2'},'YTick',[0:pi/2:3*pi/2]);
ylabel(clr1,'Relative angle, $\phi \, \, \left( \mathrm{rad} \right)$','Interpreter','Latex','FontSize',14);
xlim([0 60]);
ylim([0 20]);
caxis([0 3*pi/2]);
set(gca,'TickLabelInterpreter','latex','FontSize',14)
set(gca,'Ydir','normal')
set(u1,'Units','Inches');
posu1=get(u1,'Position');
set(u1,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[posu1(3),posu1(4)])
This results in a figure of the type of the attached file called "1". Referring to this figure and code, I would like to make some changes. The first of these, the matrix called "matrix" in my code is a matrix made up of only the following values: 0, pi/2, pi, and 3*pi/2. This being the case, the ideal would be to create a colorbar which would be made up of only four solid blocks, with no color gradient between them, representing the aforementioned values. Also, it would be great if there was some way to center the label "0", "pi/2", "pi", and "3pi/2" in the middle of their corresponding blocks. I would also like to see if it would be possible to eliminate, in that case, the small ticks that mark the appearance of the aforementioned labels currently in the colorbar. Finally, I was wondering if it is possible to rotate the colorbar label "Relative angle..." 180º degrees, as it can be seen in the attached file called "2", keeping its position centered with respect to the total length of the colorbar.
Thank you for your attention.

Respuesta aceptada

darova
darova el 16 de Jun. de 2020
This should be helpfull
clc,clear
clf
h = colorbar('location','north');
set(h,'xticklabel','')
txt = {'0' 'pi/2' 'pi' '3*pi/2'};
for i = 1:4
h1 = annotation('textbox', [0.175*i+0.05 0.81 1 0.1], ...
'string', txt{i}, ...
'edgecolor','none');
end
cm = jet(4);
colormap(cm)

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by