Mike on the MATLAB Desktop

March 7th, 2011

Back To Basics: Figure Toolbar

This week I’d like to visit an ubiquitous and yet overlooked topic: the toolbar in the figure window. If you consider yourself an advanced user, feel free to stick around; maybe you’ll see something new.

The figure toolbar came up as the topic of a recent conversation with a colleague. He did not realize that the “Zoom In” button has different behaviors depending on the plot type. For a regular 2D plot, it zooms in by effectively changing the axes limits, but for a 3D plot, it keeps the limits the same and changes the size of the axes on screen. As the discussion progressed, I realized that in all the years he’s been using MATLAB, he hadn’t really given a ton of thought to the tools of the Figure window. He spends the time to get his data imported and set up just right, but usually accepts a plot as-is or decorates it manually using command-line functions. This is fine most of the time, but I find a little mouse-work saves me a ton of time when it comes to data exploration.

Here is the Figure toolbar, stolen straight from our documentation.

The most basic functions: Zoom In, Zoom Out, Pan and Rotate 3D allow you to rearrange and navigate the plot to focus on a particular section of data. These are also useful for exploring a data set to see the data in a particular region, such as where two plots intersect or the location of some minimum or maximum.

The next three buttons deal with the actual data values in the plot. Data cursor provides a tooltip showing the values of the data at point you select with the mouse. Data brushing allows you to to modify or highlight a selection of points and data. I described this feature back when it was introduced. Data link keeps the plot automatically in-sync with variables in the workspace. I also wrote about this back in 2008.

Insert Color Bar and Insert Legend are about adding informational elements to the figure window. I usually see these called via the functions legend and colorbar. But, it’s sometimes nice to use them interactively when you just want to turn one on temporarily.

The final set of buttons toggles Plot Tools, which is an interactive plot editor where you can add/delete whole elements and change properties like color and line type of a particular dataset. It’s worthy of its own post, so I’ll talk about that in future if you’re interested.

All of the previous tools show up in the default figure toolbar, but there are actually a lot more tools you can turn on to edit and explore plots. There is a camera toolbar that gives finer control around rotating and sizing a 3D plot.

There’s also a Plot Edit Toolbar that lets you add text and shapes to a figure. I find this quite useful, as it is much easier to position and size annotations with a mouse than by programmaticaly setting their coordinates.

Both the Plot Edit and Camera toolbars are not shown by default. To get them go to the View menu in the figure window and select one or both.

Are there any plot editing commands you wish were on the toolbar? Do you prefer using the command-line tools like line, text, legend, rotate, etc or do you prefer the interactive tools?

