I have already written about several undocumented hidden properties in the past. Today, I would like to introduce one of my favorites: the plot-line’s LineSmoothing property. Compare the following two outputs:
% Standard (non-smoothed) plot-line plot(1:5,2:6,'o-', 'LineWidth',1);
% Smoothed (anti-aliased) plot line plot(1:5,2:6,'o-', 'LineWidth',1, 'LineSmoothing','on');
Line smoothing (aka anti-aliasing) works by inserting semi-transparent pixels at the edges of the actual plot line, thereby giving an optical illusion of a smooth line without pixelization effects. In Matlab, antialiasing is done automatically for fonts, but unfortunately not for plot lines that have non-default line-widths.
Line-smoothing has been around for a long time. It was even mentioned in a user comment on the official MathWorks Pick-of-the-Week article that introduced the excellent Myaa utility (Myaa uses applicative Matlab code to create anti-aliased plot effects).
However, to this day (R2010a), the LineSmoothing property remains hidden, undocumented and not officially supported.
Perhaps the reason for this is the following bug: text objects that cross a smoothed line are obscured by it. Depending on the text size and the line width, the text might be completely hidden, although its handle indicates that it is visible and despite it being created after the plot line!
plot(1:5,2:6,'.-', 'LineWidth',5, 'LineSmoothing','on'); text(2.2,3.5, 'abcd','Color','r');
Note that this does not happen for standard (non-smoothed) lines:
plot(1:5,2:6,'.-', 'LineWidth',5); text(2.2,3.5, 'abcd','Color','r');
Luckily, there’s a very simple workaround for this, that allows both line-smoothing and non-obstruction: simply set the text‘s z-position to a higher value than the plot line’s. In our example, we used a simple 2D plot line (i.e., z-position = 0), so let’s set z-position=1 for our text label:
plot(1:5,2:6,'.-', 'LineWidth',5, 'LineSmoothing','on'); text(2.2,3.5,1, 'abcd','Color','r');
MathWorks have developed a special workaround for the LineWidth problem in OpenGL, using
Unfortunately, as far as I could tell it has no visible effect in this particular case (perhaps I forgot to do something?).
One final note: the LineSmoothing property also exists for line, patch, surf, mesh and other similar objects.
Do you use have any other favorite undocumented/hidden property? If so, please share it in a comment below.
- Plot LimInclude properties The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....
- Controlling plot data-tips Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....
- Axes LooseInset property Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....
- Draggable plot data-tips Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...
- Getting default HG property values Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...
- Undocumented scatter plot jitter Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...