我遇到了同样的问题,但是遮罩消除了两者之间的点,并且线条被切割(我们在图片中看到的粉红色线条是唯一不是连续的 NaN 数据,这就是线条的原因)。这是屏蔽数据的结果(仍然有差距):
xs  = df['time'].to_numpy()
series1 = np.array(df['zz'].to_numpy()).astype(np.double)
s1mask = np.isfinite(series1)
fplt.plot(xs[s1mask], series1[s1mask], ax=ax_candle, color='#FF00FF', width = 1, legend='ZZ')

也许是因为我使用 finplot(绘制蜡烛图),所以我决定用线性公式 y2-y1=m(x2-x1) 制作缺少的 Y 轴点,然后制定生成 Y 值的函数缺失点之间。
def fillYLine(y):
    #Line Formula
    fi=0
    first = None
    next = None
    for i in range(0,len(y),1):
        ne = not(isnan(y[i]))
        next = y[i] if ne else next
    
        if not(next is None):
            if not(first is None):
                m = (first-next)/(i-fi) #m = y1 - y2 / x1 - x2
                cant_points = np.abs(i-fi)-1
                if (cant_points)>0:
                    points = createLine(next,first,i,fi,cant_points)#Create the line with the values of the difference to generate the points x that we need    
                    x = 1
                    for p in points:
                        y[fi+x] = p
                        x = x + 1
            first = next
            fi = i
        next = None
    return y
def createLine(y2,y1,x2,x1,cant_points):
    m = (y2-y1)/(x2-x1) #Pendiente
    points = []
    x = x1 + 1#first point to assign
    for i in range(0,cant_points,1):
        y = ((m*(x2-x))-y2)*-1
        points.append(y)
        x = x + 1#The values of the line are numeric we don´t use the time to assign them, but we will do it at the same order
    return points
然后我使用简单的调用函数来填补 like 之间的空白y = fillYLine(y),我的 finplot 就像:
x = df['time'].to_numpy()
y = df['zz'].to_numpy()
y = fillYLine(y)
fplt.plot(x, y, ax=ax_candle, color='#FF00FF', width = 1, legend='ZZ')

您需要认为 Y 变量中的数据仅用于绘图,我需要操作中的 NaN 值(或从列表中删除它们),这就是我从 pandas dataset 创建一个 Y 变量的原因df['zz']。
注意:我注意到在我的情况下数据被消除了,因为如果我不屏蔽 X (xs) 值在图表中向左滑动,在这种情况下它们变为连续而不是 NaN 值,它绘制连续线但缩小到剩下:
fplt.plot(xs, series1[s1mask], ax=ax_candle, color='#FF00FF', width = 1, legend='ZZ') #No xs masking (xs[masking])

这让我觉得有些人使用蒙版的原因是因为他们只绘制那条线,或者非蒙版数据和蒙版数据之间没有太大区别(很少有差距,不像我的数据有很多)。