gpt4 book ai didi

python - 二维图重叠圆圈并随时间演变

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:44 25 4
gpt4 key购买 nike

我正在巴黎开展一个有关 Velib 发行版的项目。对于那些不知道 Velib 的人来说,这是一个可以在车站租自行车的项目。巴黎各地大约有2000个(真实值为lR0)个车站。不幸的是,有时没有任何 Velib 可供出租,也没有任何地方可以放置您的 Velib,所以这很烦人。我想说明一下这个问题。

为此,我计算了平均占用百分比 Bary_tauxR/2 的圈子里直径。如果Bary_taux < T我想在 map 上画一个圆(红色)(我有圆心的经度和纬度,并且我有大约 100 个 T_moy 遍布巴黎的值),一次链接到 t

事情变得复杂的是,我在 192 个给定时间(每 10 分钟 - 24 小时)有这 100 个值,我想制作一个可以随时间演变的图,显示红色圆圈的演变。

一次性t ,我可以画它,但我不知道如何随着时间的变化而进化。

此外,我想让红色随着重叠圆圈数量的增加而变得更强。

这是我的Bary_taux功能:

def Bary_taux(lng_0,lat_0,R):
T_Bary=0
C=0

for k in range(lR0):
if (((R_0[k]['position']['lng'])-lng_0)**2)+(((R_0[k['position']['lat'])-lat_0)**2)<R**2:
C+=1
T_bary+=Taux(k)

return (lng_0,lat_0,R,T_bary/C)

BBary_taux 的列表在给定时间 t。我有192 B列出每个包含 100 Bary_taux 。这是我到目前为止所拥有的:

import matplotlib.pyplot as plt

for k in range (100):
if B[k]<T:

circle1 = plt.Circle((, 0), R, color='r')


fig, ax = plt.subplots()


plt.show()

我该怎么做?感谢您的宝贵时间。

最佳答案

为了在 matplotlib 中对绘图进行动画处理,您可以使用 matplotlib.animate.FuncAnimation。这将需要一个函数来为每个帧调用。如果我们之前创建了所有 100 个圆圈,我们可以使用此更新函数根据某些参数将它们设置为可见。我不确定我是否正确理解了您的 bary_tauxB。所以我自己发明了一些数字。

import matplotlib.pyplot as plt
import matplotlib.patches
import matplotlib.animation
import numpy as np
import datetime



x = np.random.randint(0,180, size=100) # xcoordinate
y = np.random.randint(0,100, size=100) # ycoordinate
R = np.random.randint(3,10, size=100) # radius
b = np.random.rand(192,100) # parameter by which to judge if circle is drawn or not

# set up plot
fig, ax = plt.subplots()
ax.set_xlim([0,180])
ax.set_ylim([0,100])
ax.set_aspect("equal")
text = ax.text(0.5,1.02, "", transform=ax.transAxes, ha="right" )

#create 100 circles
circles = []
for i in range(100):
c = matplotlib.patches.Circle((x[i],y[i]), radius=R[i], color="r", alpha=0.6)
circles.append(c)
# add them already to the plot
ax.add_artist(c)

def totime(t):
minutes = datetime.timedelta(seconds=t*10*60 )
d = datetime.datetime(1,1,1) + minutes
return "{}h{:2d}".format(d.hour, d.minute)

def update(t):
text.set_text(totime(t))
for i in range(100):
# depending on condition set circle visible or not
if b[t,i] > 0.6:
circles[i].set_visible(True)
else:
circles[i].set_visible(False)
# redraw the canvas
fig.canvas.draw()

# call for single plot
update(92)
#call for animation
ani = matplotlib.animation.FuncAnimation(fig, update, interval=300, frames=192)


plt.show()

关于python - 二维图重叠圆圈并随时间演变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41225505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com