Skip to content

Commit 20e10b8

Browse files
committed
#5 Work in progress:
- Improve expert_plot method - Merge matplotlib_plot and basemap_plot methods - Create matplotlib_animation method [ci skip]
1 parent 778eb65 commit 20e10b8

File tree

9 files changed

+660
-401
lines changed

9 files changed

+660
-401
lines changed

docs/tutorials/plotting.rst

+123-39
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,49 @@
11
Plotting
22
--------
33

4-
ezGPX currently provides four different ways to plot a :py:class:`~ezgpx.gpx.GPX` object.
4+
ezGPX currently provides many different ways to plot a :py:class:`~ezgpx.gpx.GPX` object.
55

66
Matplotlib
77
^^^^^^^^^^
88

9+
This method relies on the well known Matplotlib Python library to create simple yet useable plots of GPX files.
10+
11+
.. warning:: Requires :py:mod:`~basemap`.
12+
913
::
1014

1115
import ezgpx
16+
import matplotlib as mpl
1217

1318
# Parse GPX file
1419
gpx = ezgpx.GPX("file.gpx")
1520

1621
# Plot with Matplotlib
17-
gpx.matplotlib_plot(color="elevation",
18-
start_stop_colors=("green", "red"),
19-
way_points_color="blue",
22+
gpx.matplotlib_plot(figsize=(16,9),
23+
size=5,
24+
color="ele",
25+
cmap=mpl.cm.get_cmap("viridis", 12),
26+
colorbar=False,
27+
start_point_color="green",
28+
stop_point_color="red",
29+
way_points_color=None,
30+
background="World_Imagery",
31+
offset_percentage=0.04,
32+
dpi=100,
2033
title=gpx.name(),
21-
duration=(0, 0),
22-
distance=(0.5, 0),
23-
ascent=(1, 0),
24-
pace=None,
25-
speed=None,
26-
file_path="img")
34+
title_fontsize=20,
35+
watermark=True,
36+
file_path="img.png")
2737

2838
.. image:: ../../img/matplotlib_plot_1.png
2939
:width: 500
3040
:alt: Matplotlib plot
3141

32-
Matplotlib Basemap Toolkit
33-
^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
35-
::
36-
37-
import ezgpx
38-
39-
# Parse GPX file
40-
gpx = ezgpx.GPX("file.gpx")
41-
42-
# Plot with Matplotlib Basemap Toolkit
43-
gpx.matplotlib_basemap_plot(color="darkorange",
44-
start_stop_colors=("darkgreen", "darkred"),
45-
way_points_color="darkblue",
46-
title=gpx.name(),
47-
duration=(0,0),
48-
distance=(0.5,0),
49-
ascent=None,
50-
pace=None,
51-
speed=(1,0),
52-
file_path="img")
53-
54-
.. image:: ../../img/matplotlib_basemap_plot_1.png
55-
:width: 500
56-
:alt: Matplotlib Basemap Toolkit plot
57-
5842
gmplot
5943
^^^^^^
6044

45+
This method uses the Google map engine to display the content of the GPX file in a HTML page.
46+
6147
.. warning:: Requires :py:mod:`~gmplot`.
6248

6349
::
@@ -83,6 +69,8 @@ gmplot
8369
Folium
8470
^^^^^^
8571

72+
The interactive HTML page resulting from this method allows you to visualize the content of a GPX on a nice looking map.
73+
8674
.. warning:: Requires :py:mod:`~folium`.
8775

8876
::
@@ -109,7 +97,7 @@ Folium
10997
:alt: Folium plot
11098

11199
PaperMap
112-
^^^^^^
100+
^^^^^^^^
113101

114102
.. warning:: Requires :py:mod:`~papermap`.
115103

@@ -120,16 +108,112 @@ PaperMap
120108
# Parse GPX file
121109
gpx = ezgpx.GPX("file.gpx")
122110

