guskenny83
guskenny83

Reputation: 1373

How can i specify the line colour using gplot in MATLAB?

I would like to plot a graph in MATLAB using gplot.

In the documentation for gplot, it says the proper syntax is:

gplot(A,Coordinates,LineSpec)

so if I do something like:

gplot(A,XY,'-or');

it will plot the graph in red with circles for the vertices. My problem is that i would like to plot it in grey, however the documentation for LineSpec seems to only allow line colours in the set: {r,g,b,c,m,y,k,w}; i can't seem to find anywhere in the documentation that lets you specify the line colour using an RGB triplet.

Am i just missing something?

Upvotes: 0

Views: 596

Answers (1)

sco1
sco1

Reputation: 12214

Looking through the gplot code it's a bit strangely designed. It uses the standard plot function but the logic it uses to get the line spec precludes the use of PV pairs that work with plot. Other than modifying the code I don't see a way to specify the Color property with gplot like you can with a normal line plot.

However, there is undocumented behavior in gplot that will allow you to plot the data normally yourself using a standard plot call. From the code:

%   [X,Y] = GPLOT(A,xy) returns the NaN-punctuated vectors
%   X and Y without actually generating a plot. These vectors
%   can be used to generate the plot at a later time if desired.  As a
%   result, the two argument output case is only valid when xy is of type
%   single or double.

So we can get our XY data and plot ourselves:

k = 1:30;
[B,XY] = bucky;
[X, Y] = gplot(B(k,k),XY(k,:));
plot(X, Y, '-*', 'Color', [0 1 1]);
axis square

yay

Upvotes: 1

Related Questions