How can I add a colorbar that lines up with an axis in a surf plot?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nicholas Sullivan
am 10 Jun. 2015
Beantwortet: Kelly Kearney
am 10 Jun. 2015
I have a surface plot and I want to make a colorbar that is in the same location as the vertical axis numbers and label. I also want it to line up with the numbers on the axis. Is this possible?
0 Kommentare
Akzeptierte Antwort
Kelly Kearney
am 10 Jun. 2015
Determining the plotting area of a 3D axis can be tricky. But if you don't mind a little manual clicking, the following method works. When the cursor appears, click first of the lower vertex of the z-axis, then on the upper vertex. This assumes the colorbar will go to the left of the axis and that you're using the default view, but a few little modifications can move it to the right or deal with other rotations.
[x,y,z] = peaks(20);
surf(x,y,z)
cb = colorbar;
axtmp = axes('position', [0 0 1 1], 'color', 'none');
[xax, yax] = ginput(2);
delete(axtmp);
cbpos = get(cb, 'position');
set(cb, 'position', [xax(1)-cbpos(3) yax(1) cbpos(3) diff(yax)]);
set(gca, 'clim', get(gca, 'zlim'));
set(cb, 'Ticks', get(gca, 'ztick'));
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!