9 Responses to “Back To Basics: Figure Toolbar”

  1. Sven replied on :

    I have a question about using the axis views. It’s more about coding the view rather than using the toolbars, but it’s somewhat related and quite helpful for animation. Consider the following:

    figure
    plot3(1 ,1,1,'go'), hold on, plot3(0,0,0,'r.')
    view(3), axis square
    T1 = view
    

    Now rotate the plot a little bit (or use, say, camorbit):

    camorbit(pi/60,0)
    T1 = view
    

    Now, T1 and T2 are different. Is there any straightforward way I can jump between them? Something like:

    view(T1)
    view(T2)
    

    The only way I’ve been able to do something like the above (which produces an error) is by storing all of
    campos, camtarget, camva separately, and using those commands one at a time.
    Basically, as far as I can tell, the view matrix summarizes all of the camva, campos, camup and camtarget properties in one matrix. Is there a convenient way of setting those 4 properties from such a matrix?

    Thanks,
    Sven.

  2. Jotaf replied on :

    I actually use the data cursor and colorbar buttons a lot, to get more info on the data I’m viewing. Working with images, many times I call imagesc(data) to see some response values for every pixel or inspect some other large matrices.

    The only extra button I’d like to see would be a tool that lets you zoom/pan/rotate freely using the mouse and mousewheel, as the current tools are sometimes too cumbersome to navigate large plots! There are a few File Exchange submissions that do this but it would be nice to have an official version in the toolbars. Or letting users add custom buttons to the figure toolbar in a similar way to adding shortcuts in the main Matlab window.

  3. naor replied on :

    Interactive plot editing used to be one of my favorite things to do in (and out of) Matlab, but since 2008 it became the most frustrating. And here’s why:

    Your Figure toolbar as shown is misleading, the screen capture was taken in an older Matlab version. Since around R2008 the tooltip on the button to open Plot tools reads “Show Plot Tools and dock figure.” And it’s that “and dock the figure” that ruined Interactive plotting for me. A long discussion of why is better suited for the forums, but the short version is: docking inevitably involves resizing the figure. And that inevitably ruins my carefully placed items (no, pin to axes doesn’t always help) and for busy plots on a weak machine takes many seconds to complete. Docking or Undocking the plot tools themselves from the Figures container doesn’t help, each option has its own critical drawbacks.

    So, to answer two of your questions above, yes a post on the Plot Tools would be interesting. And the plot command I would like to see added to the tool bar is “Show Plot Tools (but don’t dock the figure)”
    thanks,
    -naor

  4. Sven replied on :

    Oh, yes, I *absolutely* agree with Jotaf.
    A stable and intuitive way to interactively pan-zoom-rotate figure axes would be immeasurably valuable. Note that even the best file-exchange tools are primarily aimed at 2D data visualisation, and I think that *huge* value would be added in good 3d visualisation manipulation.

    I’m from a finite element analysis background, and the hands-down absolute best 3D interface I’ve used is Altair’s Hypermesh. It’s been a while, but from memory:

    Mouse wheel = zoom
    Ctrl + right mouse drag = pan
    Ctrl + left mouse drag = rotate
    Ctrl + left mouse click =

    Anything like the above (and in my mind, the last item is one of the most useful) would be a huge step forward.

  5. Sven replied on :

    Oh, yes, I *absolutely* agree with Jotaf.
    A stable and intuitive way to interactively pan-zoom-rotate figure axes would be immeasurably valuable. Note that even the best file-exchange tools are primarily aimed at 2D data visualisation, and I think that *huge* value would be added in good 3d visualisation manipulation.

    I’m from a finite element analysis background, and the hands-down absolute best 3D interface I’ve used is Altair’s Hypermesh. It’s been a while, but from memory:

    Mouse wheel = zoom
    Ctrl + right mouse drag = pan
    Ctrl + left mouse drag = rotate
    Ctrl + left mouse click = set new center of rotation

    Anything like the above (and in my mind, the last item is one of the most useful) would be a huge step forward.
    (sorry for repost… html problem)

  6. Mike replied on :

    @Sven,

    There doesn’t seem to be direct way to do it, but what you want is to do is use hgtransform, to set the view matrix.

    @Sevn and noar and Jotaf,

    Thanks for the feedback, I have sent it on to our graphics team. We have some new projects in the pipeline that should make some of your work easier.

  7. Mike replied on :

    @Sven,

    I got an updated workaround that is much simpler than using the hgtransform:

    Instead use the two-outut version of view

    [az,el] = view
    

    which can then be used as the input:

    view(az, el);
    
  8. Sven replied on :

    Thanks Mike.

    And a final note about an interface. I had previously asked a similar question which got some helpful replies from Yair and Walter:
    http://www.mathworks.com/matlabcentral/newsreader/view_thread/283529

    I’d be more than happy to elaborate on how in interface would be most used and useful if more info is needed.

    Thanks,
    Sven.

  9. KE replied on :

    I wish the Figure Toolbar had more options under Edit > Copy Figure. I use this all the time (say 20x daily) to copy figures into Word, Outlook and PowerPoint 2007. But the copied figure looks pixelated and of poor quality. The limited choices under Copy Options don’t improve things. Is there a way to increase the default pixel resolution or other options that could increase the quality? Can you suggest a workaround that does not include saving the figure to a file, since I want to stick with Edit > Copy Figure?

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks
Mike works on the MATLAB Desktop team.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.