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

11 visualizaciones (últimos 30 días)
Raphael
Raphael el 17 de Mzo. de 2022
Comentada: Ron el 3 de Feb. de 2024
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?

Respuesta aceptada

Dave B
Dave B el 17 de Mzo. de 2022
Editada: Dave B el 17 de Mzo. de 2022
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 comentarios
Raphael
Raphael el 19 de Mzo. de 2022
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 el 19 de Mzo. de 2022
@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.

Iniciar sesión para comentar.

Más respuestas (1)

Raphael
Raphael el 19 de Mzo. de 2022
Editada: Raphael el 19 de Mzo. de 2022
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 comentario
Ron
Ron el 3 de Feb. de 2024
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by