Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Saving graphs with datatips

Subject: Saving graphs with datatips

From: Andy

Date: 13 Jan, 2011 19:06:05

Message: 1 of 7

I'm currently using the following code to save a graph:

g=figure;
p=copyobj(myAxes,g);
set(p,'Units','normalized','OuterPosition',[0 0 1 1]);
print(g,'-dbmp','tempfile.bmp');
close(g);

This works pretty well, except that if the graph in myAxes has a datatip, this datatip is not saved in the bitmap. Does anybody know a way to copyobj the datatip along with the graph?

Subject: Saving graphs with datatips

From: I am too much me

Date: 13 Jan, 2011 19:28:14

Message: 2 of 7

On 11-01-13 01:06 PM, Andy wrote:
> I'm currently using the following code to save a graph:
>
> g=figure;
> p=copyobj(myAxes,g);
> set(p,'Units','normalized','OuterPosition',[0 0 1 1]);
> print(g,'-dbmp','tempfile.bmp');
> close(g);
>
> This works pretty well, except that if the graph in myAxes has a datatip, this
> datatip is not saved in the bitmap. Does anybody know a way to copyobj the
> datatip along with the graph?

I believe the datatip may be created within a different axes.

Subject: Saving graphs with datatips

From: Andy

Date: 13 Jan, 2011 21:03:04

Message: 3 of 7

I am too much me <roberson@hushmail.com> wrote in message <ignjr0$mpu$1@nrc-news.nrc.ca>...
> On 11-01-13 01:06 PM, Andy wrote:
> > I'm currently using the following code to save a graph:
> >
> > g=figure;
> > p=copyobj(myAxes,g);
> > set(p,'Units','normalized','OuterPosition',[0 0 1 1]);
> > print(g,'-dbmp','tempfile.bmp');
> > close(g);
> >
> > This works pretty well, except that if the graph in myAxes has a datatip, this
> > datatip is not saved in the bitmap. Does anybody know a way to copyobj the
> > datatip along with the graph?
>
> I believe the datatip may be created within a different axes.

Some poking around with Yair's findjobj (http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects) suggests that this is not the case.

But I'm guessing everything about a data tip is nearly invisible from a programmatic point of view. For example, run the following:

x=linspace(0,10,100);
y=sin(x);
f=figure;
a=axes('parent',f);
p=plot(a,x,y);

% add a few data tips
findjobj(f)

Now if you right click on one of the datatips and "Export handle to findjobj_hdls", you'll have the handle for the data cursor in your workspace. I then renamed mine to dc. Then you can see all of the properties of the data cursor:


>> get(dc)
            Annotation: [1x1 hg.Annotation]
           DisplayName: ''
           HitTestArea: 'off'
          BeingDeleted: 'off'
         ButtonDownFcn: []
              Children: [0x1 double]
              Clipping: 'on'
             CreateFcn: []
             DeleteFcn: []
            BusyAction: 'queue'
      HandleVisibility: 'off'
               HitTest: 'on'
         Interruptible: 'on'
                Parent: 1109.00012207031
    SelectionHighlight: 'on'
                   Tag: ''
                  Type: 'hggroup'
              UserData: []
              Selected: 'off'
             FontAngle: 'normal'
              FontName: 'Helvetica'
              FontSize: 8
             FontUnits: 'points'
            FontWeight: 'normal'
             EdgeColor: [0.8 0.8 0.8]
       BackgroundColor: [1 1 0.933333333333333]
             TextColor: [0 0 0]
                Marker: 'square'
            MarkerSize: 10
       MarkerEdgeColor: [1 1 0.862745098039216]
       MarkerFaceColor: [0 0 0]
       MarkerEraseMode: 'normal'
             Draggable: 'on'
                String: [1x19 char]
               Visible: 'on'
             StringFcn: []
             UpdateFcn: []
         UIContextMenu: [1x1 uicontextmenu]
                  Host: [1x1 graph2d.lineseries]
           Interpolate: 'off'

