在 Matlab 中创建 OHLC 成交量图表

问题描述 投票:0回答:1

我想在 Matlab-R2018a 中创建一个股票图表,其中在同一图中包含数据和成交量,Y 轴显示两种不同的比例,如下所示。 x 轴标签的位置并不重要。

示例: enter image description here

我尝试了

subplot
但无法让最终的图形看起来像图像。也许
tiledlayout
可以做到这一点,但它在 R2018a 中不可用。 这个解决方案在同一个图表中绘制多个相似的数据最接近我想要的,但数据光标给出了错误的值。

x = 470:0.1:484;
z1 = cos(x)/2;
z2 = sin(x)/3;
z3 = cos(x+0.2)/2.3;
figure
plot(x,z1);
hold on
plot(x,z2+2);
plot(x,z3+4);
ytick = [-0.5,0.0,0.5];
set(gca,'ytick',[ytick,ytick+2,ytick+4]);
set(gca,'yticklabel',[ytick,ytick,ytick]);
text(484.5,0,'z1')
text(484.5,2,'z2')
text(484.5,4,'z3')`

Any ideas how to modify it to get the correct values? Or maybe an alternative solution? 
Any help would be appreciated. Thanks 
matlab charts ohlcv
1个回答
0
投票

如果您只需要绘制两个数据集,则可以使用

yyaxis
,然后只需使用两个轴的
ylim
即可将绘图堆叠起来 正确的数据提示值:

x = 470:0.1:484;
z1 = cos(x)/2;
z2 = sin(x)/3;

figure
yyaxis left
plot(x,z1);
yticks([-0.5 0 0.5])
ylim([-2.5 0.5])

hold on
yyaxis right
plot(x,z2);
ylim([-0.5 2.5])
yticks([-0.5 0 0.5])

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.