I've created a map and I am reading in a CSV of latitude and longitude coordinates into a Pandas DataFrame. I've been successful in plotting multiple great arcs using a 'for' loop after reading in the DataFrame.
A new great arc is drawn when a new set of coordinates is ADDED to the CSV.
However, I can't figure out how to REMOVE a great arc once the coordinates have been removed. The line just stays on the map.
How do I remove all the old lines and re-draw the lines everytime the CSV is updated? I only want to see the lines currently contained within the CS.
The CSV contains the following:
sourcelon sourcelat destlon destlat
50.44 30.51 -80.84 35.22
52.52 13.4 -80.84 35.22
43.18 -22.97 -80.84 35.22
44.1 -15.97 -80.84 35.22
55.44 30.51 -80.84 35.22
The minimal code is below:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import matplotlib.animation
# setup mercator map projection.
fig = plt.figure(figsize=(27, 20))
m = Basemap(projection='mill', lon_0=0)
m.drawcoastlines(color='r', linewidth=1.0)
def animate(i):
df = pd.read_csv('c:/python/scripts/test2.csv', sep='\s*,\s*',header=0, encoding='ascii', engine='python'); df
for x,y,z,w in zip(df['sourcelon'], df['sourcelat'], df['destlon'], df['destlat']):
line, = m.drawgreatcircle(x,y,z,w,color='r')
ani = matplotlib.animation.FuncAnimation(fig, animate, interval=1000)
plt.tight_layout()
plt.show()
Using blitting:
When using blitting the lines are automatically removed.
Without blitting:
If blitting is not desired, one may remove the lines manually.