How to use clabel with log scale axes?
3 views (last 30 days)
Show older comments
Hello,
Does anybody know how to get nice contourlabels (clabel) in plots with logaritmic axes. I have a workaround where I plot the log data in the contour and replace the x and ytick labels of the plot. However I am not happy with result because the labeling does work during zoom. See my example.
[x, y]=meshgrid(logspace(-3,3,1000),logspace(-2,2,800));
%some function
z = 3*(1-log10(x)).^2.*exp(-(log10(x).^2) - (log10(y)+1).^2) ...
- 10*(log10(x)/5 - log10(x).^3 - log10(y).^5).*exp(-log10(x).^2-log10(y).^2) ...
- 1/3*exp(-(log10(x)+1).^2 - log10(y).^2);
figure
hA1 = subplot(1,1,1);
[cS hCS]=contour(x,y,z,[-6:1.5:8]);
set(hA1,'xscale','log','yscale','log');
hLS = clabel(cS,hCS);
title('cluttered contour labels, nice x and yticklabel, also when zoomed')
figure
hA2 = subplot(1,1,1);
[cS hCS]=contour(log10(x),log10(y),z,[-6:1.5:8]);
hLS = clabel(cS,hCS);
%modify xyticklabel manualy
set(hA2,'xticklabel',num2str(10.^str2num(get(hA2,'xticklabel'))))
set(hA2,'yticklabel',num2str(10.^str2num(get(hA2,'yticklabel')),2))
title('nice contour labels, messy x and yticklabel, does not work for zooming')
outputs:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145956/image.png)
and
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145957/image.png)
please try zooming
Anyone ideas how to plot nice contourlabels in contour plots with logaritmic axes?
Patrick
1 Comment
dpb
on 3 Nov 2014
Edited: dpb
on 4 Nov 2014
No solutions at hand, sorry, and not enough time to try to help at the moment.
I can only suggest
a) searching File Exchange and see if anybody else has had the same desire and already solved it or
b) to solve the zoom problem you'd have to write callback functions to do what you're doing now at each zoom operation.
The messy tick labels are also a pita that's been a continual pet peeve of mine that TMW didn't allow the TeX interpreter in the 'ticklabel' so you have to use text to write them formatted when faced with the problem of log axes with other than the standard decade ranges. There've been a coupld of postings on the subject with the last month or so that illustrates how to solve that minor portion of the problem.
ADDENDUM
While it probably(*) won't solve your immediate problem, I strongly suggest submitting this problem to TMW official support at www.mathworks.com for inclusion in the enhancements-needed database.
(*) It's always possible one of their handle graphics gurus just might take pity and provide workaround code if you have current support.
Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!