MATLAB Answers

Is it possible to use GraphicsSmoothing for lines and not for the figure box?

2 views (last 30 days)
Daniel on 25 Jun 2015
Commented: Mike Garrity on 14 Jul 2015
I see the benefits of having graphics smoothing option, available now since 2014 versions. However, I noticed that the smoothing is applied to all the elements in the figure. Is it possible to switch on the smoothing for the plotted lines, while switching it off when generating the figure's axis lines and box?
I have generated two examples, with and without smoothing.
I would like to have the generated figure as in the WithSmoothing case. But also the axes lines and figure box as in NoSmoothing case, where they appear very sharp and thin. I also would like to set this new configuration as default in my Matlab session.
Note: To switch on/off the smoothing option I use the following command lines: set(groot,'DefaultFigureGraphicsSmoothing','off'); or set(groot,'DefaultFigureGraphicsSmoothing','on');

Accepted Answer

Mike Garrity
Mike Garrity on 25 Jun 2015
No, it's implemented using MSAA , which means that it applies to all objects which are drawn into the window.
On the other hand, the box and ticks are drawn using AlignVertexCenters. This means that they usually don't get softened by the GraphicsSmoothing.
Consider the following example:
figure('Position',[100 100 300 200])
x = repmat(1:50,[3 1]);
y = repmat([0; 1; nan],[1 50]);
h = line(x(:),y(:),'Color','black')
ylim([-5 5])
title('AlignVertexCenters = off')
Without AVC, the lines are evenly spaced, but a little blurry. That's because some of them are landing "between pixels".
h.AlignVertexCenters = 'on'
title('AlignVertexCenters = on')
With AVC, the spacing between the lines isn't consistent, but the lines look quite crisp.
One possibility is that the LineWidth of your axes is large enough that the edges are touching multiple pixels. The default line with is 1/2 point (1/36th inch). The number of pixels that maps to is a function of your screen resolution. The math looks like this:
If that returns a number which is greater than 1, then you could try turning DefaultAxesLineWidth down a little bit.
I really need to do a post for my blog that explains all of the details.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!