Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Adding a legend to the plot
Replies: 3   Last Post: Sep 5, 2013 7:54 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: Adding a legend to the plot
Posted: Sep 5, 2013 7:54 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Friday, September 6, 2013 11:11:05 AM UTC+12, GIRAY YALCIN wrote:
> Howdy Folks,
>
>
>
> So I have a dilemma; I will condense the issue here, so that it may be easier to digest the question.
>
>
>
> Let's assume that my data consists of 3 points. Just for giggles, assume that they are at points [10, 2], [15, 3] and [20,4].
>
>
>
> How can I give unique colors to the data that I want. Instead of saying legend('data1','data2','data3'), my goal is to uniquely identify the colors within the legend.
>
>
>
> For example, the following code works fine, but it uses the "legend's" reference to data points.
>
>
>
> R=[1 0 0];
>
> G=[0 1 0];
>
> B=[0 0 1];
>
>
>
> X=[10, 2];
>
> Y=[15, 3];
>
> Z=[20,4];
>
> plot(X(1),X(2),'x','LineWidth',10,'Color', R)
>
> hold on
>
> plot(Y(1),Y(2),'x','LineWidth',10,'Color', G)
>
> plot(Z(1),Z(2),'x','LineWidth',10,'Color', B)
>
> legend('data1','data2','data3')
>
>
>
> Is there a way to say something like this:
>
>
>
> legend('data1',R,'data2',G,'data3',B)
>
>
>
> Or perhaps another way to add legend to the plot without calling the legend function?
>
>
>
> Maybe even showing a jpeg image, which I created in paint, on the outside left corner of the plot?
>
>
>
> What do you think the most ingenious way of approaching this issue is?
>
>
>
> Thanks.


I'm not all sure what you're getting at, but perhaps this will solve your problem:
h1=plot(X(1),X(2),'x','LineWidth',10,'Color', R);
hold on
h2=plot(Y(1),Y(2),'x','LineWidth',10,'Color', G);
h3=plot(Z(1),Z(2),'x','LineWidth',10,'Color', B);
legend([h1 h2 h3],'data1','data2','data3')



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.