Problem using ginput to reposition axes

9 ビュー (過去 30 日間)
Marc Jakobi
Marc Jakobi 2016 年 1 月 30 日
コメント済み: Marc Jakobi 2016 年 2 月 1 日
Hi. I am working on a function that lets you interactively reposition an axes (for example a subplot) using the mouse input. This is my attempt (simplified a bit) for one axes
%create invisible axes covering the figure
drawax = axes('Position',[0, 0, 1, 1],'Visible','off');
[left, bottom] = ginput(1); %get position
[top, right] = ginput(1);
newpos = [left, bottom, max(0,right-left), max(0,top-bottom)];
ax1.Position = newpos; %ax1 is the subplot that is to be repositioned.
[left, bottom] return the correct positions, but [top, right] seem to be returning coordinates from ax1. Is there a way I can force ginput to select points that correspond with the normalized position of drawax?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 1 月 31 日
Marc - please clarify what you mean by reposition an axes. Are you just trying to zoom in on a particular area and so are trying to reset the x and y axis limits?
Marc Jakobi
Marc Jakobi 2016 年 2 月 1 日
In Matlab figures, there's always a white border around the axes when you save it. Cropping bitmap images to remove the border is quite simple, but it gets a lot more complicated when you want to export the figure to the emf format. Just using "export setup..." and "expand axes to fill figure" often results in the plots getting distorted (especially when you have multiple axes on top of each other per subplot - as in plotyy or when you copy an axes in order to create a second legend). My function tries to do this automatically taking into account various factors (amount of ylabels, colorbars, and axes per subplot, amount of subplots, etc.). I managed to get it to crop pretty much all figures for emf export that I have tested it on, but just in case it encounters a figure that it crops incorrectly, I am trying to implement a manual mode, in which it does the automatic cropping, highlights the subplots one by one and lets the user manually select the bottom left and top right corner of each subplot in order to correct the "crop". For this, I would like to implement an option using ginput() and one in which it displays the new position and queries a corrected position from the user via input (each correction occuring in a loop until the user is satisfied with the crop). I believe the ginput() method would make it a little easier for users who have little experience with the normalized position [left, bottom, width, height] vectors of axes. However, I can't seem to get it to return normalized coordinates relative to the position of the axes, which is what I need for the manual axes expansion.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2016 年 1 月 31 日
Perhaps call xlim() and ylim() to find out your "field of view" in your graph, then call ginput(1) to find a desired center of the graph, then, based on that, compute new limits for the displayed x and y ranges, then call xlim() and ylim() to assign them to the graph.
  5 件のコメント
Image Analyst
Image Analyst 2016 年 2 月 1 日
You can just accept this one. Thanks! Glad it worked out for you.
Marc Jakobi
Marc Jakobi 2016 年 2 月 1 日
Thanks again for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by