Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a tutorial for the Maps module #605

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"In this code we create a default map" -> "In this code we create a default Map" (to distinguish against Python maps)


.. 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