Apparent bug in getting the current axis (gca) with ginput on a Mac?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a script in which I click on different subplots to interactively edit data. Let's say the figures are like this:
figure(1)
subplot(2,2,1)
plot(0:1,0:1)
subplot(2,2,2)
plot(0:2,0:2)
subplot(2,2,3)
plot(0:3,0:3)
subplot(2,2,4)
plot(0:4,0:4)
Now, when the figure is open and I click with the mouse on one of the subplots and then do gca, it will return the subplot axis which I clicked on as the current axis. For example, if I move my cursor to the first subplot and click on it and then do gca, I get the following output:
ans =
Axes with properties:
XLim: [0 1]
YLim: [0 1]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0.1300 0.5838 0.3347 0.3412]
Units: 'normalized'
Show all properties
However, when I run ginput(1) and then click on one of the subplots and do gca, it will always return the last subplot which I plotted (in this case the fourth subplot) instead of the subplot axis which I clicked on.
The reason I am wondering if this is a MacOS related bug is because this was not an issue in Windows. I recently switched from using a Windows to a Mac (running MacOS BigSur 11.6.4 and MATLAB 2021a). Unfortunately, I no longer own a Windows machine to test my hypothesis. However, in Windows (as I recall), when you run ginput(1) , click on a subplot, and then call gca, it outputs the subplot axis that you clicked on. If you click on an axis, you should activate that axis as the current axis. This doesn't appear to be the case on Mac when using ginput.
Anyone confirm or deny this or is something else going on?
Thanks
댓글 수: 2
AndresVar
2022년 3월 5일
편집: AndresVar
2022년 3월 5일
Hi, I am on windows 11 (Matlab '9.11.0.1873467 (R2021b) Update 3'). I can confirm that ginput activates the axis that was clicked. I don't know what the issue is in mac.
The code below adds the new plot on the axis that was activated by ginput
figure(1);
subplot(2,2,1);
plot(0:1);
subplot(2,2,2);
plot(0:1);
subplot(2,2,3);
plot(0:1);
subplot(2,2,4);
plot(0:1);
ginput(1)
hold on;
plot(0:1,'x--') % it adds the new line on the subplot that was clicked
Edit: tested also on R2020a Update5 on Windows 10, works as you originally expected.
AndresVar
2022년 3월 7일
편집: AndresVar
2022년 3월 7일
Edit: maybe also try switching from subplot to tiledlayout: Create tiled chart layout - MATLAB tiledlayout (mathworks.com)
@Darcy you can try ginputc from file exchange: Custom GINPUT - File Exchange - MATLAB Central (mathworks.com)
that function has the following option
[X,Y,BUTTON,AX] = ginputc(...) returns a fourth result, AX, that contains a vector of axes handles for the data points collected.
MAYBE it works.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!