color coding transitions in a stackplot

General forum for EasySpin: questions, how to's, etc.
Post Reply
melaniedrake
Newbie
Posts: 2
Joined: Wed Jul 15, 2015 4:19 pm

color coding transitions in a stackplot

Post 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)
Matt Krzyaniak
EasySpin Guru
Posts: 153
Joined: Tue Jul 22, 2014 11:01 am
Location: Northwestern University

Re: color coding transitions in a stackplot

Post 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')
Stefan Stoll
EasySpin Creator
Posts: 1073
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: color coding transitions in a stackplot

Post 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]);
Post Reply