Stackedplot axes XLabel = ('Raman shift [cm^{-1}]') (superscript) not working

조회 수: 6 (최근 30일)
Raphael
Raphael 2022년 3월 17일
댓글: Ron 2024년 2월 3일
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?

채택된 답변

Dave B
Dave B 2022년 3월 17일
편집: Dave B 2022년 3월 17일
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.
A workaround: put the stackedplot inside a 1 by 1 tiledlayout, and label the tiledlayout instead:
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)
  댓글 수: 3
Raphael
Raphael 2022년 3월 19일
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.
Thanks @Dave B for the support!
Dave B
Dave B 2022년 3월 19일
@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.

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

추가 답변 (1개)

Raphael
Raphael 2022년 3월 19일
편집: Raphael 2022년 3월 19일
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?
  댓글 수: 1
Ron
Ron 2024년 2월 3일
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.

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

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by