Stackedplot axes XLabel = ('Raman shift [cm^{-1}]') (superscript) not working
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Dear community,
I was working on some figures with ln1 = stackedplot and tried to use the same label for my x-axes as I did when using ln1 = plot. So when using plot I can add the line ax1.XLabel = ('Raman shift [cm^{-1}]') and this shows what I want. Using stackedplot prints exactly this term 'Raman shift [cm^{-1}]', so I have to use '1/cm' instead. Do you know how to use superscript inside the axes label for stackedplot?
채택된 답변
Unfortunately stackedplot doesn't let you control the interpreter for the XLabel, so you can't use tex like you can for a regular axes.
t=tiledlayout(1,1);
nexttile
stackedplot(rand(10,3))
xlabel(t,'Raman shift [cm^{-1}]')

Notes:
- The default FontSize for a TiledChartLayout's label is a bit bigger, but you can change it.
- If you want to adjust the position of the stackedplot, you'll instead need to adjust the position of the TiledChartLayout (t)
댓글 수: 5
Thanks for the great solution.
I tried myself a little bit and got that far:
tbl3=horzcat(spec_raman,spec_raman2,spec_raman3);
XAxislow = 400;
XAxishigh = 1800;
t=tiledlayout(1,1);
nexttile
stackedplot(wave_raman, tbl3);
ax1 = gca;
ax1.FontSize=12;
ax1.LineWidth=1.2;
ax1.XLimits = [XAxislow XAxishigh];
ax1.AxesProperties(1).YLimits= [0 1200];
ax1.AxesProperties(2).YLimits= [0 1200];
ax1.AxesProperties(3).YLimits= [0 1200];
ax1.DisplayLabels = {'C)','B)','A)'};
txt = xlabel(t,'Raman shift [cm^{-1}]');
txt2 = ylabel(t,'Raman intensity');
txt.FontSize = 13;
txt2.FontSize = 13;
t.TileSpacing = 'none';
t.Padding = 'tight';
leading to this chart:

Strange thing,
TileSpacing = 'none'
is not working. Whatever I enter here from documentation like 'loose' or 'compact', the result is always the same. I would like to use 'none'. Edit: I guess it´s because I use 1,1 tiledlayout and for this function I would need to use 1,3 with separate plots?
My next question is: How can I get the y-label more closer to the graph as I would like to switch the y-label with ax1.DisplayLabels. I tried to do that in the stackedplot function, but the only way to use it there is the DisplayLabels itself.
Do you have another idea?
@Raphael - in response to your 'answer' below:
I don't know of a great way to get the label closer to the bottom of the stackedplot using this workaround, a somewhat hacky solution is to tweak the VerticalAlignment property on the label. That doesn't give you precise control of the position, but you might find one of the alignment options suits you well.
t=tiledlayout(1,1);
nexttile
stackedplot(rand(10,3))
xlabel(t,'Raman shift [cm^{-1}]','VerticalAlignment','middle')

If you want that deeper control you'll need a different approach to making the text. One option would be to use the annotation function, and position it based on the position of the stacked plot. Note that this method won't automatically update when you change the figure size, so you'll need to update it when you resize...
figure
sp=stackedplot(rand(10,3));
x = sp.Position(1);
y = sp.OuterPosition(2);
w = sp.Position(3);
h = sp.Position(2) - sp.OuterPosition(2);
a = annotation("textbox", [x y w h], 'String','Raman shift [cm^{-1}]', ...
'HorizontalAlignment','center','VerticalAlignment','middle','EdgeColor','none');
% Now if you want to tweak the position (probably easier in some non-normalized unit):
a.Units='pixels';
a.Position(4)=a.Position(4)-10;

Final option which is probably the easiest, but also maybe the most hacky. Add an axes to the tiledlayout, make the axes invisible, add an XLabel to the axes, make the label visible. The tiledlayout should keep the stackedplot and axes aligned, so your label will be in the right position (but note that it depends on the font sizes matching up)
figure;
t=tiledlayout(1,1);
nexttile
sp=stackedplot(rand(10,3));
ax=axes(t,'Visible','off');
ax.FontSize=sp.FontSize;
xlabel(ax,'Raman shift [cm^{-1}]','Visible','on')

Thanks for the quick response.
X-axes is working now. Great hint for the function to make axes unvisible.
What I did understand is, that I need to use annotations for the displayed label, so I can use the tiledlayout for y-axes.
This is what I have done, which is working now:
tbl3=horzcat(spec_raman,spec_raman2,spec_raman3,spec_raman4);
XAxislow = 400;
XAxishigh = 1800;
t=tiledlayout(1,1);
nexttile
stackedplot(wave_raman, tbl3);
ax1 = gca;
ax1.FontSize=12;
ax1.LineWidth=1.2;
ax1.XLimits = [XAxislow XAxishigh];
ax1.AxesProperties(1).YLimits= [0 150];
ax1.AxesProperties(2).YLimits= [0 150];
ax1.AxesProperties(3).YLimits= [0 150];
ax1.AxesProperties(4).YLimits= [0 150];
ax1.DisplayLabels={'','','',''};
ann1 = annotation('textbox',[.94 .21 .5 .5],'String',{'A)'},'FitBoxToText','on');
ann1.VerticalAlignment = 'bottom';
ann1.LineStyle = 'none';
ann1.FontSize = 11;
ann1.FontWeight = 'normal';
ann2 = annotation('textbox',[.94 .42 .5 .5],'String',{'B)'},'FitBoxToText','on');
ann2.VerticalAlignment = 'bottom';
ann2.LineStyle = 'none';
ann2.FontSize = 11;
ann2.FontWeight = 'normal';
ann3 = annotation('textbox',[.94 .63 .5 .5],'String',{'C)'},'FitBoxToText','on');
ann3.VerticalAlignment = 'bottom';
ann3.LineStyle = 'none';
ann3.FontSize = 11;
ann3.FontWeight = 'normal';
ann4 = annotation('textbox',[.94 .84 .5 .5],'String',{'D)'},'FitBoxToText','on');
ann4.VerticalAlignment = 'bottom';
ann4.LineStyle = 'none';
ann4.FontSize = 11;
ann4.FontWeight = 'normal';
txt = xlabel(t,'Raman shift [cm^{-1}]');
txt2 = ylabel(t,'Raman intensity');
txt.FontSize = 13;
txt2.FontSize = 13;
t.Padding = 'compact';
resulting in this:

Which is fine now.
One hint for other readers: t.Padding = 'tight' is not working properly, because it cuts the lower edges off [cm-1 ] when copying the figure.
@MathWorks Support Team Would be great, if Matlab could support drag and drop of a customizable layout (out of the box) which can be filled individually with data.
@Raphael - glad it's working, sorry the workflow is so painful!
Standalone visualizations like stackedplot provide a limited set of options (so you don't get the full feature set that you would with a regular axes) but in exchange they provide some richer features (like the interactive multi-axes datatip line thingy that stackedplot provides). They can be a real time-saver for some visualizations, but when you reach a feature that's not incorporated (like tex interpreted labels) it can be pretty frustrating and you have to get into this sort of workaround space.
I want to use the subscript for the labels bitnthe mentioned method is not able to solve the problem. It will be really gratful if anyone can help me out. Please help me.

추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
