MATLAB R2014b: Rendering plots with lines in the same place - matlab

Since version R2014b, MATLAB now renders graphics nicely anti-aliased (finally!)
However, this causes a glitch in the way it displays some of my figures. If I plot a line, use hold on and then plot another line in exactly the same place with a different colour, the line appears in a mottled combination of both colours. In the past, the line would simply appear as the last colour that was plotted in that location.
Here's an example of a trace in blue, with some sections (the steeper bits) showing a green line. In previous MATLAB versions, the green lines would be continuous, but now some of the blue line shows through.
Is there a neat way to work around this in the new version, or do I have to ensure that I remove any existing lines before plotting in the same place?

When overplotting, the new anti aliasing plots can have some bleed through, try
set(gcf,'GraphicsSmoothing','off')
To see if it restores the functionality you're used to.
Ref:
http://www.mathworks.com/matlabcentral/answers/157758-how-do-i-turn-off-antialiasing-in-matlab-r2014b

Related

MATLAB R2014b switch back to old color scheme?

As announced, MATLAB R2014b adopts a new color scheme, which sort of replaces red with orange and blue to gray blue.
I would like to opt back for the old scheme. How may I do this?
P.S.:
If I am simply plotting dot, lines, and all that, I can just specify the color myself. However, this is not the case.
I am calling a sophisticated drawing function, which displays the heat map with the MATLAB color scheme. They used to be "blue for cold, and red for hot", and now they become "gray blue for cold, and yellow for hot". It is just counter-intuitive!
Therefore, to avoid modifying the function, I would rather switch the whole graphics system back to pre-R2014b scheme.
The old default colormap is still available - it's called jet.
If you want to set the colormap for individual axes or figures back to the old default, you can do that with colormap(figHandle, jet) or colormap(axesHandle, jet).
To change it for all your plots, try set(groot, 'DefaultFigureColormap', jet). You may need to set that each time you start MATLAB, so perhaps you might want to put the command into a startup.m file.
However I'm not sure I agree that the new colormap is less intuitive; in fact there is quite a bit of solid evidence that it is much worse in some very specific ways. That's why they changed it. Your choice though...

How to modify the visibility of different layer in a figure plotted by Matlab when I finished the plotting?

A figure file is saved. When several lines are intersected, I want to make one of the line visible. How should I modify the different layer of the lines without re-plotting the figure?
Use uistack (see doc). For example, after:
figure
hold on
hblue=plot([1 2],[3 4],'b','LineWidth',5);
hred=plot([1 2],[4 3],'r','LineWidth',5);
the red line is on top (and the blue line would not be seen if the the red line covered it). Then, if you use uistack(hblue,'top'), the blue line is brought to the top. Other options to reorder plots, instead of top, are up, down, and bottom. You can optionally specify the number of steps up or down (e.g. uistack(h,'up',2) to move a handle two layers up - though no need in my simple example).
If, as you say, the 'figure file is saved', and you don't have the handles for the plots, (hblue and hred in my example), after loading the plot, you can get the handles using get(gca,'children').
If I understood you correctly, try to use hold on before plotting...

Line detection using PIL

Given an image consisting of black lines (a few pixels wide) on white background, what is a good way to find the coordinates along the the lines, say for every 10th pixel or so? I am considering using PIL for the task, but other python or java-based libraries would also be OK.
Ideally the coordinates would point to the middle of the line, but as the lines are narrow, it's enough that they point somewhere inside the line.
A very short line or a point should be identified with at least one coordinate.
Usually, Hough transformation is used to find lines. It gives you the parameters describing the line (which can be transformed easily between different representations), and you can sample this function to get your sample points. See http://en.wikipedia.org/wiki/Hough_transform and https://stackoverflow.com/questions/tagged/hough-transform+python
I only found this http://coding-experiments.blogspot.co.at/2011/05/ellipse-detection-in-image-by-using.html implementation in python, which actually searches for ellipses.

Strange behavior in Matlab when exporting figure to eps, pdf

When I make a figure in Matlab, with a legend and a rectangle that touches the y axis (strange, I know) upon exporting the figure to eps (or pdf) I've noticed that the rectangle obtains the line-style of the last line drawn (rather than what the rectangle was drawn with)
This behaviour also occurs for rectangles drawn after the one that touches the axis...
This doesn't happen if the rectangle is drawn before the legend is created....
Needless to say, it took me half a day to create a minimal example:
clf
L=plot(X,sin(X),'--');
legend(L,'sin(x)')
rectangle('position',[0.001,.1,.7,.7])
rectangle('position',[0,.5,.6,.7])
rectangle('position',[0.001,.3,.5,.7])
%legend(L,'sin(x)')
On the screen the 3 rectangle have solid lines, as they should. but once they are exported, the result has the last two with dashed lines (like the sin(x)). If the legend command is done later (as in the commented out line), everything works as it should....
Is this a feature or a bug?
This is not a feature. I am submitting this to development.
You found a workaround that works with minimal code gymnastics. I would document it in your code so someone does not change it unknowingly and move on.
If you are open to other output formats, notice this is not an issue with formats that use an output filter of MATLAB.
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/print.html
(Graphic Format Files section, right column in table)
-Doug, Advanced Support at MathWorks dealing with graphical issues.

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');