File Exchange

image thumbnail


version 1.2 (9.37 KB) by

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



View License

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.

Comments and Ratings (8)

Pablo Trucco

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.



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?


Rhys (view profile)

John Barber

John Barber (view profile)


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



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)


Felipe (view profile)


gmart (view profile)



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


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

MATLAB Release
MATLAB 7.10 (R2010a)

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

» Watch video