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.
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Translated by
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.