Creating multiple colorbars on y axis one under the other, on the same graph and on the same x-axis

4 vues (au cours des 30 derniers jours)
Hi all,
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.

Réponses (1)

Pravarthana P
Pravarthana P le 28 Sep 2022
Hi Engin Tarhan,
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:
I hope this helps you!
  1 commentaire
alexrecai
alexrecai le 29 Sep 2022
Modifié(e) : alexrecai le 29 Sep 2022
Dear Pravarthana,
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by