Page 1 of 1

color coding transitions in a stackplot

Posted: Wed Jul 15, 2015 4:28 pm
by melaniedrake
Is there a way to color code different transitions in a stack plot? I am simulating the spin-1 NV center, and I would like to have the 0to+1 and 0to-1 transitions be different colors. I can use Opt.Transitions to separate the transitions and plot them separately and on top of each other, but I can't find a way to change the color of the stackplots. Does anyone know if this can be done?

this code will plot the transitions separately, but they are both still blue:

Opt.Transitions=[1 2]; %(0)<->(-1)
Opt.Output='separate';
[Field,NV1]=pepper(SysNV,ExpNV,Opt);

Opt2.Transitions=[2 3]; %(0)<->(+1)
Opt2.Output='separate';
[Field2,NV2]=pepper(SysNV,ExpNV,Opt2);

stackplot(Field,NV1)
hold on
stackplot(Field2,NV2)

Re: color coding transitions in a stackplot

Posted: Thu Jul 16, 2015 6:42 am
by Matt Krzyaniak
Sadly not with stackplot at this moment.

When using opt.Output = 'separate', your spectra come out row-wise. One way that you can achieve what you want is to use the built-in matlab functions to plot and just shift your spectra appropriately.

Code: Select all

% generate an offset matrix
% 2*max(max(NV1)) - estimates the amount that you need to shift spectra by to avoid overlap
% repmat([1:size(NV1,1)]', 1, size(NV1,2)) - makes a vector 1 to number of transitions and repeats that for the number of field points
 
a = 2 * max( max( NV1 ) ) * repmat([1:size(NV1,1)]', 1, size(NV1,2));

% then we just plot
plot(Field,a+NV1,'b',Field2,a+NV2,'g')

Re: color coding transitions in a stackplot

Posted: Thu Jul 16, 2015 5:54 pm
by Stefan Stoll
Here's an alternative. Ask stackplot to return you the handle to the line objects. Then you can modify any line properties directly yourself.

Code: Select all

clear, clf
Field = linspace(0,1,51);
Spc1 = rand(12,51);
Spc2 = rand(12,51);

hold on
h1 = stackplot(Field,Spc1);
h2 = stackplot(Field,Spc2);

set(h1,'Color',[0 0 1]);
set(h2,'Color',[0 0.5 0]);