Chapter 5. User Defined Graphics

Rslice does not have a GUI facility for adding extra graphics (e.g. coastlines) to its display, but it can be done. All that is needed is to arm yourself with a little knowledge of matlab handle graphics, and you'll be set.

In this example, we add a coastline for the eastern seaboard to an rslice display for the NENA grid. The only important change from the usual rslice startup is that we don't throw away the return argument for rslice.

>> ncfile = '/home/jevans/roms/nena/run4/avg/'; 
>> rh = rslice ( 'file', ncfile, 'variable', 'temp' );

The variable rh is a graphics handle for the rslice display. It is actually a handle for the figure itself, but the important thing is that thru this handle, we can access all the child handles, including the axis of the rslice display. So let's get access to those handles.

>> rslice_handles = guihandles ( rh );

That axis of the rslice display that we want is a field of rslice_handles and is designated as horizontal_slice_axis.

Now let's add a coastline. You can see from the command line that it's not possible to add graphics to the rslice display from the command line, a new figure window always pops up to take the graphics. But with a little slight of hand, we can easily transfer the graphics between figure windows.

>> coastline_handle = plot ( coast_lon, coast_lat );    % pops up in another figure window
>> set ( coastline_handle, 'Parent', rslice_handles.horizontal_slice_axis );

At this point, rslice has no knowledge of the coastline, and any subsequent redraws will erase it. The way to inform rslice about the coastline is to make use of the Tag property.

>> set ( coastline_handle, 'Tag', 'rslice user defined graphics' );

After this, rslice will take note and save those graphics handles, reloading them after a redraw. The handles are actually saved in a file called user_defined_rslice_graphics.fig.

This method can be used with more than just coastlines. One could add text for cities, for example. All that need be done is to properly transfer tag the handle to the rslice display and to tag it.