Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 3 ratings Rate this file 5 Downloads (last 30 days) File Size: 9.37 KB File ID: #29317 Version: 1.2
image thumbnail



John Barber (view profile)


08 Nov 2010 (Updated )

Easily create surface plots with logarithmic z-axis and color scale.

| Watch this File

File Information

LOGZPLOT is an easy way to create surface plots with both a log-scaled z-axis and log-scaled coloring. LOGZPLOT creates a plot using SURF, MESH, IMAGE, PCOLOR, TRISURF or TRIMESH, then applies the logarithmic transformation. If called without data inputs, LOGZPLOT will apply the logarithmic scaling to an existing surface plot.

Although creating a plot like LOGZPLOT's output is easy to do from the command line, getting a colorbar to display the correct data range requires some additional scaling of the color data. LOGZPLOT automatically scales the color data so that a colorbar will have a scale corresponding to the input data, even after changing the axes' 'CLim' property. To do this, LOGZPLOT attaches a listener function to the axes that corrects the color data scaling whenever the 'CLim' property changes. This allows the user to specify 'CLim' values in the normal units of the original data.

See the help text for additional information and examples.

MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
08 Nov 2014 John Barber

John Barber (view profile)


Thanks for the feedback. Yes, the changes to the graphics in R2014b introduce some incompatibilities with logzplot(). I hope to have some time to update it for compatibility, but it will probably be a month or two at the earliest.


Comment only
29 Oct 2014 Cornelis

dear John, thanks for sharing.

Just an observation FYI:
in R2014b I had to make changes in lines 808 and 810 as in this version 'Location' is without any upper Cases :

switch get(hCbar,'Location')
case {'East','West','EastOutside','WestOutside','east','west','eastoutside','westoutside'}
scaleName = 'YScale';
case {'North','South','NorthOutside','SouthOutside','north','south','northoutside','southoutside'}
scaleName = 'XScale';

Then still no luck because in:
line 815 >> set(hCbar,scaleName,'log')

Error using
There is no YScale property on the ColorBar class.

Kind of takes away a/the main feature of your function. Is there anything that can be done to make it r2014b compatible?

Comment only
18 Jun 2013 Rhys

Rhys (view profile)

31 May 2012 John Barber

John Barber (view profile)


Thanks for the suggestions. I've included them in the latest version.


Comment only
16 May 2012 Felipe

Felipe (view profile)

Thanks a lot for your submission. I like specially the colorbar update callbacks. I was mostly interested in the log-scaled colorbar. I wanted to use it for images. I could get the picture that I wanted plotting the data as a surface then setting view(2) and 'EdgeColor','none', but for large images it's slower. So I've added support for images, e.g., logzplot(X,Y,Z,@image,'colorbar'), or h=image(Z); logzplot(h,'colorbar'); I also needed the colorbar handle (to adorn it with titles, etc.) so now it's a return value. Here are the diffs in case you want to incorporate:

< function h = logzplot(varargin)
> function [h,h2] = logzplot(varargin)
< plotFunList = {'surf','pcolor','mesh','trisurf','trimesh'};
> plotFunList = {'surf','pcolor','mesh','trisurf','trimesh','image'};
< case {'surf','mesh','pcolor'}
> case {'surf','mesh','pcolor','image'}
> case 'image'
> CDataName = 'CData';
> pcolorFlag = 1; % avoid setting ZScale.
> case 'image'
> CDataName = 'CData';
> pcolorFlag = 1; % avoid setting ZScale.
> if isvector(x), x2 = x; else x2 = x(1,:); end
> if isvector(y), y2 = y; else y2 = y(:,1); end
> hAx2 = gca();
> axes(hAx) %#ok<MAXES>
> hSurf = plotFun(x2,y2,CData);
> axes(hAx2) %#ok<MAXES>
> set(hAx, 'YDir','normal')
> hCbar = [];
< LogZPlotColorbar(hFig,hAx)
> hCbar = LogZPlotColorbar(hFig,hAx);
< if nargout == 1
> if nargout > 0
> if nargout > 1
> h2 = hCbar;
> end
< case {'surface','patch'}
> case {'surface','patch','image'}
< hSurf = findobj(hAx,'Type','surface','-or','Type','patch');
> hSurf = findobj(hAx,'Type','surface','-or','Type','patch','-or','Type','image');
< function LogZPlotColorbar(hFig,hAx,hCbar)
> function hCbar = LogZPlotColorbar(hFig,hAx,hCbar)

Comment only
16 May 2012 Felipe

Felipe (view profile)

28 Dec 2011 gmart

gmart (view profile)

30 Nov 2010 1.1

- Added support for trisurf and trimesh plots
- Improved speed and memory performance
- Improved colorbar support

31 May 2012 1.2

- Added support for plots using IMAGE
- Added colorbar handle output
- Fixed CLim equality test bug

Contact us