Home > Software engineering >  Matplotlib: How to use two colors in a single line?
Matplotlib: How to use two colors in a single line?

Time:10-21

I am getting a list of close data which is both negative and positive. When I plot a line I want to show positive value as a green segment and negative value as a red segment. I have data in the following df format:

                                A       price     B         side  size  signal  \
time                                                                            
2019-06-12 03:54:26.668990  4603.35936  7990.0  4583.96620  Buy    20    True   
2019-06-12 03:54:26.668990  4603.24884  7990.0  4583.96620  Buy    38    True   
2019-06-12 03:54:26.668990  4603.26808  7990.0  4583.96620  Buy    69    True   
2019-06-12 03:54:26.668990  4603.32670  7990.0  4583.96620  Buy    25    True   
2019-06-12 03:54:26.668990  4603.32670  7990.0  4583.96620  Buy   450    True   
...                                ...     ...         ...  ...   ...     ...   
2019-06-12 12:07:48.793863  3997.85136  8043.5  4375.44562  Buy    22   False   
2019-06-12 12:07:48.793863  3997.87648  8044.0  4375.44562  Buy  1300   False   
2019-06-12 12:07:48.793863  3997.87616  8044.0  4375.44562  Buy     6   False   
2019-06-12 12:07:48.793863  3997.89530  8044.0  4375.44562  Buy  1000   False   
2019-06-12 12:07:48.793863  3997.90046  8044.0  4375.44562  Buy   280   False

If the signal is True show green else red. I found enter image description here

  • Related