How can I reposition the colorbar to not overlap my x-axis label?

13 visualizaciones (últimos 30 días)
When I create a plot with a horizontal colorbar my x-axis label is covered by the colorbar itself so that it is no longer visible. How can I reposition my colorbar so that the label is uncovered.
plot(1:10);
xlabel('\Omega_m');
ylabel('H_0');
hbar = colorbar('horiz');
xlabel(hbar,'\Omega_c h^2');

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 27 de Jun. de 2009
To ensure that overlap of the x-axis label and the colorbar does not occur, you can modify the position of the axes in the figure and the position of the colorbar. For example:
%Create Plot as before
plot(1:10);
xlabel('\Omega_m');
ylabel('H_0');
ax = gca;
hbar = colorbar('horiz');
xlabel(hbar,'\Omega_c h^2');
% Modify Colorbar to a manual setting
set(hbar,'location','manual','ActivePositionProperty','OuterPosition')
% Reset the outerposition of the colorbar to be normalized from figure
hbarPos = get(hbar,'OuterPosition');
set(hbar,'OuterPosition',[0 0 1 hbarPos(4)])
% What are the axes positions and margin info
axPos = get(ax,'Position');
axMargin = get(ax,'TightInset');
% Calculate and set new position of axes to accomodate colorbar and margins
newAxPos = [axPos(1),hbarPos(4)+axMargin(2),...
axPos(3), axPos(4)+axPos(2)-hbarPos(4)-axMargin(2)-axMargin(4)];
set(ax,'ActivePositionProperty','Position','Position',newAxPos)

Más respuestas (1)

Mr M.
Mr M. el 24 de Jul. de 2018
Error using matlab.graphics.illustration.ColorBar/set There is no activepositionproperty property on the ColorBar class.
set(hbar,'location','manual','activepositionproperty','outerposition')

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2006a

Community Treasure Hunt

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

Start Hunting!

Translated by