Rotate stacked plot Labels to have them vertical - App Designer
25 views (last 30 days)
Show older comments
Andrea Quintarelli
on 13 Aug 2019
Commented: Adam Danz
on 1 Jun 2023
Hi,
i am using stacked plots in App Designer to visulize some data and i would love to rotate the labels on the left side of these plots, having them in vertical direction.
Does Anybody know if this is possible at all with stacked plots?
Thank you very much!
0 Comments
Accepted Answer
Sahithi Kanumarlapudi
on 16 Aug 2019
For normal plots ‘ytickangle’ can be used in order to rotate the y-axis label.
But in case of stacked plots y-axis labels are treated as ‘DisplayLabels’ and their orientation cannot be changed.
3 Comments
Bruce Vernham
on 25 Nov 2019
If that is the case than this feature is completely usless for displaying data and not worth the time and effort to implement the code!
hirdesh kumar pharasi
on 14 Jun 2020
Edited: hirdesh kumar pharasi
on 14 Jun 2020
True, only for that particular reason I am unable to use it
More Answers (1)
Adam Danz
on 19 Nov 2020
Edited: Adam Danz
on 17 May 2023
You can get the axis handles in stackedplot using the undocumented NodeChildren property. Then rotate and center the labels.
rng('default')
h = stackedplot(rand(100,4));
drawnow
ax = findobj(h.NodeChildren, 'Type','Axes');
set([ax.YLabel],'Rotation',90,'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom')
5 Comments
Pedro
on 1 Jun 2023
Edited: Pedro
on 1 Jun 2023
For some reason this is not working for me on MATLAB 2023a running on Windows 11. I also want to change the interpreter for the Y axis to 'tex'. I don't know if it changes anything but I'm using a LiveScript with Output on Right.
This is my code:
figure;
opts.str = 'AE monitoring results 2022-06-14 16:42:40 [120 kN]';
opts.s = stackedplot(MainTT,RateTT,bValueTT,opts.vars,"LegendVisible","off",...
"GridVisible","on",'Title',opts.str);
drawnow
opts.c = parula(numel(opts.s.LineProperties));
opts.ax = findobj(opts.s.NodeChildren,'Type','Axes');
set([opts.ax.YLabel],'Rotation',90,'HorizontalAlignment', ...
'Center', 'VerticalAlignment', 'Bottom', 'Interpreter','tex');
for ii=1:numel(opts.s.LineProperties)
opts.s.LineProperties(ii).MarkerEdgeColor = "k";
opts.s.LineProperties(ii).MarkerFaceColor = opts.c(ii,:);
opts.ax(ii).XAxis.Exponent = 0; %turn off scientific notation on axis
end
% Adjust individual graphs
% Make every graph from 2 to 'n' scatter
for ii = 2:numel(opts.s.LineProperties)
opts.s.LineProperties(ii).PlotType = "scatter";
opts.s.LineProperties(ii).MarkerFaceColor = opts.c(ii,:);
end
% AccumRate
opts.s.AxesProperties(1).LegendLabels = {'cum AE'};
% Rate
opts.s.AxesProperties(2).LegendLabels = {'AE/sec'};
% Frequency
opts.s.AxesProperties(3).YLimits = [0 1000];
opts.s.AxesProperties(3).LegendLabels = {'f (kHz)'};
% Amplitude
opts.s.AxesProperties(4).YLimits = [0 140];
opts.s.AxesProperties(4).LegendLabels = {'A (dB)'};
% beta_t
opts.s.LineProperties(end-1).PlotType = 'plot';
opts.s.LineProperties(end-1).LineStyle = '--';
opts.s.LineProperties(end-1).Color = 'k';
opts.s.LineProperties(end-1).Marker = 'o';
opts.s.LineProperties(end-1).MarkerFaceColor = opts.c(end-1,:);
opts.s.LineProperties(end-1).MarkerEdgeColor = 'k';
opts.s.AxesProperties(end-1).LegendLabels = {'\Beta_t'};
% b-Value
opts.s.LineProperties(end).PlotType = 'plot';
opts.s.LineProperties(end).LineStyle = '--';
opts.s.LineProperties(end).Color = 'k';
opts.s.LineProperties(end).Marker = 'o';
opts.s.LineProperties(end).MarkerFaceColor = opts.c(end,:);
opts.s.LineProperties(end).MarkerEdgeColor = 'k';
opts.s.AxesProperties(end).YLimits = [0.5 2];
opts.s.AxesProperties(end).LegendLabels = {'b-value'};
clear opts ii
And this is my output
Also the Interpreter seems to be changing just for the title (which is not what I want).
When I copy and run your code it works as intendend. My guess is that some of my other property settings is interfering with the set function, but I can't grasp what it is.
Adam Danz
on 1 Jun 2023
@Pedro when using undocumented features there's no guarantee that they will always work. Figures generated in live scripts behave differently and don't support these undocumented features.
I recommend writing to tech support to request an interpreter property in stackedplot as well as having access to the axes label handles. Go to Contact Support > Report a Bug > Select Technical Support & Product help, bugs, suggestions.
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!