I have a trouble regarding creating three different colorbars on y axis one under the other, on the same graph and on the same x-axis. So basically data1, data2, data3 will be my three data sets and they will be on the y-axis. On my x-axis I will have the time. I tried the subplot function, but I ended up with multiple graphs. But I want to show data1, data2, data3 on the same graph. I sketched roughly what I am trying to do and I will appreciate any help from you. Thank you in advance.
I understand that you are facing an issue while plotting multiple data sets on y-axis against same x-axis in the same plot as shown in the attached image.
In order to plot the y-axis horizontally you can use the “barh” MATLAB function.
To plot multiple data on y-axis in the same plot, the following workaround can be helpful:
%Example:
x = [1980 1990 2000];
y = [8 15 25; 30 35 40; 50 55 62]; % multiple y data set
tiledlayout(1,1);
ax2 = nexttile;
barh(ax2,x,y,'stacked') % Stacked
To add the color map with the plot colors:
c1 = [0 0.4470 0.7410];
c2 = [0.8500 0.3250 0.0980] ;
c3 = [0.9290 0.6940 0.1250] ;
c = [c1 ; c2; c3] ;
colorbar;
%x = minimum value
%y = maximum value
colorbar('Ticks',[x,y],...
'TickLabels',{'Min','Max'})
colormap(c);
For more information, kindly refer to the following links:
First of all thank you for your informative answer. But the thing I am trying to do is a bit different, where each horizontal bar on the y axis will be matrices with their time data (so A, B and C are 500x2 matrices where the first column is force and the second column is time), and the x axis on the graph will be the time data, not the values of the y vectors. Also, I am trying to do the horizontal bars as colorbars, where their color will change according to their value, and a reference colorbar like this:
Thank you for your help and support, I would be very happy if you can help me about this.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.