Labeling both graphs for a priceandvol plot

2 ビュー (過去 30 日間)
Brett Wicker
Brett Wicker 2021 年 3 月 30 日
編集済み: Vaibhav 2024 年 2 月 14 日
How can you label the price and volume graphs when you plot the graphs using the priceandvol function? Right now when I enter my code it only attaches to the bottom graph and I do not know how to format the top graph so I can label the x/y axis?
  1 件のコメント
Brett Wicker
Brett Wicker 2021 年 3 月 30 日
This is my current code:
ford = xlsread('Ford_Stock_Prices.xlsx');
MATLABDate = x2mdate(ford,1,'datetime');
priceandvol(ford(:,1:end));
xlabel('Date')
ylabel('Volume')
dateaxis('X',12,min(ford(:,1)))
title('Ford Stock Price')
legend('Volume of Shares')

サインインしてコメントする。

回答 (1 件)

Vaibhav
Vaibhav 2024 年 2 月 14 日
編集済み: Vaibhav 2024 年 2 月 14 日
Hi Brett
I understand that you are facing issues in formatting the top graph so that you can label the x/y axis.
When you use the priceandvol function to plot stock prices and volume, it creates a figure with two subplots, one on top of the other. The top one usually displays the stock price, while the bottom one shows the trading volume. To add labels and titles to each subplot, you'll need to grab handles to these subplots and then use them to set properties for each one individually.
Here's how you can modify your code to label both the price and volume graphs:
% Read data from Excel file
ford = xlsread('Ford_Stock_Prices.xlsx');
MATLABDate = x2mdate(ford(:,1),1,'datetime');
% Create the price and volume plot
[ax, h1, h2] = priceandvol(ford(:,1:end));
% ax(1) is the handle for the top subplot (price)
% ax(2) is the handle for the bottom subplot (volume)
% Label the x-axis of the bottom plot (volume)
xlabel(ax(2), 'Date')
ylabel(ax(2), 'Volume')
dateaxis(ax(2), 'X', 12, min(ford(:,1)))
title(ax(2), 'Ford Stock Volume')
legend(ax(2), 'Volume of Shares')
% Label the x-axis of the top plot (price)
xlabel(ax(1), 'Date')
ylabel(ax(1), 'Price')
title(ax(1), 'Ford Stock Price')
legend(ax(1), 'Price of Shares')
% Adjusting the x-axis date format for both subplots
dateaxis(ax(1), 'X', 12)
dateaxis(ax(2), 'X', 12)
You can refer to the MathWorks documentation below to learn more about "priceandvol" function:
Hope this helps!

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by