Enableing Line Smoothing causes axes drawing errors - matlab

In Matlab 2011a I am plotting a line, and I use the parameter ("LineSmoothing", 1) to make the line look prettier, but it causes the Y and X axis to disappear.
Does someone know what is causing this, and more importantly, how it can be fixed?
I tried the opengl('OpenGLLineSmoothingBug',1) but it didn't change anything.
Thanks in advance!

The undocumented LineSmoothing property causes the figure to automatically switch to using the OpenGL renderer. And the bug you've shown in fact affects all OpenGL-rendererd figures (regardless of this property use).
Example: (tested on R2012a in WinXP)
plot(1:10,'o-'), box on
set(gcf, 'Renderer','opengl')
note how the top and right borders of the box disappear once you execute the second line.
There are some suggested workarounds.

Related

Matlab: Export a figure made with myaa

I am trying to get better quality phase plots of complex functions made with the Complex Function Explorer of E. Wegert CFE. For this purpose I apply the Matlab anti-aliasing function myaa.m to the phase plots that are made with the CFEGUI.m. For the example screenshot of the result window below I used the setting myaa([8 8]) in the Matlab command window which means that the supersampling enlarge the figure 8x and then downscale it to 1/8 to get the original h x w.
As one can see the window of the figure has no operation icons or menu options for save or print. My question is what to do with such a figure (beside making screenshots)? Can I somehow use export-fig to save such a figure or load it in an image array and if yes, how?
It is also possible to use the setting myaa([8 1]) which results in a very large figure window that is larger than my screen (and has the unpleasant attribute that it can not be moved). It would be even better if such a whole figure could be saved (not only the visible part).
You can use getframe to grab current figure information in pixels.
However, while I do not know how this affects you, notice that MATLAB versions above 2014b (included) have already anti-aliasing. The code you linked seem to be from 2008, I am not 100% sure if it has become obsolete now.

How to prevent the fill command in MATLAB from creating boxes without "corners"

I am currently using the fill command in MATLAB to create a graph of boxes that were created using the 'fill' command (the actual code is based off this StackOverflow Question.
My issue is that the boxes that I create do not have "corners." I am attaching a PNG that illustrates the issue. Note that you have to look a little carefully since the image was heavily rendered, though in this example my arrows also look weird since they don't have edges either)
I am wondering if anyone has an idea of what might be going wrong? The boxes appear this way immediately after I use the fill command, which has the following structure:
fill(X,Y,MyFaceColor,'FaceAlpha',0.5,'EdgeColor', MyEdgeColor,'LineStyle','','LineWidth',box_line_width,'EdgeAlpha',1)
The function fill appears to leave space for corner markers if they are not explicitly defined. Hence, calling fill with the marker property will solve your problem. However, since markers and linewidths seem to work on different scales, you will have to play around with the marker size to get smooth edges.
Example:
fill(X,Y,'r','FaceAlpha',0.5,'EdgeColor', 'k',...
'LineWidth', 5,'EdgeAlpha',1 , 'marker', '.', 'markersize', 15)

Matlab: drawing rectangle when using tabpanel

I'm using TabPanel for building my GUI. The problem is, that when I'm drawing rectangle it appears outside of my axes. Problem does not exist when not using TabPanel.
I was testing 'clipping' parameter, but my object is still outside axes (fig).
Any hints?
thanks!
I have good news and bad news. (There is no answer all over the internet, I just saw unanswered requests like this one).
I had exactly the same problem. After checking, the problem is actually restrained to MARKERS (so either marker not set to none in the case of plots, or scatters). If I only plot lines, it stays clipped.
The issues is the renderer of the figure in which your plot is. You have to set it to "painter" or "zbuffer" and not "openGL". Sadly only the latter lets you plot transparent images :( . I think Matlab should fix this issue so we can have both unclipped markers and transparent images in the same figure...
K>> get(handles.output,'Renderer')
ans =
OpenGL
K>> set(handles.output,'Renderer','painter')
Yanis
edit: the solving might be similar for rectangles I hope.

Adding text annotation to figure programmatically

I would like to add text annotation to a figure from a GUI made with GUIDE. First I plot some data, than when the user clicks on a checkbox I call the text function in the event handler like this:
text(obj.XData(q), obj.YData(q)+10, int2str(q), 'Units', 'pixels');
obj is the line object itself, q is a counter for each point in the plot. It runs without errors, but nothing happens. I suppose I should 'refresh' the axis somehow, but refresh command doesn't help and I haven't found anything in the documentation.
Edit: I have found out that my code was wrong: pixel units correspond to a coordinate system where the origin is the lower-left corner of my axis control, what is not the same as my data coordinate system. I fixed this problem with ds2nfu, and when I paint before plotting everything is fine. But after plotting I see nothing. Is it possible that there is some kind of z-order problem with annotations?
As I mentioned in the comments, you should use the normalized units to place things in the same coordinate system as the data.
Now for the other problem. I'm not sure if this is a z-order issue, but if it is, you can bring the text to the front using UISTACK:
hText = text(x,y,'str');
uistack(hText, 'top')

In MATLAB, how do I change the background color of a subplot?

I'm trying to change the background color of a single subplot in a MATLAB figure.
It's clearly feasible since the UI allows it, but I cannot find the function to automate it.
I've looked into whitebg, but it changes the color scheme of the whole figure, not just the current subplot.
(I'm using MATLAB Version 6.1 by the way)
You can use the set command.
set(subplot(2,2,1),'Color','Red')
That will give you a red background in the subplot location 2,2,1.
I know you mentioned that you are using MATLAB 6.1, but it bears mentioning that in the newer versions of MATLAB you can specify additional property-value pair arguments in the initial call to SUBPLOT, allowing for a more compact syntax. The following creates an axes with a red background in the top left corner of a 2-by-2 layout:
subplot(2,2,1,'Color','r');
I'm not certain in which version of MATLAB this syntax was introduced, since the release notes going back to Version 7 (R14) don't seem to mention it.
I've not used Matlab in several years, but I think it might well be the whitebg method called after the subplot declaration, similar to the way in which you would set a title.
subplot(3, 2, 4), hist(rand(50)), whitebg('y');