During my work, I got the figure shown below
It is clear that it turns out to be a mess below 5 on the y-axis. What I want to do, is to "expand" the y-axis only in the range from 3 to 5 such that the lines are separated and can be clearly distinguished.
I tried using set(gca, 'Xtick', [0 1 2 3:.5:5 5:25]) but this didn't help at all.
Any hint is appreciated.
What I got is as shown in the figure below:
Since I am getting my data through iterative loops and even sub-loops, I couldn't manage to get the desired figure using "inset plot", it got so complicated. However, what I did is simply that I had two MATLAB figures, the original one and another copy of it with a zoom-in of the y-axis from 3.5 to 5, then I copied the zoomed one to the original one and that's it.
This practice is better than using power point or paint to get the figure since doing so in MATLAB gives MUCH more flexibility in terms of editing the two figures, resizing them, axes labeling and so on.
Hope this would help someone else.
I am using ezpolar to draw an arc on a compass plot. It's super easy,
ezpolar('1', [TH1, TH2])
to plot a circular arc with a radius 1 over the range [TH1, TH2]. However the function itself "r=1" gets displayed on the plot, which I do not want. I can't find and references to how this can be suppressed with an extra parameter or something.
I realise I could plot the arc other ways, but this is a cool function and super-compact, so I'd like to use it here and in the future.
Anyone know how to suppress the displaying of the function on the plot?
Thanks in advance
Tricky!
It looks like ezpolar is one of those MATLAB plots where a lot of things happen but nothing gets returned to the user. However I found the way using findobj.
Fiddling with the plot I realized that it is a 'Text' object what MATLAB puts in the plot, so we can try to find it with
h = findobj(gca,'Type','Text')
and then delete the text, for example with:
h.String='';
Tada!
I'm trying to calculate the slope between two points. I've tried some other methods such as imline, but none of them allows the snapping to a curve. I found out this morning that I can possibly use the data tips in the datacursormode.
So, what I want to do is:
Select two points showing the black dot for both points
Upon the second left-clicking, a line is drawn connecting the two points and a text box shows the calculated slope
If I move either black dot, the text box is updated with a new slope
I can have as many pairs as I want, many lines between a part of black dots
If either dot is deleted, the associated text box disappears along with it
I've tried things like
waitforbuttonpress;
point1 = getCursorInfo(data_cursor_mode_obj);
waitforbuttonpress;
point2 = getCursorInfo(data_cursor_mode_obj);
slope = abs((y2-y1)/(x2-x1));
text((x1+x2)/2,(y1+y2)/2,[' \leftarrow' num2str(slope) ])
This of course doesn't update the text. In fact, for some reason, Matlab complains and I don't know how to fix it.
Another thing I tried was using UpdateFcn, but a problem with it is that I can only pass one point data by doing event_obj.Position.
Your help will be greatly appreciated.
Thanks,
Eric
I was looking at this question, and the answer by Marc, and I can't get the getpts function to work as described. (BTW, I wanted to just comment on Marc's answer, but the site doesn't let me comment until a rep of 50.) According to documentation, and Marc, using
[x,y] = getpts(ax);
is supposed to restrict the user's point selection to within the axis, and prohibit point selection in the rest of the figure. Right??
Well, if so, it's not working. I'm writing a program in which I want the user to specify a part of the image to chop off. I made a figure with an image via the imagesc() command. I then try to do the following:
set(0,'CurrentFigure',1) (Because he program has more than one figure open)
ax = gca;
[x,y] = getpts(ax);
The small cross cursor comes up, and I can click and select points anywhere in the figure, including in the gray border area outside of the image. This is exactly the same behavior as I get if I run [x,y] = getpts(gcf); So, what's going on here?? Either way, the point selection is allowed in the entire figure window and NOT restricted to just the axis area where my image is...
My Matlab version is R2014a.
I would like to plot a vertical line (I'd prefer any orientation, but I'd be happy with just vertical right now) with two-color dashes, say red-blue-red-blue-...
I know I could do it like this:
plot([1,1],[0,1],'r'),
hold on,
plot([1,1],[0,1],'--b')
However, since I need to be able to move the line, among others, it should only have a single handle. How could I do this?
EDIT
Thank you for your answers. I guess I should indeed give some more information.
I have some data that is classified into different parts. I want to be able to manually adjust the boundaries between classes. For this, I'm drawing vertical lines at the classification boundaries and use draggable to allow moving the lines.
For the boundary between the red and the blue class, I'd like to have a red/blue line.
plot(ones(10,1),linspace(0,1,10),'-bs','MarkerFaceColor','r','MarkerEdgeColor','none','linewidth',6)
is what I'm actually using at the moment. However, it's not so pretty (if I want equal spacing, it becomes a real pain, and I want to give both colors the same weight), and I would like to have the possibility to use three colors (and not with marker edge and face being different, because it makes my eyes bleed).
Unfortunately, draggable does not allow me to use multiple handles, and grouping the lines with hggroup does not seem to create a draggable object.
cline looks like a promising approach, but rainbow colors won't work for my application.
You can use the code you have, and just concatenate the handles from each line into a vector of handles. When you want to change the properties of both lines simultaneously, the SET function is able to accept the vector of handles as an argument. From the documentation for SET:
set(H,'PropertyName',PropertyValue,...)
sets the named properties to the
specified values on the object(s)
identified by H. H can be a vector of
handles, in which case set sets the
properties' values for all the
objects.
Here's an example:
h1 = plot([1 1],[0 1],'r'); %# Plot line 1
hold on;
h2 = plot([1 1],[0 1],'--b'); %# Plot line 2
hVector = [h1 h2]; %# Vector of handles
set(hVector,'XData',[2 3]); %# Shifts the x data points for both lines
UPDATE: Since you mention you are using draggable from the MathWorks File Exchange, here's an alternate solution. From the description of draggable:
A function which is called when the
object is moved can be provided as an
optional argument, so that the
movement triggers further actions.
You could then try the following solution:
Plot your two lines, saving the handle for each (i.e. h1 and h2).
Put the handle for each in the 'UserData' property of the other:
set(h1,'UserData',h2);
set(h2,'UserData',h1);
Create the following function:
function motionFcn(hMoving) %# Currently moving handle is passed in
hOther = get(hMoving,'UserData'); %# Get the other plot handle
set(hOther,'XData',get(hMoving,'XData'),... %# Update the x data
'YData',get(hMoving,'YData')); %# Update the y data
end
Turn on draggable for both lines, using the above function as the one called when either object is moved:
draggable(h1,#motionFcn);
draggable(h2,#motionFcn);
I've never used it, but there's a submission by Sebastian Hölz called CLINE on the Mathworks File Exchange that seems related.
I don't know how to do exactly what you want, but presumably the reason you want to do this is to have some way of distinguishing this line from other lines. Along those lines, take a look at MathWorks' documentation on 2-D line plots. Specifically, this example:
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)
should give you plenty of ideas for variation. If you really need the two-color dashes, it might help to specify why. That way, even if we can't answer the question, perhaps we can convince you that you don't really need the two-color dashes. Since you've already ruled out the over-lapping solution, I'm fairly certain there's no solution that answers all of your needs. I'm assuming the two-colorness is the most fluid of those needs.