From e5a74ebdc1c96651ab5e352c1a512dd19159e9a3 Mon Sep 17 00:00:00 2001 From: Shuaib Nuruddin <95973048+ShuaibNuruddin@users.noreply.github.com> Date: Tue, 19 Dec 2023 08:16:49 +0200 Subject: [PATCH] Added a tutorial for the Maps module (#605) --- docs/tutorial.rst | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 6f9c0029..2d37cafb 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -388,4 +388,48 @@ Let's do the bootstrap test on the two categories. Drawing Maps ------------ -To come. +The main class in the maps module is the Map class. In this code we create a default Map. Maps can be displayed or converted to html. + +.. ipython:: python + + from datascience.maps import Map # import the Map class + default_map = Map() # generate a default Map + default_map.show() # display the Map + + html = default_map.as_html() # generate the html + with open('map.html', 'w') as f: # make a file to store the html + f.write(html) # write the html to the file + +The maps modules also allows you to make custom maps with markers, circles and regions. + +.. ipython:: python + from datascience.maps import Map, Marker, Circle, Region # import the Map, Marker, Circle and Region class + + # generates markers with custom sets of coordinates, colors and popups + marker1 = Marker(37.372, -121.758, color="green", popup="My green marker") + marker2 = Marker(37.572, -121.758, color="orange", popup="My orange marker") + + # generates a circle with a custom set of coordinates, color and popup + circle = Circle(37.5, -122, color="red", area=1000, popup="My Circle") + + # make a geojson object which is needed when making a region + geojson = { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ # specifies the coordinates + [[-121,37],[-121.5,37],[-121.5,37.5],[-121,37.5],[-121,37]] # these coordinates make a rectangle + ] + } + } + + # make a region with your geojson object + region = Region(geojson) + + + # Initialize the map + custom_map = Map(features=[marker1, marker2, circle, region], # specifies the features + width=800, # specifies a custom width + height=600 # specifies a custom height + ) + custom_map.show() # display the map