필터 지우기
필터 지우기

adding textbox to plot - text doesnt stay in one line

조회 수: 18 (최근 30일)
Jan Böttner
Jan Böttner 2023년 8월 11일
댓글: Voss 2023년 8월 11일
Hi,
i want to add a text box to my chart. I followed the documentation but in my case, the text doesnt stay in one line and I'm wondering how I can resolve this.
It should be 'Biomass = 1.03' and 'Electricity = 2.065'.
figure()
hb = bar(out.combinednew{:,1}, [out.combinednew{:,3},out.combinednew{:,9},out.combinednew{:,12}]);
legend(out.combinednew.Properties.VariableNames([3,9,12]));
xlabel('Primary Energy Demand');
xscale = Tmin:2:Tmax;
xticks(Tmin-2:2:Tmax+2);
xticklabels({'HP',xscale,'LGB'})
hb(1).FaceColor = [0.83 0.83 0.83];
hb(2).FaceColor = [0.4660 0.6740 0.1880];
hb(3).FaceColor = [0 0.4470 0.7410];
txt = {'Primary energy factors:','Biomass =' num2str(Basisdaten.Primaerenergiefaktor.Biomasse.today), ...
'Electricity =' num2str(Basisdaten.Primaerenergiefaktor.Strom.today),};
dim = [.15 .6 .3 .3];
annotation('textbox',dim,'String',txt,'FitBoxToText','on');
Furthermore I would like to have subscripted letters in the legend on the top right but I'm reading those out from the labels in a table. Is this possible?
Thanks!

채택된 답변

Voss
Voss 2023년 8월 11일
편집: Voss 2023년 8월 11일

To fix the one-line-text problem, enclose the relevant text in [ ] to make it a single character vector:

txt = {'Primary energy factors:',['Biomass =' num2str(Basisdaten.Primaerenergiefaktor.Biomasse.today)], ...
      ['Electricity =' num2str(Basisdaten.Primaerenergiefaktor.Strom.today)]};
  댓글 수: 2
Jan Böttner
Jan Böttner 2023년 8월 11일
perfect, thanks a lot!
Voss
Voss 2023년 8월 11일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

C B
C B 2023년 8월 11일
편집: C B 2023년 8월 11일
It is happening because its creating seprate cells.
you can modify like below :
txt = {'Primary energy factors:','Biomass = ' ,num2str(11), ...
'Electricity = ' num2str(12),};
display(txt)
txt = 1×5 cell array
{'Primary energy factors:'} {'Biomass = '} {'11'} {'Electricity = '} {'12'}
txt = {'Primary energy factors:',['Biomass = ' ,num2str(11)], ...
['Electricity = ', num2str(12)],};
display(txt)
txt = 1×3 cell array
{'Primary energy factors:'} {'Biomass = 11'} {'Electricity = 12'}
figure()
xlabel('Primary Energy Demand');
txt = {'Primary energy factors:',['Biomass = ' ,num2str(11)], ...
['Electricity = ', num2str(12)],};
dim = [.15 .6 .3 .3];
annotation('textbox',dim,'String',txt,'FitBoxToText','on');

카테고리

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

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by