Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to display values on a plot

Subject: How to display values on a plot

From: Vicky

Date: 28 Apr, 2008 23:24:02

Message: 1 of 15

hi,

is there a way to display a value instead of circles for
points on an x-y plot?

as an simple example, suppose my data points are numbered:

indic x y
1 1.2 0.66
2 2.7 0.58
3 3.6 0.44
...

I want each the value in indic to show up in the plot
instead of default circles so that i know where each pair
of values are on the plot directly.

any way to do this?

Subject: How to display values on a plot

From: Steven Lord

Date: 29 Apr, 2008 02:24:41

Message: 2 of 15


"Vicky " <happygalpeanut@yahoo.com> wrote in message
news:fv5mai$p72$1@fred.mathworks.com...
> hi,
>
> is there a way to display a value instead of circles for
> points on an x-y plot?
>
> as an simple example, suppose my data points are numbered:
>
> indic x y
> 1 1.2 0.66
> 2 2.7 0.58
> 3 3.6 0.44
> ...
>
> I want each the value in indic to show up in the plot
> instead of default circles so that i know where each pair
> of values are on the plot directly.
>
> any way to do this?

HELP TEXT.

--
Steve Lord
slord@mathworks.com

Subject: How to display values on a plot

From: Anh Huy Phan

Date: 29 Apr, 2008 02:50:03

Message: 3 of 15

"Vicky " <happygalpeanut@yahoo.com> wrote in message
<fv5mai$p72$1@fred.mathworks.com>...
> hi,
>
> is there a way to display a value instead of circles for
> points on an x-y plot?
>
> as an simple example, suppose my data points are numbered:
>
> indic x y
> 1 1.2 0.66
> 2 2.7 0.58
> 3 3.6 0.44
> ...
>
> I want each the value in indic to show up in the plot
> instead of default circles so that i know where each pair
> of values are on the plot directly.
>
> any way to do this?


Did you try 'text' funtion?

text(x,y,num2str(indic),'HorizontalAlignment','center')

then set scaling for the x- and y-axes by axis function