123-
# Plot with Folium
111+
# Plot with Papermap
124112
gpx.papermap_plot(tile_server="OpenStreetMap",
125113
size = "a4",
126114
use_landscape = True,
127115
scale = 25000,
128116
dpi = 300,
129117
add_grid = True,
130118
grid_size = 1000,
131-
file_path = "map.pdf"):
119+
file_path = "map.pdf")
132120

133121
.. image:: ../../img/papermap_plot_1.png
122+
:width: 500
123+
:alt: PaperMap plot
124+
125+
Expert Plot
126+
^^^^^^^^^^^
127+
128+
This method creates animations of the activity contained in a GPX file.
129+
130+
.. warning:: Requires :py:mod:`~basemap`.
131+
132+
::
133+
134+
import ezgpx
135+
136+
# Parse GPX file
137+
gpx = ezgpx.GPX("file.gpx")
138+
139+
# Create animation with Matplotlib
140+
gpx.matplotlib_animation(figsize=(16,9),
141+
size=4,
142+
color="red",
143+
cmap=None,
144+
colorbar=False,
145+
start_point_color=None,
146+
stop_point_color=None,
147+
way_points_color=None,
148+
background="World_Imagery",
149+
offset_percentage=0.04,
150+
dpi=200,
151+
interval=10,
152+
fps=24,
153+
repeat=False,
154+
title=gpx.name(),
155+
title_fontsize=15,
156+
watermark=True,
157+
file_path="video_1.mp4")
158+
159+
Expert Plot
160+
^^^^^^^^^^^
161+
162+
This is the most advanced plotting method built into ezGPX. It allows to plot the path with or without a background map, the elevation profile, the pace profile and other relevant data related to the GPX file as tables or graphs.
163+
164+
.. warning:: Requires :py:mod:`~basemap`.
165+
166+
::
167+
168+
import ezgpx
169+
170+
# Parse GPX file
171+
gpx = ezgpx.GPX("file.gpx")
172+
173+
# Expert plot
174+
gpx.expert_plot(figsize=(16,9),
175+
subplots=(3,2),
176+
map_position=(0,0),
177+
map_size=10,
178+
map_color="ele",
179+
map_cmap=matplotlib.cm.get_cmap("viridis", 12),
180+
map_colorbar=True,
181+
start_point_color=None,
182+
stop_point_color=None,
183+
way_points_color=None,
184+
background="World_Imagery",
185+
offset_percentage=0.04,
186+
xpixels=1000,
187+
ypixels=None,
188+
dpi=100,
189+
elevation_profile_position=(1,0),
190+
elevation_profile_size=10,
191+
elevation_profile_color="ele",
192+
elevation_profile_cmap=matplotlib.cm.get_cmap("viridis", 12),
193+
elevation_profile_colorbar=False,
194+
elevation_profile_grid=True,
195+
elevation_profile_fill_color="lightgray",
196+
elevation_profile_fill_alpha=0.5,
197+
pace_graph_position=(2,0),
198+
pace_graph_size=10,
199+
pace_graph_color="ele",
200+
pace_graph_cmap=None,
201+
pace_graph_colorbar=False,
202+
pace_graph_grid=True,
203+
pace_graph_fill_color="lightgray",
204+
pace_graph_fill_alpha=0.5,
205+
pace_graph_threshold=15,
206+
ascent_rate_graph_position=(1,1),
207+
made_with_ezgpx_position=(0,1),
208+
shared_color="ele",
209+
shared_cmap=None,
210+
shared_colorbar=True,
211+
data_table_position=(2,1),
212+
title=test_gpx.name(),
213+
title_fontsize=20,
214+
watermark=False,
215+
file_path="img.png")
216+
217+
.. image:: ../../img/expert_plot_1.png
134218
:width: 500
135219
:alt: PaperMap plot

examples/plot.py

+87-22
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
import ezgpx
2+
import matplotlib as mpl
23

34
# Parse GPX file
45
gpx = ezgpx.GPX("file.gpx")
56

