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 673833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:38:21+00:00 2026-05-14T00:38:21+00:00

I would like to plot a vertical line (I’d prefer any orientation, but I’d

  • 0

I would like to plot a vertical line (I’d prefer any orientation, but I’d be happy with just vertical right now) with two-color dashes, say red-blue-red-blue-…

I know I could do it like this:

plot([1,1],[0,1],'r'),
hold on,
plot([1,1],[0,1],'--b')

However, since I need to be able to move the line, among others, it should only have a single handle. How could I do this?

EDIT
Thank you for your answers. I guess I should indeed give some more information.

I have some data that is classified into different parts. I want to be able to manually adjust the boundaries between classes. For this, I’m drawing vertical lines at the classification boundaries and use draggable to allow moving the lines.

For the boundary between the red and the blue class, I’d like to have a red/blue line.

plot(ones(10,1),linspace(0,1,10),'-bs','MarkerFaceColor','r','MarkerEdgeColor','none','linewidth',6)

is what I’m actually using at the moment. However, it’s not so pretty (if I want equal spacing, it becomes a real pain, and I want to give both colors the same weight), and I would like to have the possibility to use three colors (and not with marker edge and face being different, because it makes my eyes bleed).

Unfortunately, draggable does not allow me to use multiple handles, and grouping the lines with hggroup does not seem to create a draggable object.

cline looks like a promising approach, but rainbow colors won’t work for my application.

  • 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-05-14T00:38:22+00:00Added an answer on May 14, 2026 at 12:38 am

    You can use the code you have, and just concatenate the handles from each line into a vector of handles. When you want to change the properties of both lines simultaneously, the SET function is able to accept the vector of handles as an argument. From the documentation for SET:

    set(H,'PropertyName',PropertyValue,...)
    sets the named properties to the
    specified values on the object(s)
    identified by H. H can be a vector of
    handles, in which case set sets the
    properties’ values for all the
    objects.

    Here’s an example:

    h1 = plot([1 1],[0 1],'r');    %# Plot line 1
    hold on;
    h2 = plot([1 1],[0 1],'--b');  %# Plot line 2
    hVector = [h1 h2];             %# Vector of handles
    set(hVector,'XData',[2 3]);    %# Shifts the x data points for both lines
    


    UPDATE: Since you mention you are using draggable from the MathWorks File Exchange, here’s an alternate solution. From the description of draggable:

    A function which is called when the
    object is moved can be provided as an
    optional argument, so that the
    movement triggers further actions.

    You could then try the following solution:

    • Plot your two lines, saving the handle for each (i.e. h1 and h2).
    • Put the handle for each in the 'UserData' property of the other:

      set(h1,'UserData',h2);
      set(h2,'UserData',h1);
      
    • Create the following function:

      function motionFcn(hMoving)  %# Currently moving handle is passed in
        hOther = get(hMoving,'UserData');  %# Get the other plot handle
        set(hOther,'XData',get(hMoving,'XData'),...  %# Update the x data
                   'YData',get(hMoving,'YData'));    %# Update the y data
      end
      
    • Turn on draggable for both lines, using the above function as the one called when either object is moved:

      draggable(h1,@motionFcn);
      draggable(h2,@motionFcn);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 360k
  • Answers 360k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you talking about Anonymous Types? May 14, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer You use a semicolon after a statement. This is a… May 14, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer Is there a reason why the plugin omits pom.xml and… May 14, 2026 at 2:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.