Results 1 to 4 of 4

Math Help - MatLab plots with legends.

  1. #1
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901

    MatLab plots with legends.

    Hello.

    Is there any way to add a legend to a diagram such that the information int he legend is actually independent of the information on the graph? Such that the information in the legend describes a property of a group of objects, rather than a specific object?

    For example, I have written a program which takes numerous complex numbers, z1, z2, z3, z4...zn and inserts them into an iterative method whereby they converge to either 1, -1, i, -i. I have then plotted each point, z1...zn, as a star.

    However, each point is colour coded according to which number it converges to in the iteration. So I may have 3 points that converge to 1, and hence are plotted in green, and 2 points that converge to i, and hence are plotted in red. So what I want my legend to show is

    * converges to 1
    * converges to -1
    * converges to i
    * converges to -i

    So as you see, the legend refers not to specific points, but a collection of points. And I want my legend to show, for example, the 4th option, even if no number in the iteration ACTUALLY converge to -i.

    So how do I do that?!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Moo
    Moo is offline
    A Cute Angle Moo's Avatar
    Joined
    Mar 2008
    From
    P(I'm here)=1/3, P(I'm there)=t+1/3
    Posts
    5,618
    Thanks
    6
    hello,

    I'm sorry I know only Scilab, which is the free version of Matlab, so maybe it's very similar (especially the commands)

    Suppose you have two plots
    plot2d(s,N,4);
    plot2d(s,N1,6);

    4 and 6 are the colours.

    legends(['Legend corresponding to colour 4','Legend corresponding to colour 6'],[4,6])



    in scilab, you just have to click on the window where the graph is in order to place the legends. Dunno how it is in Matlab
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901
    Quote Originally Posted by Moo View Post
    hello,

    I'm sorry I know only Scilab, which is the free version of Matlab, so maybe it's very similar (especially the commands)

    Suppose you have two plots
    plot2d(s,N,4);
    plot2d(s,N1,6);

    4 and 6 are the colours.

    legends(['Legend corresponding to colour 4','Legend corresponding to colour 6'],[4,6])



    in scilab, you just have to click on the window where the graph is in order to place the legends. Dunno how it is in Matlab
    Hmm this doesn't seem to work!

    My code looks something like:

    Code:
    plot(z1,'*r')
    plot(z2,'*y')
    plot(z3,'*b')
    plot(z4,'*g')
    Where z1...z4 are the complex numbers to be plotted, * indicates that they be plotted as stars, and r/y/b/g denotes the colours.

    So according to your example, my legend code should be:

    Code:
     legend(['Converges to 1','Converges to -1','Converges to i','Converges to -i'],['r','y','b','g'])
    Yes?

    This produces a legend with only 2 entries, as follows:

    * Converges to 1 Converges to -1 Converges to i Converges to -i
    * rybg

    Not quite what I was after! =[
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901
    Anyone else have any ideas!?

    Help!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. MATLAB: Coloring surf-plots
    Posted in the Math Software Forum
    Replies: 0
    Last Post: May 20th 2010, 10:08 AM
  2. Replies: 3
    Last Post: March 29th 2010, 03:10 PM
  3. Probably Plots
    Posted in the Advanced Statistics Forum
    Replies: 3
    Last Post: March 14th 2010, 12:43 PM
  4. Matlab help plots, finding nth number....
    Posted in the Math Software Forum
    Replies: 12
    Last Post: March 10th 2010, 09:25 PM
  5. Log-Log plots!!
    Posted in the Calculus Forum
    Replies: 0
    Last Post: November 9th 2009, 11:38 AM

Search Tags


/mathhelpforum @mathhelpforum