Hello,
I am trying to plot a contour so that in each countour line a value (label) appears. At the moment the number of decimal places appearing in the label is 4, is there any way to force matlab to present only one decimal place, having for example 32.0, 40.4, etc. ?
Below is the code I am presently using. Thanks in advance for any help.
figure(f1)
subplot(3,1,1);
[cs,h]=contourf(xgrid,ygrid,U,10); hold on;
clabel(cs,h);
set(gca, 'CLim', [12 50]);
xlabel('$y$ $(cm)$','interpreter','latex','Fontsize',18,'Fontname','Times'),
ylabel('$z$ $(cm)$','interpreter','latex','Fontsize',18,'Fontname','Times'),
axis([83 92 1.2 3.9]);
colormap('jet')
colorbar

 채택된 답변

Walter Roberson
Walter Roberson 2018년 2월 4일

1 개 추천

[cs,h] = contourf(sort(rand(50,50)*10), 20);
clabel(cs,h);
h.LevelList = round(h.LevelList, 1);

추가 답변 (2개)

antonio ferreira
antonio ferreira 2018년 2월 4일

0 개 추천

Hello, Your suggestion does not appear to help in terms of controlling the number of decimal places, but its rather focussed on the colour of the contour label, which is not an issue to me. Can you/someone suggest me an alternative please?Thanks in advance.
antonio ferreira
antonio ferreira 2018년 2월 4일

0 개 추천

Apparently the TextPrims function controls the text label according to what is written on the post. I have therefore inserted an extra line on the code after "[cs,h]=contourf(xgrid,ygrid,U,10); hold on;", with "labels = h.TextPrims;". I am not being able to access the properties in "labels", which makes difficult to follow the example you pointed me to, since this feature is not well documented. What line in the first example you pointed me to controls the number of decimal places?

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by