필터 지우기
필터 지우기

need to to put input from user in the legend

조회 수: 3 (최근 30일)
Kelsey Pettrone
Kelsey Pettrone 2020년 11월 15일
편집: Adam Danz 2020년 11월 17일
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;

답변 (1개)

Adam Danz
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)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by