How to remove artifacts in plots?

2 views (last 30 days)
Adrie
Adrie on 22 Jun 2015
Edited: Adrie on 23 Jun 2015
The following code is an example that represents my problem:
x=0:1:100;
y=zeros(size(x));
y(1:10)=10:-1:1;
y(13:2:99)=1e-15;
plot(x,y);
Unexpectedly the plot doesn't show a straight line for x values higher than 10. The plot suggests that the 'bumps' are much higher than 1e-15, since 1e-15 shouldn't be visible when using this y axis. However, if I use the Pan tool and move the line a very tiny bit upwards, then it suddenly becomes straight.
As a temporary work-around I round all y values before making plots, but I think that shouldn't be necessary.
How can I remove the artifacts without having to round the y values?
  2 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 22 Jun 2015
I am not following you, what is exactly your problem?
Adrie
Adrie on 22 Jun 2015
See little bumps in figure below. (I forgot to mention that I use MATLAB R2011B.)

Sign in to comment.

Accepted Answer

Mike Garrity
Mike Garrity on 22 Jun 2015
I think I might know what you're referring to.
I'm guessing that you're using a version of MATLAB which is older than R2014b. For example, if I run your code in R2014a, and turn off the axes:
axis off
I get something that looks like this:
The rendering pipeline we used in earlier versions of MATLAB rounded coordinates to the nearest pixel, and in this case, the Y values 0 and 1e-15 map to adjacent pixels. This means that you see a ripple effect as the line oscillates between those two different rows of pixels.
We overhauled the rendering pipeline in R2014b. The new version doesn't represent pixel coordinates as integers. As a result, this case now looks something like this:
But you're also seeing the fact that the new renderering pipeline antialiases by default. You can turn that off using the GraphicsSmoothing property:
set(gcf,'GraphicsSmoothing','off')
and then you get this:
Assuming this is the issue you're seeing, then you're probably better off upgrading to a newer version of MATLAB than actually fiddling your data. If you have to use a version of MATLAB with integer pixel coordinates, you could try fiddling the Renderer property on the figure and see if one of the other renderers looks better, but I think that the differences will probably be pretty small.
Or perhaps I've guessed incorrectly. If you are using R2014b or later, then I would really like to know more about what you're seeing.
  3 Comments
Mike Garrity
Mike Garrity on 22 Jun 2015
Not really. Your best bet is probably explicitly setting the Renderer. But as you say, each of the renderers had some quirks in this version. What types of problems are you hitting with OpenGL?
Adrie
Adrie on 23 Jun 2015
Edited: Adrie on 23 Jun 2015
Below you see the result with the OpenGL renderer. There are no 'bumps' on the horizontal line. In fact, the horizontal blue line isn't shown at all. Furthermore I miss the black lines at the y axis and the top of the plot. I think the OpenGL renderer isn't the way to go. Therefore I will continue manipulating the data to avoid artifacts. Thanks for your help Mr. Garrity!

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!