Borrar filtros
Borrar filtros

Renaming y-axis of stackedplot in MATLAB

9 visualizaciones (últimos 30 días)
Vicky Ngo
Vicky Ngo el 29 de Sept. de 2021
Comentada: Vicky Ngo el 30 de Sept. de 2021
Hi, here I just import some stock prices for Apple (which is inside the Apple.mat file in the first line) and do a few calculations in MATLAB. I plot stock return vs time using stackedplot, however I can't figure out how I can rename the y-axis to something else rather than Column1. Can anyone help me with that? (sorry this sounds like an amateur question).
I attached the pic of the graph as well as the Apple.mat table here. Thank you so much!
% Name of loaded table is AppleDailyPriceHistoryTable
% 'Ascending' sorts dates from oldest to newest (2017-2021)
% 'Descending' sorts dates from newest to oldest (2021-2017)
% Either sort the table in ascending order using the code below or manually in
% the variables menu. If already sorted then skip
% Apple_descending=sortrows(Apple_ascending,1,'descend');
t = AppleDailyPriceHistoryTable{:,1}; % extract first column = dates
st = AppleDailyPriceHistoryTable{:,2}; % extract second column = prices
STplot = stackedplot(t,st);
STplot.XLabel = 'Exchange Date';
% Calculate rt. (Extract from the table will return a cell array, which can't
% be used for numerical calculations).
% rt is in decimal form, not percentage form.
for i=1:1:(length(st)-1)
dt = 1/12;
mean = sum(rt)/(length(st)-1);
mu = mean/dt;
sd = std(rt);
sigma = sqrt(1/dt)*sd;
% mean = 0.001565 = 0.1565%
% sd = 0.020558
% sigma = [0.0712144108966816]
% mu = [0.0187856732853678]

Respuesta aceptada

Dave B
Dave B el 29 de Sept. de 2021
(I'm not entirely sure why you're using stackedplot if you only have one plot, you might consider just using 'plot' but...)
You can use the DisplayLabels property on a stackedplot to set the labels:
s.DisplayLabels={'Apple' 'Banana' 'Microsoft'};

Más respuestas (0)


Más información sobre Time Series Objects en Help Center y File Exchange.




Community Treasure Hunt

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

Start Hunting!

Translated by