need to to put input from user in the legend
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Adam Danz
2020-11-16
编辑:Adam Danz
2020-11-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!