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?
조회 수: 22 (최근 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!