contourf without isoline but with label

조회 수: 9 (최근 30일)
roudan
roudan 2021년 7월 16일
댓글: dpb 2021년 7월 16일
Hi
below code from below question to remove the isoline. But I'd like to keep label with it. How to do it?
[C,h] = contourf(peaks(20),10);
set(h,'LineColor','none')
I do have below code, but once I used set(h,'LineColor','none'), the below code does't work anymore.
clabel(ct,hct,'FontWeight','bold','FontSize',contourlinefontsize_right,'Color','k');
ok, here is the whole code you can exerciese:
Z = peaks ;
[c,h]=contourf(Z); hold on ;
set(h,'LineColor','none')
h.LineWidth = 0.001;
clabel(c,h,'FontWeight','bold','FontSize',10,'Color','k');
Thanks

채택된 답변

DGM
DGM 2021년 7월 16일
Set linecolor to 'flat'
[C,h] = contourf(peaks(20),10);
set(h,'LineColor','flat')
clabel(C,h,'FontWeight','bold','FontSize',5,'Color','k');
  댓글 수: 3
roudan
roudan 2021년 7월 16일
oh, my goodness, Mr DGM. you saved my day. I have been googling and trying for 3 hours and never succeed. Now you can just solve it. That is the beautty of knowledge and expertise. Thank you DGM. I really appreciate it!
dpb
dpb 2021년 7월 16일
Huh. That's the one option I never thought of as having any effect...good catch! Certainly much easier than the alternative...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2021년 7월 16일
This one is nearly intractable -- the underlying text handles are tied to the color of the line, although one could set their color independently by use of the CData property for each.
BUT, the kicker is, internally, the handles to those text objects comes and goes depending upon whether the 'LineStyle' or 'LineColor' property are set -- if either of those is set to 'none' to hide the lines, then the text objects themselves disappear entirely, they aren't just hidden.
So (and I didn't have time just now to try to do it), the only way I see to go at it would be to
  1. create the plot; save the handle to the contour object [~,hC]=contourf(...);
  2. make sure lines/contour levels are showing
  3. save array of text object handles from undocumented TextPrims property -- hTxt=hC.TextPrims;
  4. retrieve all the poop about each -- including 'VertexData', 'Rotation', 'String', etc., etc., ...
  5. turn off 'LineStyle' by hC.LineStyle='none';
  6. now redraw all the text objects from the data saved in step 4) above.
Without such machinations, the next best thing to no line might be
h.LineStyle=':';
to used the dotted line as subtly as possible. Unfortunately, HG internals is such that even 'LineWidth' of eps is still rendered as if were 0.5 and identically zero isn't allowed (and if were, the above behavior of deleting the text objects would also probably happen, anyways).
  댓글 수: 1
roudan
roudan 2021년 7월 16일
Thank you dpb, using linecolor='flat' will work, use 'none' will not work. see above answer. Thank you for your contribution.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by