Strange behaviour of plot

147 views (last 30 days)
Mariano
Mariano on 11 Jun 2025 at 7:07
Commented: Rui on 17 Jun 2025 at 19:36
When I do the following plot in R2025a, I do not see the line. (Here the code runs under R2024b)
plot([0,eps,1],[0,eps,1])

Accepted Answer

Rui
Rui on 13 Jun 2025 at 15:06
This is very likely due to a particular rendering algorithm being used to render the line that is more than 1 pixel wide or on a high-DPI machine. This is a known issue, and we are actively working on resolving this.
Currently, there are a couple of workarounds you can try:
1. Set the line's 'LineWidth' property to a small value such as 0.1 to force the line to be 1 pixel wide. For example:
plot([0,eps,1],[0,eps,1],LineWidth=0.1)
2. If the decreased line width isn't acceptable, then you can try setting the 'LineJoin' property to 'chamfer'. (Caveat: this may result in some performance degradation in rendering and interactions)
plot([0,eps,1],[0,eps,1],LineJoin="chamfer")
  3 Comments
Mariano
Mariano on 13 Jun 2025 at 17:00
Thanks. Indeed, the resolution I have is 2880x1920.
Rui
Rui on 13 Jun 2025 at 19:50
Currently, we don't have an existing publicly facing bug report link.
For the plot issue here, we would expect any line plot with a LineWidth > 1 or a line plot on a high-DPI monitor may encounter this issue. The suggested workarounds are as above.

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 11 Jun 2025 at 10:30
Edited: John D'Errico on 11 Jun 2025 at 10:39
Cute. If you try this in R2025a:
small = 1e-7;plot([0,small,1],[0,small,1])
small = 1e-8;plot([0,small,1],[0,small,1])
(Sorry that Answers is still seemingly broken, not executing code.)
When done using my own copy of R2025a, the first plot shows the expected diagonal line, whereas the second is a blank figure.
Even more interesting, is if I try this:
small = 1e-8;
plot([0 small 1 1+small 2],[0 small 1 1+small 2])
the plot does contain a diagonal line, but it starts at 1, not 0.
Its worth reporting to TMW as a bug.
  7 Comments
Paul
Paul on 14 Jun 2025 at 3:14
I'm still not getting it.
small = 1e-7;plot([0,small,1],[0,small,1])
small = 1e-8;plot([0,small,1],[0,small,1])
The first one worked and the second didn't. But shouldn't they both be plotting with the same DefaultLineWidth? So either both should work or neither?
And these commands
small = 1e-8;
plot([0 small 1 1+small 2],[0 small 1 1+small 2])
resulted in half of a line? Does that imply that different parts of the line use different LineWidth?
My sense from the start of this thread is that somehow the issue was related to the use of eps (as with the OP) or "small" as in this Answer thread, but I don't see how the values in the input data to plot() can influence the LineWidth.
Rui
Rui on 17 Jun 2025 at 19:36
I think the issue here is due to the precision. For the wide line rendering, the generated line join geometry (see Line - Chart line appearance and behavior - MATLAB: LineJoin for details) might be affected/degenerated under a certain precision. This explains why two values can have different results.

Sign in to comment.

Tags

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!