Effacer les filtres
Effacer les filtres

How can I combine a line plot and a bar graph into one figure?

54 vues (au cours des 30 derniers jours)
Nabil Benhadda
Nabil Benhadda le 11 Juin 2020
Commenté : Nabil Benhadda le 13 Juin 2020
Hello everyone, I have a data set of shares returns and shares turnover for a set of dates and for different shares that I was able to divide into subgroups that I need to plot as follow with the dates represented in the X axis and two Y axis for the following graphed data:
  • The shares returns as a line plot
  • The shares turnover as a bar plot
To do so, I created the given function:
function myplot(abtur,abret,date)
figure;
hold on
plot(date,abret);
hold on
bar(date,abtur);
hold off
end
And I use it as follow:
Work = readtable('Data Plotting.xlsx');
Work.Groups = findgroups(Work.Numero);
splitapply(@myplot,Work.AbnormalTurnover,Work.MarketAdjustedModel,Work.Date,Work.Groups);
However, It seems like my formula doesn't work as it provides me with the graph I did insert, can anyone please help me solve this matter?
Thank you a lot !
  4 commentaires
Rik
Rik le 12 Juin 2020
You should convert your date to an actual date format, either datetime or datenum. That should already help. Looking at the raw data you can also notice the adjusted data is fairly small compared to the other dataset.
If you want more explicit help, put your data in a mat file and attach it.
Nabil Benhadda
Nabil Benhadda le 13 Juin 2020
Thank you A LOT Rik ! That was really helpfull as it allowed me to have a better understanding of the data !

Connectez-vous pour commenter.

Réponse acceptée

Sujay C Sharma
Sujay C Sharma le 12 Juin 2020
Hi,
Have a look at the following Matlab example. From my understanding of your question, the yyaxis function should be able to do exactly what you are looking for when it is used with the bar and the plot functions as shown in the example.
  1 commentaire
Nabil Benhadda
Nabil Benhadda le 13 Juin 2020
Thank you a lot Sujay ! That has really been helpfull !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by