I have been struggling since last week to make polygons appearing/disappearing in an animation. I read through x times the manual pages, searched the forum, tried to find examples … to no avail so far. Except for one example in the Forum with exploration permits off Norway, but it is based on a complex SQL data base.
I set one polygon file with absolute time tags -Tbegin,end in the segment headers and a second polygon file with absolute time tag and duration -Tbegin/duration in the segment headers. And then used events with the following options and flags:
gmt events -As polygon1.txt -Lt -Lt -Es+r2+f2 -W1,blue -G200 -T$MOVIE_COL0 --TIME_UNIT=m
gmt events -As polygon2.txt -L5m -Es+r1+f5 -Ms3+c1.1 -Mi1+c0 -Mt+c0 -W1,blue -G150 -T$MOVIE_COL0 --TIME_UNIT=m
Polygons within polygon1 never pop up
Polygons within polygon2 appear from start to end of the animation
I tried many combinations and flags for -L and -E, -M, but generally nothing shows up, without “events” and “movie” complaining. I also tried single-segment files, no better. So I am obviously doing something wrong, likely to be trivial but …
The attached script is extracted from a more complex one with a map and graph, with many appearing/disappearing symbols and lines, which works fine. Just these polygons I can’t figure out.
Also enclosed, the two multi-segment polygon files I practiced on.
Thanks for your help.
Run from a Unix bash shell on a Mac with GMT6.5 (default units in SI)
———————————————————————
I am not sure what is your problem but I hope this script will help you. It seems that it has an small bug (in the movie that is created with my script).
Thanks Frederico for this working example. At least, it shows that polygons can popup in an animation. But I still need to figure out how to make it work with absolute time tags. I’ll continue digging and post the solution.
Following @Esteban82 I converted the absolute times of appearance and disappearance of the polygons in Unix seconds, in the polygon files, and they popup or vanish as desired.
If there is more than 1 polygon in the file, it reproduces the bug noticed by @Esteban82 : the first apex of the first polygon start moving towards the next appearing polygon in the file. Bug or feature, I let you decide.
Here is a working script (it includes the polygons), so you can see by yourself.
Run from a Unix bash shell on a Mac with GMT6.5 (default units in SI)
——————————
#!/bin/bash
# Plot polygons with different lifetimes in a movie/animation
# The 1st set of polygons pops up in different time windows
# The 2nd set of polygons shows up at different times and lasts a given duration (in seconds)
# For some reasons, polygons don't show up if the absolute times are given in ISO-8601 format,
# hence their conversion in Unix seconds
# The way the time table is constructed in the movie has, however, no effect on the outcome.
#
# A strange bug shows up when there is more than 1 polygon in a file
poly1=timed_polygons1.txt
t1=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T20:02:00 +"%s"`
t2=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T20:20:00 +"%s"`
t3=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T20:30:00 +"%s"`
t4=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T20:55:00 +"%s"`
cat > $poly1 << EOF
> Polygon -T$t1/$t2 -W1,black -G200
2 3
4 5
6 1
2 3
> Polygon -T$t3,$t4 -W1,green -G200
6 7
8 9
10 5
6 7
EOF
t1=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T21:07:00 +"%s"`
t2=`date -juf "%Y-%m-%dT%H:%M:%S" 2025-04-26T21:21:00 +"%s"`
poly2=timed_polygons2.txt
cat > $poly2 << EOF
> Polygon -T$t1/300 -W1,red -G150
1 8
3 8
2 6
1 7
1 8
> Polygon -T$t2/400 -W1,blue -G150
9 2
10 3
11 2
10 1
9 2
EOF
window=2025-04-26T20:00:00/2025-04-26T21:30:00 #--- Test
#------------------------------- Common parameters ----------------------------------------
cat > inc.sh << EOF
poly1=$poly1
poly2=$poly2
window=$window
map_offset="-X0.5 -Y0.5"
frame=0/12/0/9
proj=x1
EOF
#----------------------------- Common background slide ------------------------------
cat << 'EOF' > pre.sh
gmt begin
printf "pre: -R$frame -J$proj\n"
gmt basemap -R$frame -J$proj -Ba1 $map_offset
gmt end
EOF
#--------------------------- Animated slides ----------------------------------------
# -Es+r2+d6 r:raise phase of 2u, d:decay phase of 6u u=time=unit
# -Ms5+c0.5 s:magnify symbol 5 times then reduce it to 0.5
# -Mi1+c-0.6 i:reduce intensity from 1 [default] to -0.6
# -Mt+c0 t:change transparency to 0
cat << 'EOF' > main.sh
gmt begin
printf "\rmain: -T$MOVIE_COL0 "
gmt basemap -R$frame -J$proj -B+n $map_offset
gmt events -R$frame -J$proj -As $poly1 -Lt -Es+r1+f5 -T$MOVIE_COL0
gmt events -R$frame -J$proj -As $poly2 -L -Es -T$MOVIE_COL0
gmt end
EOF
#------------------------ Time/animation progression --------------------------------
echo "------- Start animation ---------"
progress=-Pa+jTL+w.6+o5.5/0.125c+Gwhite+gblue
#gmt math -T$window/1m -o0 T = time_list.txt
#gmt movie main.sh -Iinc.sh -Sbpre.sh -C13.5x10.5x80 -D4 -Zs -Ttime_list.txt -NAnim_cont_simple -Fmp4 -V
gmt movie main.sh -Iinc.sh -Sbpre.sh -C13.5x10.5x80 -D4 -Zs -T$window/1m -NAnim_cont_simple -Fmp4 -M50,pdf+v \
--FORMAT_CLOCK_MAP=hh:mm --FORMAT_DATE_MAP="o dd" \
$progress -Lc0+o0.5/0.2 --FONT_TAG=18p,Helvetica,red
rm -f $poly1 $poly2 time_list.txt