How to remove artifacts in plots?

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 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Jun. de 2015
I am not following you, what is exactly your problem?
Adrie
Adrie el 22 de Jun. de 2015
See little bumps in figure below. (I forgot to mention that I use MATLAB R2011B.)

Iniciar sesión para comentar.

 Respuesta aceptada

Mike Garrity
Mike Garrity el 22 de Jun. de 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 comentarios

Adrie
Adrie el 22 de Jun. de 2015
Editada: Adrie el 22 de Jun. de 2015
I forgot to mention that I use MATLAB R2011B. Your answer seems a valid explanation to me. I will discuss upgrading with our IT people. Do I have other options than rounding the data or changing the renderer setting if I have to continue using R2011B? (The OpenGL renderer doens't show the 'bumps', but it has other problems.)
Mike Garrity
Mike Garrity el 22 de Jun. de 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 el 23 de Jun. de 2015
Editada: Adrie el 23 de Jun. de 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!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 22 de Jun. de 2015

Editada:

el 23 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by