No data tip interaction when adding a second axis

Hello,
In the following example if I comment ax2 I have my new data tips but as I added the second axes it is lost. Does someone have any idea of the reason?
f = figure;
hold on;
box on;
x = 1:100;
y = sin(x);
sc = scatter(x,y);
row = dataTipTextRow('Id',x);
dtp = sc.DataTipTemplate;
dtp.DataTipRows(end+1) = row;
ax1 = gca;
set(ax1, 'FontName', 'Times', 'FontSize', 12, 'LineWidth', 1)
set(ax1,'InnerPosition',get(ax1,'InnerPosition')-[0 0 0 0.05])
ax1_pos = ax1.Position;
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');

 Respuesta aceptada

Adam Danz
Adam Danz el 27 de Mzo. de 2020
Editada: Adam Danz el 27 de Mzo. de 2020
ax2 is blocking ax1. The datatip on ax2 works fine but there are no data in ax2 so you're not seeing any datatips.
Solution: Put ax2 on the bottom:
uistack(ax2, 'bottom')
If you plan on plotting anything on ax2, you'll need to make ax1 color = none so you can see ax2 (and you won't need to set ax2 color to none).

2 comentarios

Denis A.
Denis A. el 27 de Mzo. de 2020
Thank you Adam it works. I try to do that with the set function but it didn't work... You saved my week-end ;-)
Adam Danz
Adam Danz el 27 de Mzo. de 2020
Glad I could help. Enjoy the weekend!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Mzo. de 2020

Comentada:

el 27 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by