Thread Subject: Changing the order of layers of a Scatter Plot

Subject: Changing the order of layers of a Scatter Plot

From: Eric Hoffman

Date: 23 Jan, 2012 01:47:07

Message: 1 of 3

Hi everyone,

I'm trying to plot the following (please run it to visualize it):


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')
xlabel('Income per person (GDP/capita)', 'fontsize',14,'color','k')
ylabel('Life Expectancy (years)', 'fontsize', 14, 'color', 'k')
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



My question is: How can I make the text string appear bellow the
scatter points? I've tried using uistack, as previously shown in
another thread on this forum, 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!!

Subject: Changing the order of layers of a Scatter Plot

From: matt dash

Date: 24 Jan, 2012 17:49:10

Message: 2 of 3

Eric Hoffman <ndo.hoffman@gmail.com> wrote in message <442a0d5b-3ac6-4679-824c-ca117fbae3f8@a8g2000pbi.googlegroups.com>...
> Hi everyone,
>
> I'm trying to plot the following (please run it to visualize it):
>
>
> 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')
> xlabel('Income per person (GDP/capita)', 'fontsize',14,'color','k')
> ylabel('Life Expectancy (years)', 'fontsize', 14, 'color', 'k')
> 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
>
>
>
> My question is: How can I make the text string appear bellow the
> scatter points? I've tried using uistack, as previously shown in
> another thread on this forum, 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!!

I'm not sure why, but the problem seems to be related to using normalized units on the text object. Change it to regular "data" units instead and it'll work.

Something like: ht = text('Position',[10000,50],'String','Trial', ...
    'FontUnits', 'normalized' , 'FontSize', 0.35 , ...
    'HorizontalAlignment', 'center', ...
    'VerticalAlignment', 'middle',...
    'Color',[0.6 0.8 0.8]);

Subject: Changing the order of layers of a Scatter Plot

From: Eric Hoffman

Date: 24 Jan, 2012 18:31:04

Message: 3 of 3

On Jan 24, 9:49 am, "matt dash" <n...@mail.com> wrote:
> Eric Hoffman <ndo.hoff...@gmail.com> wrote in message <442a0d5b-3ac6-4679-824c-ca117fbae...@a8g2000pbi.googlegroups.com>...
> > Hi everyone,
>
> > I'm trying to plot the following (please run it to visualize it):
>
> > 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')
> > xlabel('Income per person (GDP/capita)', 'fontsize',14,'color','k')
> > ylabel('Life Expectancy (years)', 'fontsize', 14, 'color', 'k')
> > 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
>
> > My question is:  How can I make the text string appear bellow the
> > scatter points?  I've tried using uistack, as previously shown in
> > another thread on this forum, 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!!
>
> I'm not sure why, but the problem seems to be related to using normalized units on the text object. Change it to regular "data" units instead and it'll work.
>
> Something like: ht = text('Position',[10000,50],'String','Trial', ...
>     'FontUnits', 'normalized' , 'FontSize', 0.35 , ...
>     'HorizontalAlignment', 'center', ...
>     'VerticalAlignment', 'middle',...
>     'Color',[0.6 0.8 0.8]);

Hi! Thanks so much for your reply!!!
You are right! The problem seems to be with the normalized units.
I really appreciate your help :)

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com