我希望我的循环只将“墙”内的表单元格从0更改为5。 “墙”是用户定义的,可以是基于坐标的任何形状。 这个情节只是为了形象化。你知道吗
import matplotlib.pyplot as plt
import pandas as pd
wallPointsX = [5,5,30,30,55,55,5]
wallPointsY = [5,30,30,55,55,5,5]
df = pd.DataFrame(0, index=range(60), columns=range(60))
for x in range(0, 60):
for y in range(0, 60):
df[x][y] = 5 #Should only apply inside "walls"
plt.plot(wallPointsX, wallPointsY)
plt.pcolor(df)
plt.show()
好吧,花了我一些时间,但做起来很有趣。这里的想法是首先从定义墙的坐标中创建一个连续的
path
。接下来,创建一个对象Path
。现在循环遍历数据帧中的每个点,然后使用contains_point
查看所创建的Path
是否包含该(x,y)点。此外,我还必须在if
语句中使用条件x==55 and (5<y<=55)
,以便包含与 最右边的墙。你知道吗输出
相关问题 更多 >
编程相关推荐