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?
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。