简体   繁体   English

在Matplotlib图表上绘制“信号”系列

[英]Plotting a “signals” series on a Matplotlib chart

I'm making a tool for chart analysis and I have the following problem. 我正在制作图表分析工具,但遇到以下问题。 So far I have a chart which is made by the following code: 到目前为止,我有一个由以下代码制成的图表:

def makeTheChart2(self, ser1, ser2, ser3):
    ecchart.figure(2)
    ecchart.subplot(111)
    ecchart.plot(ser1,label = "Upper Band", color = "black")
    ecchart.plot(ser2, label = "Lower Band", color = "blue")
    ecchart.plot(ser3, label = "Price", color = "red")
    ecchart.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05),
      fancybox=True, shadow=True, ncol=5)
    ecchart.ylabel('Indicators evolution')
    ecchart.suptitle('Indicators', fontsize = 20)

The result is a chart showing a red line (which is a stock price) contained between an upper (black) and a lower (blue) band (sorry I cannot post the image, I'm new to Stack Overflow so I've not enough reputation yet). 结果是一张图表,显示在上(黑色)和下(蓝色)波段之间的红线(这是股票价格)(抱歉,我无法发布图像,我是Stack Overflow的新手,所以我没有足够的声誉)。

The three series that are plotted are "ser1", "ser2" and "ser3". 绘制的三个系列为“ ser1”,“ ser2”和“ ser3”。 Now, assume that I have a fourth series which is not made of float numbers, but of booleans "True and False". 现在,假设我有第四个序列,它不是由浮点数组成的,而是由布尔值“ True and False”组成的。 Specifically, the list will be "True" when the red line is crossing either the black or the blue line, "False" viceversa. 具体来说,当红线越过黑线或蓝线时,列表将为“ True”,反之则为“ False”。 Is there a way to "plot" this information, or better to add a label to the chart everytime the red line "Price" is touching/crossing one of the other two? 有没有一种方法可以“绘制”此信息,或者每当红线“价格”触及/穿越其他两个中的一个时,最好在图表上添加标签? (I guess this info would be contained into the fourth list, something like displaying a small arrow everytime the list value is True). (我想此信息将包含在第四个列表中,类似于每次列表值为True时显示一个小箭头)。

Thanks in advance. 提前致谢。

Have a look at this answer: matplotlib: Set markers for individual points on a line 看看这个答案: matplotlib:为线上的单个点设置标记

To obtain your markers_on (as it is called in the referenced answer) you could do the following: 要获取您的markers_on (在参考答案中称为),您可以执行以下操作:

>>> import numpy as np
>>> x = np.array([1,2,3,4,5])
>>> b = np.array([True,False,False,True,False]) # this is your boolean data array
>>> markers_on = x[~b]
>>> markers_on
array([2, 3, 5])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM