Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:38:35+00:00 2026-06-04T11:38:35+00:00

I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple

  • 0

I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command ‘hold on;’, and then plot each of the data, followed by this to get my legend:

legend('DataSet1', 'DataSet2') % etcetera

However, the (multiple) datasets I am plotting on the same axes are not necessarily the same datasets each time. I am plotting up to six different sets of data on the same axes, and there could be any combination of these shown (depending on what the user chooses to display). Obviously that would be a lot of elseif’s if I wanted to setup the legend the traditional way.

What I really would like to do is assign each DataSet a name as it is plotted so that afterwards I can just call up a legend of all the data being shown.

…Or, any other solution to this problem that anyone can think of..?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:38:37+00:00Added an answer on June 4, 2026 at 11:38 am

    One option is to take advantage of the 'UserData' property like so:

    figure;
    hold on
    plot([0 1], [1 0], '-b', 'userdata', 'blue line')
    plot([1 0], [1 0], '--r', 'userdata', 'red dashes')
    
    % legend(get(get(gca, 'children'), 'userdata'))                      % wrong
    legend(get(gca, 'children'), get(get(gca, 'children'), 'userdata'))  % correct
    

    Edit: As the questioner pointed out, the original version could get out of order. To fix this, specify which handle goes with which label (in the fixed version, it is in the correct order).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use a plotting tool to visualize data for image processing.
When plotting multiple data series using both line specification ( X , Y ,
I'm doing some data analysis in Matlab, and anytime I call the hold function
When plotting a function using Plot, I would like to obtain the set of
I am plotting data in a plot using wxPython where the data limits on
I spend most of my time plotting data, but unfortunately I haven't found a
I have a scaling problem with XYChart plotting: my data serie ranges in float
When plotting on a figure in MATLAB, I have noticed that parts of the
I'm plotting on top of an image in Matlab. Sometimes, I can't see what's
I am plotting a financial candlestick chart using this MATLAB function: http://www.mathworks.com/help/toolbox/finance/candlefts.html How do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.