当前位置:网站首页>MATLAB如何将k线图设置为经典红绿配色?
MATLAB如何将k线图设置为经典红绿配色?
2022-07-27 21:49:00 【slandarer】
一个简单的图形对象属性设置小实例?
效果


讲解
首先来看官网的例子哈:
load SimulatedStock.mat;
candle(TMW(end-20:end,:),'b')
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-V9GO4Y6H-1658909385252)(https://files.mdnice.com/user/23963/6127d89a-4a14-43dd-a7a4-6631355bf173.png)]
后面的'b'就是'blue'蓝色,当然可以设置为'k'黑色,'r'红色等一系列颜色,但是这样的设置方式的绘图结果依旧是只有k线跌的时候有颜色,涨的时候颜色是空白的,我们想要的是涨和跌分别设为不同颜色。
首先我们获取一下candle函数的返回值:
CHdl=candle(TMW(end-20:end,:),'b')

我们能够发现返回了一条线及一堆多边形,嗯?多边形的数量对上了,但是线只有一条??,我们get一下那条线的属性:
get(CHdl(1))

我们会发现每两个数据点之间都有个NaN,怪不得只用一条线就能生成二十多条线,原来其实还是一条线只不过各个线之间的链接被用NaN替换掉了,要是数据没有用NaN隔开,那么那条线是这样的:

因此不包含NaN的每两个数据点就可以画出把一条线(或者包含NaN的三个数据点)。
啊这样就非常简单了,就循环检查一下每个方形是白色还是蓝色,如果是白色,就将方形的面颜色FaceColor、轮廓颜色EdgeColor、以及对应竖直线的颜色Color,修改为红色,否则修改为绿色即可,代码非常简短:
完整代码
load SimulatedStock.mat;
CHdl=candle(TMW(end-20:end,:),'b');
rColor=[208,48,53]./255; % 红色
gColor=[55,173,55]./255; % 绿色
% 获取竖直线数据
LineHdl=CHdl(1);
LineDataX=reshape(LineHdl.XData,3,[]);
LineDataY=reshape(LineHdl.YData,3,[]);
hold on
% 若原本颜色是白色则改为红色,蓝色则改为绿色
for i=2:length(CHdl)
if CHdl(i).FaceColor(1)==1
plot(LineDataX(:,i-1),LineDataY(:,i-1),'Color',rColor)
CHdl(i).FaceColor=rColor;
CHdl(i).EdgeColor=rColor;
else
plot(LineDataX(:,i-1),LineDataY(:,i-1),'Color',gColor)
CHdl(i).FaceColor=gColor;
CHdl(i).EdgeColor=gColor;
end
end
% 删除原本的竖直线
delete(LineHdl);

边栏推荐
- 永州植物细胞实验室建设布局方案
- Those "experiences and traps" in the data center
- 传奇服中怎么刷装备
- JS event propagation capture stage bubbling stage onclick addeventlistener
- Yuanuniverse office, the ultimate dream of migrant workers
- 永州出入境检验实验室建设那些事
- 细数国产接口协作平台的六把武器!
- MFC prompts that this application has requested the runtime to terminate it in an unused way editbox box has been deleted and is still in use
- "Digital economy, science and technology for the good" talk about dry goods
- Legendary Internet Setup tutorial with graphic explanation - GOM engine
猜你喜欢

「图神经网络:基础、前沿与应用」最新IJCAI2022教程

Oracle password expiration solution

荣耀多款产品齐发,笔记本MagicBook V 14售价6199元起

『百日百题 · 基础篇』备战面试,坚持刷题 第三话——分支语句!

14、 C pointer explanation (IV): pointer of pointer

Liux common commands (view and open firewall port number + view and kill process)

Remote monitoring of pump station

The 4-hour order exceeds 20000+, claiming to be "the most luxurious in a million". Is the domestic brand floating?

(12) 51 Single Chip Microcomputer -- use DS18B20 to measure the outdoor temperature in Gongjiang West

正值三伏天我却被吓出了冷汗:驾驶安全隐患离我们有多远?
随机推荐
The second uncle cured my spiritual internal friction and made me angry out of station B
require、loadfile、dofile、load、loadstring
很棒的一个思维题CF1671D Insert a Progression
软件运维监控有哪些?
HarmonyOS 3纯净模式可限制华为应用市场检出的风险应用获取个人数据
What are the software operation and maintenance monitoring?
每次读取一行字符串输入(有待补充)
How to use C WinForm to copy files and display progress
"Digital economy, science and technology for the good" talk about dry goods
liux常用命令(查看及其开放防火墙端口号+查看及其杀死进程)
「图神经网络:基础、前沿与应用」最新IJCAI2022教程
MFC提示this application has requested the runtime to terminate it in an unusual way editbox框已经删了还在使用
In the third week of July, the list of feigua data station B up main ranking list was released!
If we were the developer responsible for repairing the collapse of station B that night
[GWCTF 2019]BabyRSA1
BUUCTF-RSA
JS ATM机输出
新媒体内容输出方式-短视频
『百日百题 · 基础篇』备战面试,坚持刷题 第三话——分支语句!
JS event propagation capture stage bubbling stage onclick addeventlistener