>>> from datetime import datetime
>>> import matplotlib.pyplot as plt
>>> import asilib
>>> import asilib.asi
>>>
>>> location = 'FSMI'
>>> time_range = (datetime(2015, 3, 26, 6, 7), datetime(2015, 3, 26, 6, 12))
>>> asi = asilib.asi.themis(location, time_range=time_range)
>>> ax = asilib.map.create_map(lon_bounds=(-120, -100), lat_bounds=(55, 65))
>>> plt.tight_layout()
>>>
>>> gen = asi.animate_map_gen(overwrite=True, ax=ax)
>>>
>>> for image_time, image, ax, im in gen:
>>> # Add your code that modifies each image here...
>>> # To demonstrate, lets annotate each frame with the timestamp.
>>> # We will need to delete the prior text object, otherwise the current one
>>> # will overplot on the prior one---clean up after yourself!
>>> if 'text_obj' in locals():
>>> ax.texts.remove(text_obj)
>>> text_obj = ax.text(0, 0.9, f'THEMIS-{location} at {image_time:%F %T}',
>>> transform=ax.transAxes, color='white', fontsize=15)
>>>
>>> print(f'Animation saved in {asilib.config["ASI_DATA_DIR"] / "animations" / asi.animation_name}')
Calling animate_map_gen() returns 4 objects: a datetime.datetime of the current image, an ndarray corresponding to the image pixels, an plt.Axes object corresponding to the axis where the image is plotted, and a plt.Imshow object to add colorbars and so on.
Calling an extra scatterplot, like ax.scatterplot(x,y,c=z) where x and y are array-like objects of longitudes and latitudes and z is a quantity I want to plot, results in a singular spot being plotted on the image, even when x,y,z have more than one element. Why is this happening and is there a workaround?
To reproduce this issue, you can run the following code:
from datetime import datetime
import matplotlib.pyplot as plt
import asilib
import asilib.asi
# Sample Data
latitudes = [60, 61, 62]
longitudes = [-110, -111, -112]
values = [10, 20, 30]
# Configuration for the map
location = 'FSMI'
time_range = (datetime(2015, 3, 26, 6, 7), datetime(2015, 3, 26, 6, 12))
asi = asilib.asi.themis(location, time_range=time_range)
ax = asilib.map.create_map(lon_bounds=(-120, -100), lat_bounds=(55, 65))
plt.tight_layout()
# Generate the animation frames
gen = asi.animate_map_gen(overwrite=True, ax=ax)
text_obj = None # Initialize text_obj outside the loop
for image_time, image, ax, im in gen:
# Add scatter plot on each frame
scatter_plot = ax.scatter(longitudes, latitudes, c=values, cmap='viridis', s=100)
# Example of adding time-stamped annotations
if text_obj:
text_obj.remove() # Remove the previous text object from the axes
text_obj = ax.text(0, 0.9, f'THEMIS-{location} at {image_time:%F %T}',
transform=ax.transAxes, color='white', fontsize=15)
# Save the final animation
print(f'Animation saved in {asilib.config["ASI_DATA_DIR"] / "animations" / asi.animation_name}')
Calling animate_map_gen() returns 4 objects: a
datetime.datetime
of the current image, anndarray
corresponding to the image pixels, anplt.Axes
object corresponding to the axis where the image is plotted, and aplt.Imshow
object to add colorbars and so on.Calling an extra scatterplot, like
ax.scatterplot(x,y,c=z)
wherex
andy
are array-like objects of longitudes and latitudes andz
is a quantity I want to plot, results in a singular spot being plotted on the image, even whenx,y,z
have more than one element. Why is this happening and is there a workaround?To reproduce this issue, you can run the following code:
and the result is