1 Cursor over different subplots with different x-axis

44 ビュー (過去 30 日間)
Minialoe
Minialoe 2018 年 6 月 15 日
コメント済み: Minialoe 2018 年 6 月 21 日
Hello everybody :)
I would like to know (and I hope so) if it is possible to put a cursor (or something similar) on every subplot of my figure:
- although the x-axis is not the same for each subplot
- with all the different cursors linked together
What I mean: if I move the cursor on the 1st subplot, the cursor on the 2nd and 3rd subplot will also move in the same manner. If the cursor is on the 670th value on the 1st subplot, the cursor is also on the 670th value on the other subplots (info: the length of the plotted vector of every subplot is the same).
How to do it?
Thank for your help, if you have some tips don't hesitate !

回答 (1 件)

Minialoe
Minialoe 2018 年 6 月 18 日
Nobody for help? :)
  2 件のコメント
Minialoe
Minialoe 2018 年 6 月 18 日
Here a first draft to solve my problem... I can display the index I (what I want) on the plot, but I also want to retrieve it !!! How to do it?
function Indexplot(varargin)
fig =figure;
plot(varargin{:})
set(gca,'ylim',[-50 1600]);
dcm=datacursormode(fig);
datacursormode on
set (dcm, 'updatefcn', @myfunction) ;
function [output_txt, info] = myfunction(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position');
I = get(event_obj, 'DataIndex');
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)],...
['I: ', num2str(I)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
Minialoe
Minialoe 2018 年 6 月 21 日
Here with this function I can display several synchronized cursors on my plot.
Remark: fig = figure() hplot(1) = subplot(2,1,1) etc...
function dcm=Indexplot(fig,hplot)
% fonction qui permet d'afficher un curseur sur l'ensemble des subplot du
% graphique
% fig = figure(20) par ex
% hplot correspond à {hplot(1), hplot(2), hplot(3)} avec hplot(1)=subplot(2,1,1), hplot(2)=subplot(2,1,2) par ex
dcm=datacursormode(fig);
set(dcm,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on', 'updatefcn', @myfunction)
disp('Click line to display a data tip, then press Return.')
% Wait while the user does this.
pause
c_info = getCursorInfo(dcm);
index=c_info.DataIndex;
for i=1:length(hplot) % pour chaque subplot, on affiche le cursor (au même endroit)
hPlot=hplot(i);
% create a datatip
hDatatip(i) = dcm.createDatatip(hPlot);
% get the axis data
X = get(hPlot, 'XData');
Y = get(hPlot, 'YData');
Z = get(hPlot, 'ZData');
% determine the datatip position
if isvector(X) && isempty(Z) % for 2D lines
pos = [X(index) Y(index) 0];
elseif isvector(X) % for 3D lines
pos = [X(index) Y(index) Z(index)];
else % for 3D surfaces
pos = [X(index(1), index(2)),...
Y(index(1), index(2)),...
Z(index(1), index(2))];
end
set(hDatatip(i), 'Position', pos)
updateDataCursors(dcm)
end
function output_txt = myfunction(obj,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
% pos = get(event_obj,'Position');
% I = get(event_obj, 'DataIndex');
% output_txt = {['X: ',num2str(pos(1),4)],...
% ['Y: ',num2str(pos(2),4)],...
% ['I: ', num2str(I)]};
%
% % If there is a Z-coordinate in the position, display it as well
% if length(pos) > 2
% output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
%
%
%
% end
output_txt =[];
Here the way to use Indexplot. While the figure is open, Matlab has to execute the instructions.
while ishandle(fig) %quitte la boucle si on ferme la figure
if ~ishandle(fig); continue; end %check again if the window is open
dcm=Indexplot(fig, hplot);
if ~ishandle(fig); continue; end
disp('Line ok, press Return to delete cursor(s)')
if ~ishandle(fig); continue; end
pause
if ~ishandle(fig); continue; end
dcm.removeAllDataCursors;
if ~ishandle(fig); continue; end
disp('Cursor(s) deleted, press Return to put a new cursor')
if ~ishandle(fig); continue; end
pause
end
But this is problematic because i need to push a button everytime I want to change the cursors of place ... I can not slide them together....
Here is a way to synchronized 2 cursors on 2 plots.
https://stackoverflow.com/questions/43721024/is-it-possible-to-synchronize-data-cursors-across-multiple-figures-in-matlab
I am able to change little things to synchronize 2 cursors on 2 subplots (one on each).
But now: how to do it with 10 cursors on 2 different subplots ?
(2 curve on the 1st subplot, 2 cursors 6 six curve on the 2nd subplot, 6 cursors so in total 8 cursors... If I move 1 cursor, the 7 others have to follow)

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

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by