67
# Plot with Matplotlib
7-
gpx.matplotlib_plot(color="elevation",
8-
start_stop_colors=("green", "red"),
9-
way_points_color="blue",
8+
gpx.matplotlib_plot(figsize=(16,9),
9+
size=5,
10+
color="ele",
11+
cmap=mpl.cm.get_cmap("viridis", 12),
12+
colorbar=False,
13+
start_point_color="green",
14+
stop_point_color="red",
15+
way_points_color=None,
16+
background="World_Imagery",
17+
offset_percentage=0.04,
18+
dpi=100,
1019
title=gpx.name(),
11-
duration=(0, 0),
12-
distance=(0.5, 0),
13-
ascent=None,
14-
pace=(1, 0),
15-
speed=None,
20+
title_fontsize=20,
21+
watermark=True,
1622
file_path="img_1")
1723

18-
# Plot with Matplotlib Basemap Toolkit
19-
gpx.matplotlib_basemap_plot(color="darkorange",
20-
start_stop_colors=("darkgreen", "darkred"),
21-
way_points_color="darkblue",
22-
title=gpx.name(),
23-
duration=(0,0),
24-
distance=(0.5,0),
25-
ascent=None,
26-
pace=None,
27-
speed=(1,0),
28-
file_path="img_2")
29-
3024
# Plot with gmplot (Google Maps)
3125
gpx.gmplot_plot(color="yellow",
3226
start_stop_colors=("green", "red"),
@@ -48,5 +42,76 @@
4842
file_path="map_2.html",
4943
open=True)
5044

51-
# Write new GPX file
52-
gpx.to_gpx("new_file.gpx")
45+
# Plot with Papermap
46+
gpx.papermap_plot(tile_server="OpenStreetMap",
47+
size = "a4",
48+
use_landscape = True,
49+
scale = 25000,
50+
dpi = 300,
51+
add_grid = True,
52+
grid_size = 1000,
53+
file_path = "map_1.pdf")
54+
55+
# Expert plot
56+
gpx.expert_plot(figsize=(16,9),
57+
subplots=(3,2),
58+
map_position=(0,0),
59+
map_size=10,
60+
map_color="ele",
61+
map_cmap=mpl.cm.get_cmap("viridis", 12),
62+
map_colorbar=True,
63+
start_point_color=None,
64+
stop_point_color=None,
65+
way_points_color=None,
66+
background="World_Imagery",
67+
offset_percentage=0.04,
68+
xpixels=1000,
69+
ypixels=None,
70+
dpi=100,
71+
elevation_profile_position=(1,0),
72+
elevation_profile_size=10,
73+
elevation_profile_color="ele",
74+
elevation_profile_cmap=mpl.cm.get_cmap("viridis", 12),
75+
elevation_profile_colorbar=False,
76+
elevation_profile_grid=True,
77+
elevation_profile_fill_color="lightgray",
78+
elevation_profile_fill_alpha=0.5,
79+
pace_graph_position=(2,0),
80+
pace_graph_size=10,
81+
pace_graph_color="ele",
82+
pace_graph_cmap=None,
83+
pace_graph_colorbar=False,
84+
pace_graph_grid=True,
85+
pace_graph_fill_color="lightgray",
86+
pace_graph_fill_alpha=0.5,
87+
pace_graph_threshold=15,
88+
ascent_rate_graph_position=(1,1),
89+
made_with_ezgpx_position=(0,1),
90+
shared_color="ele",
91+
shared_cmap=None,
92+
shared_colorbar=True,
93+
data_table_position=(2,1),
94+
title=gpx.name(),
95+
title_fontsize=20,
96+
watermark=False,
97+
file_path="img_2.png")
98+
99+
100+
gpx.matplotlib_animation(figsize=(16,9),
101+
size=4,
102+
color="red",
103+
cmap=None,
104+
colorbar=False,
105+
start_point_color=None,
106+
stop_point_color=None,
107+
way_points_color=None,
108+
background="World_Imagery",
109+
offset_percentage=0.04,
110+
dpi=200,
111+
interval=10,
112+
fps=24,
113+
repeat=False,
114+
title=gpx.name(),
115+
title_fontsize=15,
116+
watermark=True,
117+
file_path="video_1.mp4")

0 commit comments

Comments
 (0)