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:
Plotting

Subject: Plotting

From: Jessica

Date: 7 Sep, 2008 13:19:01

Message: 1 of 6

Hi,


I am trying to create a high-quality graph. Below I have included the code that I am currently using. I have two problems with this code. First, the two lines that the programs draws are not perfectly straight-- they look jagged. Is there a way to make them look straight?

And second, I would like to create a legend that includes both the type of line and the data point. For example, the legend would read that a thick line and a square point are Data1 while a thin line and "plus" point are Data2.

Any suggestions?

Thanks in advance for your help!

My Code:

x1=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9];
y1=[16.41 32.675 39.455 3.127 40.592 45.003 14.29597827 45.101 2.635 7.954 10.946 17.786 8.164 7.444 11.254 5.248 31.457 39.38 21.944 57.534 41.893 59.09 14.205 43.024 58.483 56.04 0 10.965 17.617 16.281 58.885 33.357 19.021 0 59.488 51.584 41.564 59.786 41.155 60 16.879 29.83 59.495 48.599 0 10.671 18.169 11.141 54.518 35.943 22.59 0 60 54.95 52.286 58.424 43.095 60 16.138 26.869 59.685 47.433 0 27.514 13.633 8.229 50.609 35.557 13.963 0 55.365 54.153 48.967 51.128 15.259 60 18.884 5.292 58.256 49.92 0 42.145 13.321 30.52 49.576 34.803 10.372 0 48.046 55.844];


x2=[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9];
y2=[11.558 8.589 24.195 4.911 9.559 4.957 3.779 21.144 5.232 5.587 8.944 11.748 9.657 7.422 11.198 6.376 6.557 8.084 30 0 7.669 3.86 2.355 51.975 0 1.509 8.704 23.997 9.936 1.58 0 0 0 4.294 27.685 0 2.359 0 4.278 39.953 0 0 36.974 21.975 0 0 0 0 0 0 28.045 0 7.586 0 1.322 25.683 0 0 8.981 0 0 0 0 0 0 0 22.369 0 0 0 4.813 12.283 0 0 1.34 0 0 0 0 0];


scatter(x1,y1,30,'k+');
hold on
scatter(x2,y2,30,'ks');
hold on


x = 0.9:1:10;
y3=(-1.0756*x)+12.4321; %Rac
y4=(0.5562*x)+29.1053; %Owl
plot (x,y3,'k','LineWidth',5);
hold on
plot(x,y4,'k','LineWidth',10);

axis( [0.9, 10, 1, 50] )
xlabel( 'Minute passed' );
ylabel( 'Rate' );

Subject: Plotting

From: Husam Aldahiyat

Date: 7 Sep, 2008 15:33:02

Message: 2 of 6

To make it not jagged try the myaa function at File Exchange.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=20979&objectType=file

Subject: Plotting

From: Jessica

Date: 7 Sep, 2008 20:57:02

Message: 3 of 6

Thanks for that tip. That function did help make the lines smoother but the scatter plot points now look rather faint. Also, it doesn't seem possible to save the myaa graph as a high-quality image? Any further suggestions?


"Husam Aldahiyat" <numandina@gmail.com> wrote in message <ga0s7e$p07$1@fred.mathworks.com>...
> To make it not jagged try the myaa function at File Exchange.
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=20979&objectType=file

Subject: Plotting

From: Husam Aldahiyat

Date: 8 Sep, 2008 02:36:02

Message: 4 of 6

I think you will need a program to do that outside MATLAB.

As for the legend question, in case you haven't figured it out yet, here is the answer:

legend works like this:

legend([handle1,handle2,handle3],'text1','text2','text3')

So you will need to obtain the handles of the graphic objects you wish to include in the legend.

One way to do this is by using findobj, like this:

h1=findobj('marker','*')
h2=finobj('type','line','color','b')
etc...

Subject: Plotting

From: Gavrilo Bozovic

Date: 8 Sep, 2008 09:37:02

Message: 5 of 6

You are plotting straight lines --> you'll be best using the "line" function, with only the start and end points of the line. It will all be nice and smooth.

Then just a side comment: if you want to plot several curves in one set of axes, you just have to type "hold on" once.

for instance:

figure,
grid on
hold on
plot(...)
plot(...)
plot(...)

will do, and so you won't add unncessary lines to your code.

Subject: Plotting

From: Jessica

Date: 9 Sep, 2008 15:21:03

Message: 6 of 6

thanks for the tip!

"Gavrilo Bozovic" <gavrilo.bozovic@helbling.ch> wrote in message <ga2rnu$6eh$1@fred.mathworks.com>...
> You are plotting straight lines --> you'll be best using the "line" function, with only the start and end points of the line. It will all be nice and smooth.
>
> Then just a side comment: if you want to plot several curves in one set of axes, you just have to type "hold on" once.
>
> for instance:
>
> figure,
> grid on
> hold on
> plot(...)
> plot(...)
> plot(...)
>
> will do, and so you won't add unncessary lines to your code.
>
>

Tags for this Thread

No tags are associated with 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