Rotate stacked plot Labels to have them vertical - App Designer

26 vues (au cours des 30 derniers jours)
Andrea Quintarelli
Andrea Quintarelli le 13 Août 2019
Commenté : Adam Danz le 1 Juin 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!
question.JPG

Réponse acceptée

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi le 16 Août 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 commentaires
Bruce Vernham
Bruce Vernham le 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
hirdesh kumar pharasi le 14 Juin 2020
Modifié(e) : hirdesh kumar pharasi le 14 Juin 2020
True, only for that particular reason I am unable to use it

Connectez-vous pour commenter.

Plus de réponses (1)

Adam Danz
Adam Danz le 19 Nov 2020
Modifié(e) : Adam Danz le 17 Mai 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 commentaires
Pedro
Pedro le 1 Juin 2023
Modifié(e) : Pedro le 1 Juin 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
Adam Danz le 1 Juin 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by