Color Bar Classifying different time points

I have three sets of time - Time1, Time2, Time3. These three time points do not overlap. I would like to make a color bar to show when it is Time1, Time2 or Time3. this is hard to describe so I attached an image with the basic design. The idea being that this would continue for whatever times are in each of the three vectors.
Please let me know if I can clarify anymore.

3 个评论

Seems fairly easy. What other data have you got? Could you upload some sample data and sketch how youd like to plot?
I attached two matrices with time points. The plot just could be similar to the plot above, other than that I am not too picky!
Oh, I thought you had some x-y data to go with the times. I have actually written a code for this exact type of plot before. I'll see if I can find it in my previous answers.
Edit: Here it is. I'll see if I can adapt it to your data.

请先登录,再进行评论。

 采纳的回答

Try something like this, which is based on a previous answer
n=length(t_comb_2(:));
subplot(1,2,1);
x=t_comb_2;
x=x';
x=x(:)';
tic
X=[0 x;0 x];
Y=[1.1.*ones(1,n+1);0.9.*ones(1,n+1)];
colormap(lines(n+1))
Z=linspace(0,1,n+1);
Z=[Z;Z];
surf(X,Y,Z)
view([0 90])
set(gca,'ycolor','none')
axis tight
ylabel('time')
.
Note that the colors were are determined by their z-value and the colormap lines. You can change the colormap and try different ones.

10 个评论

This looks great. What about using the same 2-3 colors for the 2-3 units of time?
So that all the times from the first matrix are one color and all the other times from the other matrix another color.
I've updated the answer. It's best if you try and grasp how the colors are determined from the Z-value, so that you can customize the code yourself. It's a bit hard to see, but you can tell that the color sequence are the same for both data sets. You can see if from this view:
Ok, I think I understand the z value determining the color. How do you plot the above?
Just rotate the plot, either manually or by writing
set(gca,'view',[-37.5000 30.0000])
for the default 3d-view.
The plot is already in 3d as per the code above, but you are viewing it from above by setting the view to [0 90]
Ok maybe I don't understand. If I have three different matrices with intervals of time in each, how do I get them to repeat the same colors. I attached an example of an image I want to replicate if REM, NREM and wake are three different matrices of intervals.
Just take a look at this example
load time2.mat
n=length(t_comb_2(:));
x=t_comb_2;
x=x';
x=x(:)';
X=[0 x;0 x];
Y=[1.1.*ones(1,n+1);0.9.*ones(1,n+1)];
colormap([0 0 0;1 0 0;0 0 1])
Z=[1 2 3 1 2 3 1 2 3 2 1 3 2 1 3 2 1 1 1 1 1 1 1 1 1 1 1]
Z=[Z;Z];
surf(X,Y,Z)
view([0 90])
set(gca,'ycolor','none')
axis tight
ylabel('time')
in the colormap I have defined three colors: black, red and blue.
colormap([0 0 0;1 0 0;0 0 1])
black redblue
there are 26 segments in time2.mat, and I've added a 27th segment between t=0 and the first segment. If you do not wish to have this 27th segment, just remove the zeros from this line:
X=[0 x;0 x];
We need to define a number of colors equal to the number of segments, in this case 27. This is done here:
Z = [1 2 3 1 2 3 1 2 3 2 1 3 2 1 3 2 1 1 1 1 1 1 1 1 1 1 1]
black red blue
This is the color sequence. In this case it's [black red blue black red blue black red blue red black...]. Note that some segments are really short, so they are barely visible in the plot.
If you have 4 different groups, just define 4 colors in the colormap and number your segments 1-4 instead of 1-3.
I still am not sure I am making myself clear. Could you take the all the time intervals from the first matrix (time1) and make them all the same one color and the second matrix (time2) all them all the same color?
I have been trying to work with your solution and I do not htink that it is addressing what I asked
Its a bar with different color segments... How can it not be what you asked? Do you want time1 and time2 plotted in the same bar?? Are they not overlapping?

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 White 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by