이미지 위에 지리 좌표 플롯을 애니메이션화하려고합니다.이 경우에는지도의 일부입니다. 정적 플롯을 생성했지만 애니메이션으로 만들 수 없습니다. matplotlib 애니메이션 기능을 사용하여 애니메이션을 적용하려고했지만 성공하지 못했습니다. pandas를 사용하여 csv를 Python으로 읽고 matplotlib.pyplot을 플롯합니다. 다음은 정적 플롯에 대한 코드입니다.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('mydata.csv', header=0)
# find max/min, plug into a website, snip area as png and insert as plotmap
BBox = ((df.LONGITUDE.min(), df.LONGITUDE.max(),
df.LATITUDE.min(), df.LATITUDE.max()))
#read the image in, plot points over image
plotmap = "myimage.png"
truthplot = plt.imread(plotmap)
fig, ax = plt.subplots(figsize = (8,8),linewidth = 0.1)
ax.scatter(df.LONGITUDE, df.LATITUDE, zorder=1, alpha= 0.5, c='b', s=10)
plottitle = "test"
ax.set_title(plottitle)
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.set_xlim(BBox[0], BBox[1])
ax.set_ylim(BBox[2], BBox[3])
ax.imshow(truthplot, zorder=0, extent = BBox, aspect= 'equal')
plt.show()
몇 가지 예 좌표 :
LATITUDE LONGITUDE
30.112342 10.678982
29.443459 11.678997
29.334221 11.889544
28.993448 12.003847
나는 아직 초보자입니다. 어떤 도움을 주시면 감사하겠습니다.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
df = pd.read_csv('mydata.csv', header=0)
# find max/min, plug into a website, snip area as png and insert as plotmap
BBox = ((df.LONGITUDE.min(), df.LONGITUDE.max(),
df.LATITUDE.min(), df.LATITUDE.max()))
#read the image in, plot points over image
plotmap = "myimage.png"
truthplot = plt.imread(plotmap)
fig, ax = plt.subplots(figsize = (8,8),linewidth = 0.1)
plottitle = "test"
ax.set_title(plottitle)
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.set_xlim(BBox[0], BBox[1])
ax.set_ylim(BBox[2], BBox[3])
scat = ax.scatter(df.LONGITUDE, df.LATITUDE, zorder=1, alpha= 0.5, c='b', s=10)
color_data = np.random.random((500, len(df.LATITUDE)))
def update(frame):
scat.set_array(color_data[frame])
return scat,
ani = FuncAnimation(fig, update, frames=range(500), blit=True)
ax.imshow(truthplot, zorder=0, extent = BBox, aspect= 'equal')
plt.show()
무엇을 애니메이션화하고 싶었는지 잘 모르겠습니다. 그래서 포인트를 깜박이게했습니다. 그러나 업데이트 기능에서 원하는 모든 산점도를 쉽게 변경할 수 있습니다. scat
PathCollection이며 여기에서 해당 기능을 찾을 수 있습니다. https://matplotlib.org/3.2.1/api/collections_api.html#matplotlib.collections.PathCollection
단계별로 경로를 작성하려는 경우 PathCollention을 조작하는 것은 그리 편리하지 않습니다. obj를 다시 만드는 것이 좋습니다.
scat = ax.scatter(df.LONGITUDE[0], df.LATITUDE[0], zorder=1, alpha= 0.5, c='b', s=10)
max_frames = 10
def update(frame):
scat = ax.scatter(df.LONGITUDE[:(frame * (len(df.LONGITUDE) + 1))//max_frames],
df.LATITUDE[:(frame * (len(df.LATITUDE) + 1))//max_frames],
zorder=1, alpha= 0.5, c='b', s=10)
return scat,
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다