不显示半圆并发送一条消息,说明“将输入数据剪切为有效范围以显示带RGB数据的imshow(浮点数为[0..1],整数为[0..255]) 。”
我的代码是这样的:
import math
import numpy as np
import matplotlib.pyplot as plt
new_image = np.zeros((300, 250, 3))
for x in range(300):
for y in range(250):
if (180 <= x <= 240) and (100 <= y <=200):
new_image[x, y , 2] = 255
elif (90 <= x <= 150) and ((-2*x/3)+110 <= y <= (2*x/3)-10):
new_image[x,y,0] = 255
elif (60 <= x <=120) and (150 <= y <= 200+math.sqrt(900-(x-90)^2)):
new_image[x,y,0] = 255
new_image[x,y,1] = 255
else:
new_image[x,y,0] = 255
new_image[x,y,1] = 255
new_image[x,y,2] = 255
# First Plot
plt.figure()
plt.imshow(new_image)
plt.axis('off')
plt.show()
答案 0 :(得分:2)
在您的情况下,new_image是一个浮点数数组,但是当您分配颜色值时,您需要给出0到1之间的值,但是您给出的是255,它是一个整数。
您可以将int(0-255)设置为颜色值,但图像数组应由int组成。
因此您可以使用
来消除错误new_image = np.zeros((300, 250, 3), dtype = int)