Unwanted white "grid" lines using axvline

Question:

I have the following code:

for df in dfs:
    
    plt.plot(df['Digital'], lw=5, label='A', zorder=2)
    plt.plot(df['Analog'], lw=2, linestyle='--', label='B', zorder=2)
    
    for rowNr in np.arange(len(df)):
        if df.iloc[rowNr]['Analog'] >= 0:
            plt.axvline(df.index[rowNr], ymin=0.08, color='gray', alpha=0.3, zorder=1)

    plt.ylim(-2, 25)

This gives me the following result:

Results

I want to get rid of all the vertical white "grid" lines. I tried using axvspan(), but got the same result. Setting plt.grid() to False actually turned it on and showed that it is not the real grid lines that can be seen.
Maybe it is somehow connected to the low alpha value, since setting alpha to 1 removes these lines?

TLDR: I want to get rid of all the vertical white lines.

Asked By: racctor

||

Answers:

A little lack of context here, but it seems like the white vertical lines you observe actually come from the spaces between all the plotted gray axvlines.

Maybe it is somehow connected to the low alpha value, since setting alpha to 1 removes these lines?

Setting the color to a lighter gray (e.g color="lightgray") with an alpha value of 1 might do the trick then. See the list of matplotlib named colors

Answered By: thmlsmr