10月 242016
 

I've written several articles about scatter plot smoothers: nonparametric regression curves that reveal small- and large-scale features of a response variable as a function of an explanatory variable. However, there is another kind of "smoothness" that you might care about, and that is the apparent smoothness of curves and markers that are rendered on your computer screen or other device.

Recall that anti-aliasing is a graphical technique in which some pixels along a rendered curve are set to an intermediate color, which makes a curve look smoother. For example, if a curve is being drawn by using a black pen, some of the neighboring pixels along the rendered curve are set to shades of grey, which tricks the eye into seeing a smooth curve instead of a jagged, pixellated curve.

subpixel

Anti-aliasing in ODS statistical graphics

The ANTIALIAS= and ANTIALIASMAX= options were added to the ODS GRAPHICS statement in SAS 9.2. A typical usage follows:

ods graphics / antialias=on antialiasmax=5000;

The ANTIALIAS= option specifies whether to anti-alias. By default, anti-aliasing is on. Because it can be expensive to anti-alias many thousands of graphical elements, the ANTIALIASMAX= option enables you to specify the maximum number of elements (markers or curve points) that can be in a plot before anti-aliasing is disabled for that plot. The default value is ANTIALIASMAX=4000 for SAS 9.4m3. However, the default is only 600 for earlier releases, so you might want to bump up that value when you need a presentation-quality graphic that has thousands of graphical elements. If SAS disables anti-aliasing for a plot because the plot contains too many elements, the SAS log will contain a note similar to the following:

NOTE: Marker and line anti-aliasing has been disabled because
 the threshold has been reached. You can set
 ANTIALIASMAX=1000 in the ODS GRAPHICS statement to restore
 anti-aliasing.

Subpixel rendering in ODS graphics

A related option is turning on subpixel rendering by using the SUBPIXEL option. The SUBPIXEL option was added to the ODS GRAPHICS statement in SAS 9.4m3, but it has been available on the PROC SGPLOT statement for several 9.4 releases.

The SAS documentation for the ODS GRAPHICS statement says that the SUBPIXEL option "produces smoother curves and more precise bar spacing." There is a section in the documentation titled "Subpixel Rendering," which demonstrates the impact that subpixel rendering can have on curves and bar charts.

The documentation says that subpixel rendering "is enabled by default for image output, unless the graph contains a scatter plot or a scatter-plot matrix. In those cases, subpixel rendering is disabled by default."

For me, subpixel rendering solves a problem that I've experienced when I create a large bar chart with many categories. The number of bars, the width of the bars, and the dimensions of the graph determine whether the number of pixels between bars is uniform or whether some gaps are larger than others. Sometimes you will see small uneven gaps between the bars, as shown on the left side of the following plot. However, subpixel rendering improves the plot tremendously, as shown on the right side:

subpixel2

In SAS 9.4m3 and beyond, the SUBPIXEL option applies to all plot types. Prior to SAS 9.4m3, the option applied only to line charts and bar charts; see the documentation of the PROC SGPLOT statement for the specific plots that were supported.

Try it yourself

I think the best way to learn about anti-aliasing and subpixel rendering is to try it out yourself! These ODS options apply to all ODS statistical graphics, including those that are created by SAS analytical procedures. Remember, however, that the option was only available in the PROC SGPLOT statement for 9.4 releases prior to m3.

The following SAS statements enable you to play with the options and see the differences for a simple loess curve overlaid on a scatter plot:

ods graphics / reset ANTIALIAS=off;       /* anti-aliasing off */
proc sgplot data=Sashelp.ENSO;
   loess y=Pressure x=Month / smooth=0.3 degree=2;
run;
 
ods graphics / ANTIALIAS=on ANTIALIASMAX=10000 SUBPIXEL=off; /* anti-aliasing on */
proc sgplot data=Sashelp.ENSO;
   loess y=Pressure x=Month / smooth=0.3 degree=2;
run;
 
ods graphics / ANTIALIAS=on ANTIALIASMAX=10000 SUBPIXEL=on;  /* SAS 9.4m3 */
proc sgplot data=Sashelp.ENSO;
   loess y=Pressure x=Month / smooth=0.3 degree=2;
run;

Further reading

The following resources provide further information about anti-aliasing and subpixel rendering in ODS graphics:

tags: Statistical Graphics

The post Ahh, that's smooth! Anti-aliasing in SAS statistical graphics appeared first on The DO Loop.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)