axis([min(x) max(x) min(y) max(y)]

Or combine plot and text functions

plot(x,y,num2str(indic),'.')
text(x,y,num2str(indic),'HorizontalAlignment','center')

HTH,

Anh Huy Phan,

RIKEN - BSI

Subject: How to display values on a plot

From: Anh Huy Phan

Date: 29 Apr, 2008 02:50:03

Message: 4 of 15

"Vicky " <happygalpeanut@yahoo.com> wrote in message
<fv5mai$p72$1@fred.mathworks.com>...
> hi,
>
> is there a way to display a value instead of circles for
> points on an x-y plot?
>
> as an simple example, suppose my data points are numbered:
>
> indic x y
> 1 1.2 0.66
> 2 2.7 0.58
> 3 3.6 0.44
> ...
>
> I want each the value in indic to show up in the plot
> instead of default circles so that i know where each pair
> of values are on the plot directly.
>
> any way to do this?


Did you try 'text' funtion?

text(x,y,num2str(indic),'HorizontalAlignment','center')

then set scaling for the x- and y-axes by axis function

axis([min(x) max(x) min(y) max(y)]

Or combine plot and text functions

plot(x,y,num2str(indic),'.')
text(x,y,num2str(indic),'HorizontalAlignment','center')

HTH,

Anh Huy Phan,

RIKEN - BSI

Subject: How to display values on a plot

From: Trish R

Date: 28 Apr, 2009 20:06:01

Message: 5 of 15

I had the same problem and I found the 'text' function very useful.
An example from my code is as follows :

 text( x(i), y(i), [num2str(marker)] );

where the marker is the label for that point in the plot.

Subject: How to display values on a plot

From: Trish R

Date: 28 Apr, 2009 20:07:01

Message: 6 of 15

I had the same problem and I found the 'text' function very useful.
An example from my code is as follows :

 text( x(i), y(i), [num2str(marker)] );

where the marker is the label for that point in the plot.

Subject: How to display values on a plot

From: Ignazio G

Date: 3 Aug, 2010 09:30:07

Message: 7 of 15

Hello,
I am successfully showing the values on a graph for one curve,
the thing is I have 2 curves and the plot is a y-y plot:
for the left y axis curve the values are depicted correctly,
for the right axis curve no - the values are depicted according to the left axis ! !

how do i bypass this?
thank you in advance

Subject: How to display values on a plot

From: us

Date: 3 Aug, 2010 09:36:04

Message: 8 of 15

On Aug 3, 11:30 am, "Ignazio G" <igiunt...@yahoo.it> wrote:
> Hello,
> I am successfully showing the values on a graph for one curve,
> the thing is I have 2 curves and the plot is a y-y plot:
> for the left y axis curve the values are depicted correctly,
> for the right axis curve no - the values are depicted according to the left axis ! !
>
> how do i bypass this?
> thank you in advance

show CSSM the relevant part of your code...

us

Subject: How to display values on a plot

From: Ignazio G

Date: 3 Aug, 2010 11:43:04

Message: 9 of 15

> show CSSM the relevant part of your code...
>
> us

    [AX,H1,H2] = plotyy(A(:,1),A(:,2),A(:,1),A(:,3),'plot');
    text(A(:,1),A(:,2)+2,num2str(A(:,2)),'HorizontalAlignment','center')
    text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center')
    set(get(AX(1),'Ylabel'),'String','number of years');
    set(get(AX(2),'Ylabel'),'String','number of stations');
    xlabel('f');

A is this matrix:
A =

    0.2000 9.0000 26.0000
    0.2500 11.0000 24.0000
    0.3000 14.0000 22.0000
    0.3500 18.0000 20.0000
    0.4000 21.0000 19.0000
    0.4500 24.0000 18.0000
    0.5000 28.0000 16.0000
    0.5500 33.0000 14.0000
    0.6000 36.0000 12.0000
    0.6500 40.0000 10.0000
    0.7000 44.0000 8.0000
    0.7500 47.0000 6.0000
    0.8000 51.0000 4.0000
    0.8500 51.0000 4.0000
    0.9000 75.0000 1.0000

Subject: How to display values on a plot

From: us

Date: 3 Aug, 2010 11:56:04

Message: 10 of 15

"Ignazio G" <igiuntoli@yahoo.it> wrote in message <i38vc8$e24$1@fred.mathworks.com>...
> > show CSSM the relevant part of your code...
> >
> > us
>
> [AX,H1,H2] = plotyy(A(:,1),A(:,2),A(:,1),A(:,3),'plot');
> text(A(:,1),A(:,2)+2,num2str(A(:,2)),'HorizontalAlignment','center')
> text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center')

one of the solutions

% your code...
     text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center');
% new code...
% - set the parent axis
     text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center','parent',AX(2));

us

Subject: How to display values on a plot

From: Ignazio G

Date: 3 Aug, 2010 13:05:32

Message: 11 of 15

thank you! the 'parent' worked.

>one of the solutions
>
> % your code...
> text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center');
> % new code...
> % - set the parent axis
> text(A(:,1),A(:,3),num2str(A(:,3)),'HorizontalAlignment','center','parent',AX(2));
>
> us

Subject: How to display values on a plot

From: Dimitra

Date: 12 Apr, 2013 10:09:08

Message: 12 of 15

Hello,

I am new to Matlab and I have a similar problem. I have a 300X3 matrix D(X,Y,indicator) that I want to plot in 2D. In the plot, for each set (X,Y), I would like to have the value of the Indicator (3rd column of D) plotted next to the point.

I am using scatter to plot the X,Y, because I want to give different colors to the points, according to the value of their indicator.
scatter(D(:,1),D(:,2),15,Color(:,1:3))

Color(:,1:3) is the matrix where I have defined the colors I want.

How can I plot the value of each point at the plot (a number with a decimal part) on my figure?
I tried the following but without success:

for j=1:300
    text(D(j,1),D(j,2),[' ', D(j,3)],'FontSize',7);
end


Thank you in advance.

Subject: How to display values on a plot

From: TideMan

Date: 12 Apr, 2013 10:30:04

Message: 13 of 15

On Friday, April 12, 2013 10:09:08 PM UTC+12, Dimitra wrote:
> Hello,
>
>
>
> I am new to Matlab and I have a similar problem. I have a 300X3 matrix D(X,Y,indicator) that I want to plot in 2D. In the plot, for each set (X,Y), I would like to have the value of the Indicator (3rd column of D) plotted next to the point.
>
>
>
> I am using scatter to plot the X,Y, because I want to give different colors to the points, according to the value of their indicator.
>
> scatter(D(:,1),D(:,2),15,Color(:,1:3))
>
>
>
> Color(:,1:3) is the matrix where I have defined the colors I want.
>
>
>
> How can I plot the value of each point at the plot (a number with a decimal part) on my figure?
>
> I tried the following but without success:
>
>
>
> for j=1:300
>
> text(D(j,1),D(j,2),[' ', D(j,3)],'FontSize',7);
>
> end
>
>
>
>
>
> Thank you in advance.

Replace:
[' ', D(j,3)]
with
num2str(D(j,3))

Subject: How to display values on a plot

From: Barry Williams

Date: 12 Apr, 2013 10:35:05

Message: 14 of 15

"Dimitra" wrote in message <kk8mg4$rqn$1@newscl01ah.mathworks.com>...
> Hello,
>
> I am new to Matlab and I have a similar problem. I have a 300X3 matrix D(X,Y,indicator) that I want to plot in 2D. In the plot, for each set (X,Y), I would like to have the value of the Indicator (3rd column of D) plotted next to the point.
>
> I am using scatter to plot the X,Y, because I want to give different colors to the points, according to the value of their indicator.
> scatter(D(:,1),D(:,2),15,Color(:,1:3))
>
> Color(:,1:3) is the matrix where I have defined the colors I want.
>
> How can I plot the value of each point at the plot (a number with a decimal part) on my figure?
> I tried the following but without success:
>
> for j=1:300
> text(D(j,1),D(j,2),[' ', D(j,3)],'FontSize',7);
> end
>
>
> Thank you in advance.

The numbers in the array need to converted to text. num2str or sprintf would work. The latter is more flexible. I'm not sure what the ' ' is doing in [' ',D(j,3)].
Of course, this ignores the obvious question of why you want to label all 300 points. It will be way too crowded to read.
Barry

Subject: How to display values on a plot

From: Dimitra

Date: 15 Apr, 2013 08:10:11

Message: 15 of 15

Thanks a lot for the answers! The code is working now.

It is indeed very congested in the plot, I wanted though to have the option to plot the values in my plot (or maybe part of the values), if needed.

Thanks a lot again!

"Barry Williams" <barry.r.williamsnospam@saic.com> wrote in message <kk8o0p$2fi$1@newscl01ah.mathworks.com>...
> "Dimitra" wrote in message <kk8mg4$rqn$1@newscl01ah.mathworks.com>...
> > Hello,
> >
> > I am new to Matlab and I have a similar problem. I have a 300X3 matrix D(X,Y,indicator) that I want to plot in 2D. In the plot, for each set (X,Y), I would like to have the value of the Indicator (3rd column of D) plotted next to the point.
> >
> > I am using scatter to plot the X,Y, because I want to give different colors to the points, according to the value of their indicator.
> > scatter(D(:,1),D(:,2),15,Color(:,1:3))
> >
> > Color(:,1:3) is the matrix where I have defined the colors I want.
> >
> > How can I plot the value of each point at the plot (a number with a decimal part) on my figure?
> > I tried the following but without success:
> >
> > for j=1:300
> > text(D(j,1),D(j,2),[' ', D(j,3)],'FontSize',7);
> > end
> >
> >
> > Thank you in advance.
>
> The numbers in the array need to converted to text. num2str or sprintf would work. The latter is more flexible. I'm not sure what the ' ' is doing in [' ',D(j,3)].
> Of course, this ignores the obvious question of why you want to label all 300 points. It will be way too crowded to read.
> Barry

Tags for this Thread

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.

Contact us