How can one adjust the format of the numbers displayed on a contour plot using clabel and a vector specifying the levels of the contours?
13 次查看(过去 30 天)
显示 更早的评论
I have Reduced my code to this simple form. My code actually calculates the vector V that sets the contours in an evenly spaced way no matter what. Well equal area way to be exact. How can I control the format of the numbers displayed in the labels? IE e,g,f, precision of 3 etc.... The code below provides the form XXXXX.XXXXXX but I want say x.xxe^x in the labels on the contour plot for example. I have tried to find a tick or label but didn't see them available in the get / set command for contour / clabel which is how I would have approached this for other axis objects like colorbar.
clear all, clc, format short eng, format compact,
a=linspace(0,100,100);
[X,Y] = meshgrid(a,a);
Z = X.^2 .*Y.^2;
V =[60.6005e+003 405.3483e+003 1.2596e+006 2.9207e+006 5.7763e+006,...
10.6068e+006 18.7857e+006 34.3230e+006];
figure(1)
clf
grid on, hold on,
[C,h] = contour(X,Y,Z,V,'-k');
clabel(C,h,V,'LabelSpacing',1000),
hold off,
0 个评论
采纳的回答
Walter Roberson
2012-10-11
text_handles = clabel(...) returns the handles of text objects created by clabel. The UserData properties of the text objects contain the contour values displayed. If you call clabel without the h argument, text_handles also contains the handles of line objects used to create the '+' symbols.
So to get the format you want, call clabel and record the handles, then loop through the handles fetching the UserData, formatting that number as desired, and set() the String property of the text handle to the new string, possibly also setting the Interpreter property as well if you want to use LaTeX superpositioning for the exponents.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!