how to remove grid lines on image in python?

18,152

Solution 1

Apparently something in the background changes the style. I have no experience whatsoever with google colab ti judge whether this can be responsible for the observed difference in displayed image.

In any case it should be possible to manually turn the grid lines off on a per notebook basis.

%matplotlib inline
from matplotlib import pyplot as plt
plt.rcParams["axes.grid"] = False

# rest of code

Solution 2

plt.imshow(myImage)
plt.grid(None)   <---- this should remove that white grid
Share:
18,152

Related videos on Youtube

Karan Purohit
Author by

Karan Purohit

Updated on October 09, 2022

Comments

  • Karan Purohit
    Karan Purohit over 1 year

    I am using google colab for my project. I am getting grid lines on images even I am not writing them.

    from matplotlib import pyplot as plt
    %matplotlib inline
    import cv2
    
    img = cv2.imread('k15.jpg')
    
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    
    plt.imshow(img)
    

    enter image description here

    for code like above, I am getting grid lines which is not the case when I run the same code in my python shell.

  • python Jocker
    python Jocker almost 6 years
    When you open it in PIL you need to provide the entirety of the image's path
  • Karan Purohit
    Karan Purohit almost 6 years
    there is no path as I am using it on google colab. also, same script is working fine on local python shell.
  • Karan Purohit
    Karan Purohit almost 6 years
    That's finally solved my problem. I was looking for somehow to stop this but couldn't find any. Thanks!!
  • kawingkelvin
    kawingkelvin over 3 years
    Actually, plt.grid() will also remove the grid, so dont have to even type 'None'