MATLAB Answers

Turn off line smoothing (anti-aliasing) in 2014b?

4 views (last 30 days)
matt dash
matt dash on 12 Dec 2014
Commented: matt dash on 13 Dec 2014
Is there a way to turn off line smoothing for selected objects (line objects in particular) in 2014b? I mean, it's great and all, but for some graphics having perfectly unaliased lines is better. I tried setting the line smoothing property to off, but this seems to have no effect (and produces a warning)
Consider e.g. this:
figure
axes
line([0 1],[.5 .5])
line([.5 .5],[0 1])
For me this gives a perfect 1 pixel line for the horizontal line, but a lighter blue 2 pixel wide line for the vertical one.
(Resizing the axes makes the lines alternate between 1 and 2 pixels wide)

Answers (1)

Sean de Wolski
Sean de Wolski on 12 Dec 2014
Edited: Sean de Wolski on 12 Dec 2014
fig = figure;
fig.GraphicsSmoothing = 'off';
plot(1:10)
  1 Comment
matt dash
matt dash on 13 Dec 2014
That turns it off for the entire figure though, which is too restrictive for what I need. E.g. if i'm making a plot and manually drawing grid lines, i like a nice uniform grid, but i'd like to leave the main data series anti-aliased.
I found the "AlignVertexCenters" property, which turns off antialiasing at least for perfectly vertical or horizontal line segments. I think this will be adequate for most of my purposes. Unfortunately it looks like for patches this property only affects the edges, not the faces, so when plotting a patch with no edge, it still has slightly fuzzy borders. (E.g. i use patches to draw bar graphs, and they have this problem.)
Follow up question: AlignVertexCenters says it only works if your graphics card supports it. Can anyone tell me the consequence of setting this property on a computer that doesnt support it? Does it give an error or warning, or it just has no effect? I'm making GUIs for use on multiple platforms and i want to make sure they don't break.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!