0
# Visualization and Plotting
1
2
Advanced visualization tools including charts, plots, legends, timelapse animations, and color management for comprehensive geospatial data analysis and presentation.
3
4
## Capabilities
5
6
### Chart Creation
7
8
Create various chart types for data visualization and analysis using integrated plotting libraries.
9
10
```python { .api }
11
def bar_chart(
12
data,
13
x: str,
14
y: str,
15
width: int = 400,
16
height: int = 300,
17
**kwargs
18
) -> None:
19
"""
20
Create bar chart from data.
21
22
Args:
23
data: Input data (DataFrame, list, or dict)
24
x: Column name for x-axis
25
y: Column name for y-axis
26
width: Chart width in pixels
27
height: Chart height in pixels
28
**kwargs: Additional chart parameters
29
"""
30
31
def line_chart(
32
data,
33
x: str,
34
y: str,
35
width: int = 400,
36
height: int = 300,
37
**kwargs
38
) -> None:
39
"""
40
Create line chart from data.
41
42
Args:
43
data: Input data (DataFrame, list, or dict)
44
x: Column name for x-axis
45
y: Column name for y-axis
46
width: Chart width in pixels
47
height: Chart height in pixels
48
**kwargs: Additional chart parameters
49
"""
50
51
def histogram(
52
data,
53
column: str,
54
bins: int = 20,
55
width: int = 400,
56
height: int = 300,
57
**kwargs
58
) -> None:
59
"""
60
Create histogram from data.
61
62
Args:
63
data: Input data (DataFrame, list, or dict)
64
column: Column name for histogram
65
bins: Number of histogram bins
66
width: Chart width in pixels
67
height: Chart height in pixels
68
**kwargs: Additional chart parameters
69
"""
70
71
def pie_chart(
72
data,
73
names: str,
74
values: str,
75
width: int = 400,
76
height: int = 300,
77
**kwargs
78
) -> None:
79
"""
80
Create pie chart from data.
81
82
Args:
83
data: Input data (DataFrame, list, or dict)
84
names: Column name for pie slice names
85
values: Column name for pie slice values
86
width: Chart width in pixels
87
height: Chart height in pixels
88
**kwargs: Additional chart parameters
89
"""
90
```
91
92
### Advanced Chart Classes
93
94
Object-oriented chart creation with extensive customization options.
95
96
```python { .api }
97
class Chart:
98
"""Base chart class for data visualization."""
99
100
def __init__(self, **kwargs) -> None:
101
"""Initialize base chart."""
102
103
class BarChart(Chart):
104
"""Bar chart implementation."""
105
106
def __init__(self, **kwargs) -> None:
107
"""Initialize bar chart."""
108
109
class LineChart(Chart):
110
"""Line chart implementation."""
111
112
def __init__(self, **kwargs) -> None:
113
"""Initialize line chart."""
114
115
class DataTable:
116
"""Enhanced pandas DataFrame with additional functionality."""
117
118
def __init__(self, data, **kwargs) -> None:
119
"""
120
Initialize enhanced data table.
121
122
Args:
123
data: Input data
124
**kwargs: Additional parameters
125
"""
126
```
127
128
### Feature-Based Charts
129
130
Specialized charts for Earth Engine feature collections and geospatial data analysis.
131
132
```python { .api }
133
class Feature_ByFeature:
134
"""Chart features by individual feature properties."""
135
136
def __init__(self, **kwargs) -> None:
137
"""Initialize feature-by-feature chart."""
138
139
class Feature_ByProperty:
140
"""Chart features by property values."""
141
142
def __init__(self, **kwargs) -> None:
143
"""Initialize feature-by-property chart."""
144
```
145
146
### Timelapse and Animation
147
148
Create animated visualizations and timelapse sequences from Earth Engine data.
149
150
```python { .api }
151
def create_timeseries(
152
ee_object,
153
region: ee.Geometry,
154
start_date: str,
155
end_date: str,
156
bands: List[str] = None,
157
frequency: str = 'month',
158
reducer: str = 'mean',
159
**kwargs
160
) -> None:
161
"""
162
Create time series visualization.
163
164
Args:
165
ee_object: Earth Engine ImageCollection
166
region: Region of interest
167
start_date: Start date (YYYY-MM-DD)
168
end_date: End date (YYYY-MM-DD)
169
bands: Bands to include
170
frequency: Time frequency ('day', 'month', 'year')
171
reducer: Reduction method ('mean', 'median', 'sum')
172
**kwargs: Additional parameters
173
"""
174
175
def make_gif(
176
out_gif: str,
177
fps: int = 5,
178
loop: int = 0,
179
**kwargs
180
) -> str:
181
"""
182
Create GIF animation from images.
183
184
Args:
185
out_gif: Output GIF file path
186
fps: Frames per second
187
loop: Number of loops (0 for infinite)
188
**kwargs: Additional GIF parameters
189
190
Returns:
191
Path to created GIF
192
"""
193
194
def gif_to_mp4(
195
in_gif: str,
196
out_mp4: str = None,
197
fps: int = 10,
198
**kwargs
199
) -> str:
200
"""
201
Convert GIF to MP4 video.
202
203
Args:
204
in_gif: Input GIF file path
205
out_mp4: Output MP4 file path
206
fps: Frames per second
207
**kwargs: Additional parameters
208
209
Returns:
210
Path to MP4 file
211
"""
212
213
def add_text_to_gif(
214
in_gif: str,
215
out_gif: str,
216
xy: tuple = None,
217
text_sequence: List[str] = None,
218
font_size: int = 20,
219
font_color: str = "black",
220
**kwargs
221
) -> str:
222
"""
223
Add text overlay to GIF frames.
224
225
Args:
226
in_gif: Input GIF file path
227
out_gif: Output GIF file path
228
xy: Text position (x, y)
229
text_sequence: List of text for each frame
230
font_size: Font size in points
231
font_color: Font color
232
**kwargs: Additional parameters
233
234
Returns:
235
Path to output GIF
236
"""
237
238
def add_image_to_gif(
239
in_gif: str,
240
out_gif: str,
241
in_image: str,
242
xy: tuple = None,
243
image_size: tuple = None,
244
**kwargs
245
) -> str:
246
"""
247
Add image overlay to GIF frames.
248
249
Args:
250
in_gif: Input GIF file path
251
out_gif: Output GIF file path
252
in_image: Overlay image path
253
xy: Image position (x, y)
254
image_size: Image size (width, height)
255
**kwargs: Additional parameters
256
257
Returns:
258
Path to output GIF
259
"""
260
261
def reduce_gif_size(
262
in_gif: str,
263
out_gif: str = None,
264
**kwargs
265
) -> str:
266
"""
267
Reduce GIF file size.
268
269
Args:
270
in_gif: Input GIF file path
271
out_gif: Output GIF file path
272
**kwargs: Optimization parameters
273
274
Returns:
275
Path to optimized GIF
276
"""
277
```
278
279
### Color Management
280
281
Comprehensive color palette and colormap management for data visualization.
282
283
```python { .api }
284
def get_palette(
285
cmap_name: str = None,
286
n_class: int = 8,
287
hashtag: bool = False,
288
**kwargs
289
) -> List[str]:
290
"""
291
Get color palette for visualization.
292
293
Args:
294
cmap_name: Colormap name
295
n_class: Number of color classes
296
hashtag: Include # prefix for hex colors
297
**kwargs: Additional parameters
298
299
Returns:
300
List of color hex codes
301
"""
302
303
def get_colorbar(
304
colors: List[str],
305
vmin: float = 0,
306
vmax: float = 1.0,
307
index: List[float] = None,
308
step: int = None,
309
**kwargs
310
) -> str:
311
"""
312
Generate colorbar for visualization.
313
314
Args:
315
colors: List of colors
316
vmin: Minimum value
317
vmax: Maximum value
318
index: Value indices for colors
319
step: Step size for colorbar
320
**kwargs: Additional parameters
321
322
Returns:
323
Colorbar HTML string
324
"""
325
326
def list_colormaps() -> List[str]:
327
"""
328
List available colormaps.
329
330
Returns:
331
List of colormap names
332
"""
333
334
def plot_colormap(
335
cmap_name: str,
336
width: int = 8,
337
height: int = 0.4,
338
**kwargs
339
) -> None:
340
"""
341
Plot single colormap visualization.
342
343
Args:
344
cmap_name: Colormap name
345
width: Plot width
346
height: Plot height
347
**kwargs: Additional plot parameters
348
"""
349
350
def plot_colormaps(
351
width: int = 8,
352
height: int = 0.4,
353
**kwargs
354
) -> None:
355
"""
356
Plot all available colormaps.
357
358
Args:
359
width: Plot width
360
height: Plot height per colormap
361
**kwargs: Additional plot parameters
362
"""
363
```
364
365
### Legend Management
366
367
Create and manage map legends for data visualization.
368
369
```python { .api }
370
def ee_table_to_legend(
371
ee_table: ee.FeatureCollection,
372
color_column: str,
373
label_column: str,
374
**kwargs
375
) -> Dict:
376
"""
377
Convert Earth Engine table to legend.
378
379
Args:
380
ee_table: Earth Engine FeatureCollection
381
color_column: Column containing color values
382
label_column: Column containing labels
383
**kwargs: Additional parameters
384
385
Returns:
386
Legend configuration dictionary
387
"""
388
389
# Built-in legends
390
builtin_legends: Dict[str, Dict] = {}
391
```
392
393
### Data Processing for Visualization
394
395
Utilities for processing and transforming data for visualization purposes.
396
397
```python { .api }
398
def transpose_df(df, **kwargs):
399
"""
400
Transpose DataFrame for visualization.
401
402
Args:
403
df: Input DataFrame
404
**kwargs: Additional parameters
405
406
Returns:
407
Transposed DataFrame
408
"""
409
410
def pivot_df(
411
df,
412
index: str,
413
columns: str,
414
values: str,
415
**kwargs
416
):
417
"""
418
Pivot DataFrame for visualization.
419
420
Args:
421
df: Input DataFrame
422
index: Index column
423
columns: Columns to pivot
424
values: Values column
425
**kwargs: Additional parameters
426
427
Returns:
428
Pivoted DataFrame
429
"""
430
431
def array_to_df(
432
array,
433
column_names: List[str] = None,
434
**kwargs
435
):
436
"""
437
Convert array to DataFrame.
438
439
Args:
440
array: Input array
441
column_names: Column names for DataFrame
442
**kwargs: Additional parameters
443
444
Returns:
445
DataFrame object
446
"""
447
```
448
449
## Usage Examples
450
451
### Basic Charts
452
453
```python
454
import geemap
455
import pandas as pd
456
457
# Create sample data
458
data = pd.DataFrame({
459
'year': [2018, 2019, 2020, 2021, 2022],
460
'temperature': [14.2, 15.1, 14.8, 15.3, 15.7]
461
})
462
463
# Create line chart
464
geemap.line_chart(data, x='year', y='temperature', width=500, height=300)
465
466
# Create bar chart
467
geemap.bar_chart(data, x='year', y='temperature')
468
469
# Create histogram
470
sample_data = pd.DataFrame({'values': [1, 2, 2, 3, 3, 3, 4, 4, 5]})
471
geemap.histogram(sample_data, column='values', bins=5)
472
```
473
474
### Time Series Visualization
475
476
```python
477
import ee
478
479
# Initialize Earth Engine
480
ee.Initialize()
481
482
# Create time series from NDVI data
483
collection = (ee.ImageCollection('MODIS/006/MOD13A2')
484
.filterDate('2020-01-01', '2020-12-31')
485
.select('NDVI'))
486
487
roi = ee.Geometry.Point([-122.4, 37.8])
488
489
geemap.create_timeseries(
490
collection,
491
region=roi,
492
start_date='2020-01-01',
493
end_date='2020-12-31',
494
bands=['NDVI'],
495
frequency='month'
496
)
497
```
498
499
### GIF Creation and Animation
500
501
```python
502
# Create GIF from image collection
503
collection = (ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
504
.filterDate('2020-01-01', '2020-12-31')
505
.filterBounds(roi)
506
.limit(12))
507
508
# Export frames and create GIF
509
geemap.make_gif(
510
'landsat_timelapse.gif',
511
fps=2,
512
loop=0
513
)
514
515
# Add text to GIF
516
text_sequence = ['Jan 2020', 'Feb 2020', 'Mar 2020']
517
geemap.add_text_to_gif(
518
'landsat_timelapse.gif',
519
'landsat_with_text.gif',
520
xy=(50, 50),
521
text_sequence=text_sequence,
522
font_size=16,
523
font_color='white'
524
)
525
526
# Convert to MP4
527
geemap.gif_to_mp4('landsat_with_text.gif', 'landsat_timelapse.mp4', fps=5)
528
```
529
530
### Color Palettes and Colormaps
531
532
```python
533
# Get color palette
534
colors = geemap.get_palette('viridis', n_class=10)
535
print(colors)
536
537
# List available colormaps
538
colormaps = geemap.list_colormaps()
539
print(f"Available colormaps: {len(colormaps)}")
540
541
# Plot specific colormap
542
geemap.plot_colormap('RdYlBu', width=10, height=0.5)
543
544
# Create colorbar
545
colorbar = geemap.get_colorbar(
546
colors=['blue', 'green', 'red'],
547
vmin=0,
548
vmax=100
549
)
550
```
551
552
## Types
553
554
```python { .api }
555
# Chart data types
556
ChartData = Union[pd.DataFrame, List, Dict]
557
558
# Color specification
559
Color = Union[str, tuple, List[float]]
560
561
# Color palette
562
Palette = List[str]
563
564
# Chart dimensions
565
ChartDimensions = Dict[str, int] # {'width': int, 'height': int}
566
567
# Legend configuration
568
LegendConfig = Dict[str, Union[str, List[str], Dict]]
569
570
# Animation parameters
571
AnimationParams = Dict[str, Union[int, float, str, bool]]
572
```