用彩色蜡烛和体积作为水平线从Pandas数据框绘制OLHCV

2024-06-25 06:05:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个如下的数据帧:

        Symbol            DateTime      open      high       low     close   volume
0    BANKNIFTY 2019-09-09 09:15:00  27266.20  27266.20  27063.20  27115.00  19200.0
1    BANKNIFTY 2019-09-09 09:16:00  27112.85  27118.90  27096.10  27101.95   6820.0
2    BANKNIFTY 2019-09-09 09:17:00  27105.00  27142.35  27105.00  27135.95      0.0
3    BANKNIFTY 2019-09-09 09:18:00  27130.55  27140.00  27106.95  27113.00  12560.0
4    BANKNIFTY 2019-09-09 09:19:00  27113.55  27113.55  27077.00  27090.55      0.0
5    BANKNIFTY 2019-09-09 09:20:00  27083.05  27083.05  27039.15  27071.85  21260.0
6    BANKNIFTY 2019-09-09 09:21:00  27079.00  27099.00  27070.55  27080.00   2720.0
7    BANKNIFTY 2019-09-09 09:22:00  27082.45  27091.60  27071.05  27088.65      0.0
8    BANKNIFTY 2019-09-09 09:23:00  27086.65  27099.40  27081.20  27088.70      0.0
9    BANKNIFTY 2019-09-09 09:24:00  27085.45  27094.00  27079.95  27084.90      0.0
10   BANKNIFTY 2019-09-09 09:25:00  27084.90  27084.90  27070.00  27074.85      0.0
11   BANKNIFTY 2019-09-09 09:26:00  27074.85  27080.00  27070.00  27074.00      0.0
12   BANKNIFTY 2019-09-09 09:27:00  27073.05  27075.00  27065.70  27066.05      0.0
13   BANKNIFTY 2019-09-09 09:28:00  27066.05  27086.65  27062.00  27084.90      0.0
14   BANKNIFTY 2019-09-09 09:29:00  27085.45  27108.80  27080.05  27101.25      0.0
15   BANKNIFTY 2019-09-09 09:30:00  27100.00  27100.85  27076.00  27079.50   2900.0
16   BANKNIFTY 2019-09-09 09:31:00  27079.00  27114.00  27079.00  27113.95   3900.0
17   BANKNIFTY 2019-09-09 09:32:00  27110.00  27118.95  27102.70  27103.30      0.0

我想使用matplotlib在OLHCV中绘制数据,条件如下:

  1. Where Close > Open then Candle Color = Green
  2. Where Close < Open then Candle Color = Red
  3. Where Volume is Non-Zero then Candle Color = Blue
  4. Plot Volume Candle (only for non Zero Volume values) as Horizontal Lines from Right side upto the Current Candle Close Value with Volume Value written on top of the line.

任何帮助。。。你知道吗

示例输出如下: Output


Tags: the数据closedatetimevalueopensymbolwhere