21

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.

2
  • The code you show is probably not the one responsible for the gridlines. Do they still appear if you start with a fresh kernel? Commented May 27, 2018 at 18:58
  • yes.I think its something related to google colab. it's weird.... Commented May 28, 2018 at 15:59

4 Answers 4

29
plt.imshow(myImage) plt.grid(None) <---- this should remove that white grid 
Sign up to request clarification or add additional context in comments.

2 Comments

Actually, plt.grid() will also remove the grid, so dont have to even type 'None'
This worked very well, until I tried adding a twin axis at the top of my plot with ax.twiny(). Now none of the methods here work anymore :(
21

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 

1 Comment

That's finally solved my problem. I was looking for somehow to stop this but couldn't find any. Thanks!!
0

If you don't mind using a different packet, you can pretty much do it easily with PIL or Pillow

from PIL import Image img = Image.open('C:\...\k15.jpg') img.show() 

3 Comments

When you open it in PIL you need to provide the entirety of the image's path
there is no path as I am using it on google colab. also, same script is working fine on local python shell.
@KaranPurohit You can show files, then right click on the image file and choose Copy path.
0

The above answer didn't work for me in an Jupyter Notebook. Here is an alternative solution - after every imshow you need to disable the grid like this:

... plt.imshow(image) plt.grid(False) ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.