Renaming y-axis of stackedplot in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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!
load('Apple.mat');
% 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)
rt(i,1)=st(i)/st(i+1)-1;
end
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]
0 个评论
采纳的回答
Dave B
2021-9-29
(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=stackedplot(rand(30,3));
s.DisplayLabels={'Apple' 'Banana' 'Microsoft'};
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!