Skip to content Skip to sidebar Skip to footer

How To Remove A Particular Grid Line Corresponding To A Custom Xtick On A Log Scale Axis?

I'd like to remove the vertical grid line corresponding to the custom xtick (displayed at x = 71 in the below picture). I could remove a horizontal grid line corresponding to the y

Solution 1:

Credit for the idea goes to @ImportanceOfBeingErnest to whom I am extremely grateful.

I removed the grid with

axes.xaxis.grid(False, which='both')

, then I added a grid correspond to each xtick except the custom one with the following loop:

for loc in locs[1:-1]:
    if loc != x_data[np.argmax(y_data)]:
        plt.axvline(x=loc, color = 'grey', linestyle = '-', linewidth = 0.4)                                                                                                            

Insert this code just before the line

plt.xticks(locs, labels) # updates the xticks and labels.  

Example of output picture below. no problem now.

Post a Comment for "How To Remove A Particular Grid Line Corresponding To A Custom Xtick On A Log Scale Axis?"