Hey guys I am using the following code but want to change the grid color to orange. Currently, it is making a grid over a basketball court image where the grid is black. Defining the grid color with RGB does not work:
Error Code:
line 38, in im[:,::dy,:] = grid_color ValueError: could not broadcast input array from shape (3) into shape (6720,111,4)
How can I achieve this?
import matplotlib.pyplot as plt
from PIL import Image
import pylab as pl
img = Image.open('PATH_TO_IMAGE')
im = pl.imread('PATH_TO_IMAGE')
width, height = img.size
newh = height/2
neww = width/2
print(newh)
print(neww)
dx, dy = int(newh/30), int(neww/55)
print(dx)
print(dy)
#this is not working
#grid_color = (255,165,0)
# im[0,height,dx] = grid_color
# img[:,0:width:dy] = grid_color
#this is where I determine the grid but I dont know the value for orange
im[:,::dy,:] = -1500
im[::dx,:,:] = -1500
# Show the result
plt.imshow(im, extent =[0,110,0,60] )
plt.show()
Based on the shape of im
, it seems like you have an RGBA image. Try adding the fourth element, alpha, to your grid_color
:
grid_color = (255, 165, 0, 255)
im[:, ::dy, :] = grid_color
im[::dx, :, :] = grid_color
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments