Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

colorbar trick Label in log scale

2,393 views
Skip to first unread message

Marwa Helemish

unread,
Apr 21, 2009, 6:33:02 AM4/21/09
to
Hi,
I have this code,
surf(x,y,abs(D));
set(gca,'Zscale','log')
h=colorbar;
set(h,'YScale','log')
xlabel('x-axis')
ylabel('y-axis')
zlabel('function')
please try it
the trick label in color bar and its color didn't be associated to those corresponding one in 3D.
Awaiting your reply

thank you in advance

Marwa

Oliver Woodford

unread,
Apr 21, 2009, 8:07:02 AM4/21/09
to
"Marwa Helemish" <hele...@iee.tu-dresden.de> wrote in message <gsk7ct$r37$1...@fred.mathworks.com>...

Do you want the colormap to be linear in the log scale? If so you could use real2rgb (http://www.mathworks.com/matlabcentral/fileexchange/23342) to generate the log scale texture map as follows:

% Generate data
[X Y Z] = peaks(50);
Z = abs(Z) * 100 + 1;
% Generate log-scale texture
T = real2rgb(log(Z), 'jet');
% Render the surface
surf(X, Y, Z, T);
set(gca,'Zscale','log','Clim',[min(Z(:)) max(Z(:))]);
% Generate the colorbar
colormap jet;

Marwa Helemish

unread,
Apr 21, 2009, 8:32:03 AM4/21/09
to
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message <gskct5$466$1...@fred.mathworks.com>...

Hi,
thank you, your example is very nice, and exactly what I want
but, my matrix is not square like matrix in your example,for that reason, it dosenot work in my work,
if you have solution, give me it please
size(x)=40X1
size(y)=2X1
size(Z)=2X40

thank you in advance

Oliver Woodford

unread,
Apr 21, 2009, 8:42:02 AM4/21/09
to
"Marwa Helemish" <hele...@iee.tu-dresden.de> wrote in message <gskec3$cpu$1...@fred.mathworks.com>...

Any size of matrix works for me. In the example below my matrices are the same size as yours:

% Generate data
[X Y Z] = peaks(40);


Z = abs(Z) * 100 + 1;

% Resize the data to be rectangular
X = X(1,:);
Y = Y(1:2,1);
Z = Z(1:2,:);

Oliver Woodford

unread,
Apr 21, 2009, 9:12:01 AM4/21/09
to
"Oliver Woodford" wrote:
> Do you want the colormap to be linear in the log scale? If so you could use real2rgb (http://www.mathworks.com/matlabcentral/fileexchange/23342) to generate the log scale texture map as follows:
>
> % Generate data
> [X Y Z] = peaks(50);
> Z = abs(Z) * 100 + 1;
> % Generate log-scale texture
> T = real2rgb(log(Z), 'jet');
> % Render the surface
> surf(X, Y, Z, T);
> set(gca,'Zscale','log','Clim',[min(Z(:)) max(Z(:))]);
> % Generate the colorbar
> colormap jet;
> h=colorbar;
> set(h,'YScale','log')

Incidentally, this should be possible without using real2rgb, but I can't quite get it to work. Here is my attempt:

% Generate data
[X Y Z] = peaks(50);
Z = abs(Z) * 100 + 1;

% Render the surface
surf(X, Y, Z, log(Z));
set(gca,'Zscale','log');


% Generate the colorbar
colormap jet;
h=colorbar;

lims = [min(Z(:)) max(Z(:))];
set(get(h, 'children'), 'Ydata',lims);
set(h,'YScale','log', 'Ylim', lims);

Marwa Helemish

unread,
Apr 21, 2009, 9:17:02 AM4/21/09
to
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message <gskeup$m1v$1...@fred.mathworks.com>...

%%%%%%%%%%%%%%%%%%%%%%%55
Hallo,
Thank you again for you quick reply,the log scale (trick label) of the 3D surf is not the same for color bar, this is the problem

Marwa Helemish

unread,
Apr 21, 2009, 9:26:02 AM4/21/09
to
"Marwa Helemish" <hele...@iee.tu-dresden.de> wrote in message <gskh0e$bns$1...@fred.mathworks.com>...
%%% the same results can be obtained when I defind the color matrix of the surf function as
C=log10(abs(Z));
surf(X,Y,Z,C)
set(gca,'ZScale','log')
but still also the tricklabel in the color bar, it appears completely unlike the Zscale of surf plot


Oliver Woodford

unread,
Apr 21, 2009, 9:50:16 AM4/21/09
to
"Marwa Helemish" wrote:
> Hallo,
> Thank you again for you quick reply,the log scale (trick label) of the 3D surf is not the same for color bar, this is the problem

The colorbar colors and values (i.e. tick labels) coincide with the colors and Z values of the surface using the code from my first example. What more do you want? Please be as explicit as you can.

Marwa Helemish

unread,
Apr 24, 2009, 5:24:02 AM4/24/09
to
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message <gskiuo$qdq$1...@fred.mathworks.com>...


Hallo,
Many thanks, it works,
thank you Oliver
Regards
Marwa

Patrick Schneider

unread,
Feb 11, 2010, 3:31:04 PM2/11/10
to
"Marwa Helemish" <hele...@iee.tu-dresden.de> wrote in message <gss0fi$igr$1...@fred.mathworks.com>...

Oliver,

I have been unable to get your solution to work out for using a filled contour plot instead of a surf plot because the different inputs.

I have however figured out how to get the plots to work right using multiple axes.

It looks a bit screwy in the matlab figure, but the Jpg it generates looks fine. If anybody finds this thread and can help me clean it up a bit, I would appreciate it. I am new to using axes and handle lables, so I might be doing some unnecessary steps

% x data in x_scale, y data in y_scale and z data in z2
figure1 = figure('Name','fbw2');
% Create axes
axes1 = axes('Visible','off','Parent',figure1,'CLim',[min(z2) max(z2)]);
% Create axes
axes2 = axes('Parent',figure1,'Layer','top');
box(axes2,'on');
hold(axes2,'all');

% Create contour
contour(x_scale,y_scale,log(z2),200,'LineStyle','none','LineColor',[0 0 0],...
'Fill','on',...
'Parent',axes2);

% Create colorbar
cb1 = colorbar('peer',axes2,'YScale','log','YMinorTick','on','FontSize',14);

% Create colorbar
cb2 = colorbar('peer',axes1,'YScale','log','YMinorTick','on','FontSize',14);

axis tight

set(gca, 'FontSize',14)
colorbar(cb1,'delete')

saveas(figure1,'log_fbw.jpg')

0 new messages