How can I move the colorbar in a surf plot?

17 visualizaciones (últimos 30 días)
Johannes Thewes
Johannes Thewes el 14 de Sept. de 2018
Comentada: KALYAN ACHARJYA el 16 de Oct. de 2018
When using the following code, the colorbar overlaps with the tick labels of the x-axis:
surf(peaks);
set(gca,'FontSize',28);
cb = colorbar;
I already tried to modify the x-position of the colorbar with:
pos = get(cb,'Position');
set(cb,'Position',pos + [0.05,0,0,0]);
This was unsuccessful since the whole axis is rescaled and even manually entering the retrieved original position values does not result in the original colorbar position. How can I move the colorbar to not overlap with the tick labels anymore?
Edit: The provided sample code is a simplified example and the increased fontsize is necessary for readability in my original code. My attempt to solve the problem was aimed at moving the colorbar further to the east.
  1 comentario
madhan ravi
madhan ravi el 14 de Sept. de 2018
Editada: madhan ravi el 14 de Sept. de 2018
In which position do you want the color bar to be?

Iniciar sesión para comentar.

Respuesta aceptada

Johannes Thewes
Johannes Thewes el 16 de Oct. de 2018
The following answer was provided by Steve Schäfer from MathWorks Support and solves my problem (edited for readability):
Simply moving the colorbar object to right, by altering its Position(1) will not work, since it is then pushed out of the "visible" area, which is defined by the OuterPosition of the axes object. See documentation of Control Axes Layout for further information. The trick was to shrink the Position of the axes and make space in the visible area for the shifted colorbar. Look at the definition of TightInset, it should help you to understand how these control properties work:
f = figure;
s = surf(peaks);
ax = gca;
set(ax,'FontSize',28);
cb = colorbar('Location','eastoutside');
ax.Position = ax.Position - [0 0 .1 .1];
cb.Position = cb.Position + [.1 0 0 0];

Más respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 14 de Sept. de 2018
Editada: KALYAN ACHARJYA el 14 de Sept. de 2018
surf(peaks);
set(gca,'FontSize',8);
cb=colorbar;
  3 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 14 de Sept. de 2018
Editada: KALYAN ACHARJYA el 14 de Sept. de 2018
If you want at a specific location, mention it in the comment section.
Johannes Thewes
Johannes Thewes el 17 de Sept. de 2018
Thank you very much for your answer! Unfortunately, your solution involves the reduction of the fontsize, which should be kept constant for readability. I edited my question to mention it now.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by