Ordering Scatter Plot Layers
古いコメントを表示
Hi! I’m trying to do a scatter plot with a text annotation on the background. My question is how I can make the text appear bellow the bubbles, as opposed to on top of them? Here’s my code. (I’ve used random data for simplicity here)
vy = randi(80,[100,1]); % random data
vx = randi(50000, [100,1]); % random data
c = rand([length(vy),3]); % random colors RGB
figure('Position',[100 100 800 600], 'Color', 'w')
axes('Position',[0.1 0.15 0.8 0.8],'XScale','log', 'Color', 'w')
axis([200 100000 20 85]); % [xMin xMax yMin yMax]
ha = gca; % get current axes handle
set(ha, 'FontSize', 14, 'Color', 'w',...
'XColor', [0.5 0.5 0.5], 'YColor', [0.5 0.5 0.5])
set(ha, 'XTick', xTick)
set(ha,'XTickLabel',{'400';'1,000';'2,000';'4,000';
'10,000';'20,000';'40,000'})
grid on
set(ha, 'box', 'on')
ht = text('Units', 'normalized', 'Position',[0.5,
0.5],'String','Trial', ...
'FontUnits', 'normalized' , 'FontSize', 0.35 ,...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle',...
'Color',[0.6 0.8 0.8]);
hold on
hp = scatter(vx(:),vy(:),50,c,'filled'); % scatter plot
I’ve tried using uistack, but it doesn’t work :(. This is what I’ve tried:
uistack(ht,'bottom')
uistack(hp,'top' )
Any help will be greatly appreciated!! Thank you very much!!
採用された回答
その他の回答 (1 件)
Walter Roberson
2012 年 1 月 24 日
0 投票
The easiest way to get an object to appear below something else is to give the first object a more negative z coordinate than the second object.
If you happened to be using OpenGL (which would be necessary if you were using transparency or certain kinds of lighting) then this would be the approach you would have to take, as OpenGL does not obey stacking order when two objects fall in the same plane.
1 件のコメント
the cyclist
2012 年 1 月 24 日
Out of curiosity, are you able to do what you propose for Susana's specific example? I tried the following, none of which worked for me:
- Change the z-coordinate of the text's position property
- Change the ZData property of the dots
- Change the order of the Children of the axes (which neither of us mentioned, but typically works)
- uistack() command
My Renderer for this figure is zbuffer. When I change the Renderer, using
set(gcf,'Renderer','OpenGL')
the plot remains the same except the dots actually change positions! This totally baffles me. My guess is that it is a bug related to the normalized units, as mentioned in one of Susana's comments to my answer.
カテゴリ
ヘルプ センター および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!