refline - logaritmic/linear scale

Hi, I'm building a GUI that usually has tracks that have a linear scale, but I give the option for the user to change to log scale if he wants. My problem is that it is possible to add horizontal lines too, but when I switch to XScale=='log', I loose these lines.. I'm using refline function for this purpose:
hline(j,i)=refline(ax(i),[0,Depth(j)]);
Can anyone help? Best regards

7 Comments

susana - how are you switching the scale to log? Are you re-plotting the data? It could be that you are missing a call to hold on to retain the current plots/lines. Please show some of your code.
Hi Geoff, Thanks for your help.. Actually now im using hline which is very similar to refline.. So I have at first a linear scale.. at some point user switch to log scale and I loose my horizontal line
The code I'm using to set up this horizontal line is the following:
function sethline(hObject,~,ax)
handles=guidata(hObject);
cp = get(ax, 'CurrentPoint'); %get the point in the track
x=cp(1,1);%log scale
y=cp(1,2); %y is linear
h=hline(y,'g');
Thanks
susana - so once the horizontal line has been drawn, what is your next set of code that redraws to a log scale? Are you using a hold on to retain current plots on your axes?
susana's answer moved here
Hi Geoff, this is all done using uicontextmenu.. so when user right clicks the axes, he can select the option to add vertical/horizontal lines.. he can then right click again to change scale.. I am never using hold on..How would that fit here?
The code is the following for both actions:
%change scale
function setscalelog(~,~,ax)
scale=get(ax,'XScale');
if isequal(scale,'log')==1
set(ax,'XScale','linear');
else
set(ax,'XScale','log');
end
%add horizontal line
function sethline(hObject,~,ax)
handles=guidata(hObject);
cp = get(ax, 'CurrentPoint');
x=cp(1,1);
y=cp(1,2);
h = hline(y,'g');
linep2=uicontextmenu('Parent',ax.Parent);
ccmenu=uicontextmenu('Parent',ax.Parent);
set(h,'UIcontextmenu',linep2);
set(h,'Tag','qqcoisa');
txt_form=text(x,y,num2cell(round(y)),'tag','txt_form','Parent',ax,'UIContextmenu',ccmenu);
draggable(txt_form);
uimenu(linep2,'Label','Set color','Callback',@ccall);
(...) a bunch of uimenus
guidata(hObject,handles)
Thanks
susana - are the lines actually lost or are they still on the axes but in their original location which, given the change to the scale, creates the illusion that they are lost?
Hi Geoff, Very good point.. I did the assignin function to see what the axes is holding and it seems that the created line is not being store in the axes children.. I tried to set the following when I created the line: set(h,'Parent',axes) but still it wont save anyway.. The odd thing is that I also have a text above the line, which is being hold by the axes, but not the line
I though that maybe it is a bug in hline function. If I use refline the line is being stored in the axes.. I still have a "display" problem of the line.. because now, it exists in the children of the axes, but it is not displayed when i change the scale.. Any ideas?

Sign in to comment.

Answers (0)

Categories

Products

Release

R2017a

Tags

Asked:

on 18 Jul 2018

Commented:

on 8 Aug 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!