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

6 views (last 30 days)
Raphael on 17 Mar 2022
Commented: Dave B on 19 Mar 2022
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?

Accepted Answer

Dave B
Dave B on 17 Mar 2022
Edited: Dave B on 17 Mar 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:
xlabel(t,'Raman shift [cm^{-1}]')
  • 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)
Dave B
Dave B on 19 Mar 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.

Sign in to comment.

More Answers (1)

Raphael on 19 Mar 2022
Edited: Raphael on 19 Mar 2022
Thanks for the great solution.
I tried myself a little bit and got that far:
XAxislow = 400;
XAxishigh = 1800;
stackedplot(wave_raman, tbl3);
ax1 = gca;
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?




Community Treasure Hunt

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

Start Hunting!

Translated by