need to to put input from user in the legend
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want the legend to say Austrailia smoking instead of just smoking. The country is what the user puts in. How would i do this for the second figure. Also the bar graph has more bars than there are colors, is there any way to differenciate the bars other than colors?
function deliverable1(app)
data = readtable('RiskFactorAnalysis (1).csv');
userinput = app.CountryDropDown.Value;
userinput2 = app.CountryDropDown_2.Value;
useryear = app.EditField.Value
ind = strcmp(data.Entity,userinput);
year = data.Year(ind);
deaths = data.Total_Deaths_per_100000(ind);
obesity = data.Obesity_Deaths_per_100000(ind);
Drug = data.Drug_Deaths_per_100000(ind);
Alcohol = data.Alcohol_Deaths_per_100000(ind);
smoking = data.Smoking_Deaths_per_100000(ind);
% Extract all info for userinput2
ind2 = strcmp(data.Entity,userinput2);
year2 = data.Year(ind2);
deaths2 = data.Total_Deaths_per_100000(ind2);
obesity2 = data.Obesity_Deaths_per_100000(ind2);
Drug2 = data.Drug_Deaths_per_100000(ind2);
Alcohol2 = data.Alcohol_Deaths_per_100000(ind2);
smoking2 = data.Smoking_Deaths_per_100000(ind2);
% Create the 3 figures
grid(app.Axes,'on')
plot(app.Axes,year,deaths,year2,deaths2); % plot deaths2 against year2, not year
xlabel(app.Axes,'year')
ylabel(app.Axes,'deaths per 100000')
legend(app.Axes,userinput,userinput2)
grid(app.Axes2,'on')
bpcombined = [obesity, Drug, Alcohol, smoking, obesity2, Drug2, Alcohol2, smoking2];
indY2 = year2==useryear;
0 commentaires
Réponses (1)
Adam Danz
le 16 Nov 2020
Modifié(e) : Adam Danz
le 17 Nov 2020
Instead of setting the legend string from the legend function use the DisplayName property in the plot function (see demo).
plot(app.Axes,year,deaths,year2,deaths2,'DisplayName',['Austrailia ',userinput]); % plot deaths2 against year2, not year
Then just call legend without defining the strings,
legend(app.Axes)
0 commentaires
Voir également
Catégories
En savoir plus sur Legend 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!