Deep Blue
Deep Blue

Reputation: 39

How to customize and color a Matlab 2D-line?

I used this code to draw every 2D-line in the following picture :

Code:

plot([p1(2),p2(2)],[p1(1),p2(1)],':bs');

Result:

enter image description here

As you can see, every line is composed of:

I want to have a different color for each component of the line.And if possible, how to modify the type too of every component .

For example I want the result to be like this for every line:

How can I plot those colors?

Thank you in advance.

Upvotes: 0

Views: 56

Answers (1)

LowPolyCorgi
LowPolyCorgi

Reputation: 5169

You have to decompose your plot procedure in three operations:

hold on

% First point (blue filled squares)
scatter(p1(2), p1(1), [], 'bs', 'filled')

% Second point point (red filled squares)
scatter(p2(2), p2(1), [], 'rs', 'filled')

% Dashed green line in between
plot([p1(2),p2(2)],[p1(1),p2(1)],'g--');

Best,

Upvotes: 0

Related Questions