Draggable seemed like a pretty unique property name. I've never seen anything else with this property, and I'm sure this would uniquely identify data cursors in my program. But:

>> findobj('-property','Draggable')

ans =
   Empty matrix: 0-by-1

I've also tried a lot of other properties, and none of them were found by findobj. So I don't know how I can programmatically find the data cursors. The findjobj results make it look like they're children of the axes object, but get(a,'children') will only return the handle for the lineseries object.

Any other ideas?

Subject: Saving graphs with datatips

From: Andy

Date: 13 Jan, 2011 21:25:22

Message: 4 of 7

Okay, I think I've gotten closer:

    %%
    x=linspace(0,10,100);
    y=sin(x);
    f=figure;
    dcm=datacursormode(f);
    a=axes('parent',f);
    p=plot(a,x,y);

    %%
    % add some data cursors before running this cell
    get(dcm,'DataCursors')

So now that I can get the handles to the data cursors, I need to be able to copy them. Unfortunately, the data cursors are of class graphics.datatip, which does not apparently count as a graphics object so it cannot be copied via copyobj.

For the record, if after running the above script you run:

>> print(f,'-dbmp','test.bmp');

you will have a bitmap image of the graph including the data cursor. In my application, the axes is in a subpanel inside the figure, and the print command requires the handle graphics object you pass to it to be a figure. I have been just copying the graph to a new figure, using the print command, and deleting the figure.

If anybody can help me copy the data cursors over, or if anybody has a better way to save my graph without needing to make a copy, please let me know.

Subject: Saving graphs with datatips

From: By learning you will teach; by teaching you will learn.

Date: 13 Jan, 2011 21:37:48

Message: 5 of 7

On 11-01-13 03:03 PM, Andy wrote:
> I am too much me <roberson@hushmail.com> wrote in message

>> I believe the datatip may be created within a different axes.

> Some poking around with Yair's findjobj
> (http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects)
> suggests that this is not the case.

Checking further, the datatip is a hggroup object with HandleVisibility off
that is a child of the axes that the datatip is relative to.

Subject: Saving graphs with datatips

From: Yair Altman

Date: 14 Jan, 2011 11:33:05

Message: 6 of 7

"By learning you will teach; by teaching you will learn." <roberson@hushmail.com> wrote in message <ignrdu$qkt$1@nrc-news.nrc.ca>...
> On 11-01-13 03:03 PM, Andy wrote:
> > I am too much me <roberson@hushmail.com> wrote in message
>
> >> I believe the datatip may be created within a different axes.
>
> > Some poking around with Yair's findjobj
> > (http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects)
> > suggests that this is not the case.
>
> Checking further, the datatip is a hggroup object with HandleVisibility off
> that is a child of the axes that the datatip is relative to.

Firstly, since the datatips have HandleVisibility off, you need to use findall rather than findobj:

>> findobj(gca,'-property','Draggable')
ans =
   Empty matrix: 0-by-1
>> findall(gca,'-property','Draggable')
ans =
            199.0009765625
>> findall(gca,'-isa','graphics.datatip') <= this is better I would think...
ans =
            199.0009765625

Secondly, you can get the handles directly, by accessing the axes's hidden children:

>> allchild(gca)
ans =
            207.0009765625
            206.0009765625
            205.0009765625
            204.0009765625
            199.0009765625
           184.00146484375

Thirdly, for screen-capturing the axes as-is, you don't need any of the above (interesting as they may be) - you just need a good screen-capture utility. Here's one such utility that you can run in Matlab on any chosen figure/axes handle:
http://www.mathworks.com/matlabcentral/fileexchange/24323-screencapture

Yair Altman
http://UndocumentedMatlab.com

Subject: Saving graphs with datatips

From: Andy

Date: 14 Jan, 2011 14:25:05

Message: 7 of 7

Thanks, Yair! That screen capture utility is great. This completely solves my problem.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us