5

I'm using the code as follows. But the figures are different when I run my code in MATLAB R2014a and R2019a (in the same computer, Win7 64bit). It seems there is a conflict between 'ShowText' and 'LineStyle' in function contourf in MATLAB R2019a ? What I want is the figure with text and no line (like the figure by R2014a). How can I get that in R2019a?

for i = 1 : 10
    for j = 1 : 10
        res(i, j) = i * j;
    end
end
contourf(res, 'ShowText', 'on', 'LineStyle', 'none');

Figure using R2014a

figure by R2014a

Figure using R2019a

figure by R2019a

Figure using R2019a using contourf(res, 'ShowText', 'on') only

figure by R2019a using "contourf(res, 'ShowText', 'on') only

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
JQY
  • 91
  • 3
  • 5
    You can use `contourf(res, 'ShowText', 'on','LineColor', 'flat');` so the LineColor will be the same as the contour color and look "transparent". But your code should also work, this is probably a bug that need to be reported to MathWork. – obchardon Aug 14 '19 at 09:30
  • @obchardon I think that's a good solution – Sardar Usama Aug 14 '19 at 09:47
  • @obchardon That's perfect! I've ever tried contourf(res, 'ShowText', 'on','LineWidth', 0); but it's not allowed by MATLAB. I haven't thought of using LineColor. Thanks a lot! – JQY Aug 15 '19 at 02:02

1 Answers1

4

After a bit of research I found this solution with the help of undocumented MATLAB:

for i = 1 : 10
for j = 1 : 10
res(i, j) = i * j;
end
end
[c,hC] = contourf(res);
clabel(c,hC)
drawnow; % Important !
set(hC.EdgePrims(:),'Visible','off');

Which gives this result in R2017b : enter image description here

Disclaimer: This solution relies on an undocumented feature of MATLAB, the results may vary depending on your version.

R2018a

Sardar Usama came up with an alternative solution for R2018ain the comments :

%drawnow; % Important !
%set(hC.EdgePrims(:),'Visible','off');
delete(hc.EdgePrims);
Arthur
  • 508
  • 2
  • 14
  • 2
    or you can just `delete(hC.EdgePrims)` instead of drawnow and setting visibilty off – Sardar Usama Aug 14 '19 at 09:48
  • @SardarUsama I did not managed to make it work, do not hesitate to improve my answer ! – Arthur Aug 14 '19 at 10:10
  • To rephrase: instead of the last two lines, you can use `delete(hC.EdgePrims);` – Sardar Usama Aug 14 '19 at 12:34
  • @SardarUsama Unfortunately this does not work when I try it.. (in `R2017b`) – Arthur Aug 14 '19 at 12:44
  • I don't know what you mean by "does not work" but I have verified it in R2018a. if you delete the EdgePrims, there will be no EdgePrims. But undocumented features can't be expected to behave as the documented ones. So... – Sardar Usama Aug 14 '19 at 12:52
  • @SardarUsama I meant removing the 2 last lines and replacing them by `delete(hC.EdgePrims);` does not provide the expected result. The EdgePrims are not effectively deleted when I test your solution in R2017b, so yes it seems to be a version issue. – Arthur Aug 14 '19 at 12:59
  • @Arthur when I run this on R2019a, the lines are still shown in the figure. So maybe this issue appears after R2018a ? – JQY Aug 15 '19 at 02:05
  • @JQY It looks like some things have changed.. Did the workaround in `R2018a` worked ? – Arthur Aug 15 '19 at 07:56