diff --git a/CHANGELOG.md b/CHANGELOG.md
index 46455faf..bfe87d0d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+### v0.15.7
+* Changed the `radius` argument of a Circle (in Maps) to `area`.
+
### v0.15.6
* Adds support for NumPy v1.18.0+.
diff --git a/datascience/maps.py b/datascience/maps.py
index 60b29520..065a2a94 100644
--- a/datascience/maps.py
+++ b/datascience/maps.py
@@ -16,6 +16,7 @@
import json
import math
import random
+import warnings
from .tables import Table
@@ -295,7 +296,7 @@ def overlay(self, feature, color='Blue', opacity=0.6):
if 'feature' in feature:
feature = feature['feature']
- # if marker table e.g. table with columns: latitudes,longitudes,popup,color,radius
+ # if marker table e.g. table with columns: latitudes,longitudes,popup,color,area
else:
feature = Circle.map_table(feature)
@@ -504,7 +505,7 @@ def map(cls, latitudes, longitudes, labels=None, colors=None, areas=None, other_
assert latitudes is not None
assert longitudes is not None
assert len(latitudes) == len(longitudes)
- assert areas is None or hasattr(cls, '_has_radius'), "A " + cls.__name__ + " has no radius"
+ assert areas is None or hasattr(cls, '_has_area'), "A " + cls.__name__ + " has no area"
inputs = [latitudes, longitudes]
if labels is not None:
assert len(labels) == len(latitudes)
@@ -516,7 +517,7 @@ def map(cls, latitudes, longitudes, labels=None, colors=None, areas=None, other_
inputs.append(colors)
if areas is not None:
assert len(areas) == len(latitudes)
- inputs.append(np.array(areas) ** 0.5 / math.pi)
+ inputs.append(areas)
if other_attrs is not None:
other_attrs_processed = []
for i in range(len(latitudes)):
@@ -570,7 +571,7 @@ class Circle(Marker):
popup -- text that pops up when marker is clicked
color -- fill color
- radius -- pixel radius of the circle
+ area -- pixel-squared area of the circle
Defaults from Folium:
@@ -587,14 +588,19 @@ class Circle(Marker):
'lon', [-122, -122.1, -121.9],
'label', ['one', 'two', 'three'],
'color', ['red', 'green', 'blue'],
- 'radius', [3000, 4000, 5000],
+ 'area', [3000, 4000, 5000],
])
Circle.map_table(t)
"""
- _has_radius = True
+ _has_area = True
- def __init__(self, lat, lon, popup='', color='blue', radius=10, **kwargs):
+ def __init__(self, lat, lon, popup='', color='blue', area=math.pi*(10**2), **kwargs):
+ # Add support for transitioning radius to area
+ radius = (area/math.pi)**0.5
+ if 'radius' in kwargs:
+ warnings.warn("The 'radius' argument is deprecated. Please use 'area' instead.", FutureWarning)
+ radius = kwargs.pop('radius')
super().__init__(lat, lon, popup, color, radius=radius, **kwargs)
@property
diff --git a/tests/Maps.ipynb b/tests/Maps.ipynb
index fdb45c86..ef2a1346 100644
--- a/tests/Maps.ipynb
+++ b/tests/Maps.ipynb
@@ -24,10 +24,10 @@
{
"data": {
"text/html": [
- "
"
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 2,
@@ -49,10 +49,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 3,
@@ -79,10 +79,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 4,
@@ -104,7 +104,7 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
""
@@ -116,7 +116,7 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
""
@@ -128,10 +128,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 5,
@@ -154,7 +154,7 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
""
@@ -166,10 +166,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 6,
@@ -191,10 +191,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 7,
@@ -220,10 +220,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 8,
@@ -244,17 +244,17 @@
"name": "stderr",
"output_type": "stream",
"text": [
- "/Users/ahemani/Development/data8/datascience/datascience/maps.py:458: UserWarning: color argument of Icon should be one of: {'darkgreen', 'darkpurple', 'lightgreen', 'darkred', 'cadetblue', 'lightblue', 'orange', 'blue', 'lightred', 'white', 'beige', 'darkblue', 'gray', 'pink', 'red', 'purple', 'green', 'lightgrayblack'}.\n",
+ "/Users/ahemani/Development/data8/datascience/datascience/maps.py:458: UserWarning: color argument of Icon should be one of: {'darkpurple', 'lightgreen', 'lightblue', 'pink', 'blue', 'lightgrayblack', 'lightred', 'orange', 'beige', 'green', 'darkred', 'cadetblue', 'purple', 'red', 'darkblue', 'white', 'gray', 'darkgreen'}.\n",
" attrs['icon'] = folium.Icon(**icon_args)\n"
]
},
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 9,
@@ -313,10 +313,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 10,
@@ -334,31 +334,32 @@
},
{
"cell_type": "code",
- "execution_count": 11,
+ "execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
- "execution_count": 11,
+ "execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
+ "import math\n",
"colors = ['red', 'blue', 'yellow', 'green']\n",
- "Circle.map(lats, lons, colors=colors, fill_opacity=0.8, radius=20)"
+ "Circle.map(lats, lons, colors=colors, fill_opacity=0.8, area=400 * math.pi)"
]
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 26,
"metadata": {
"scrolled": false
},
@@ -398,13 +399,13 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
- "execution_count": 12,
+ "execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
@@ -413,7 +414,7 @@
"names = colors\n",
"t = Table().with_columns(*zip(['lat', 'lon', 'name', 'color'], [lats, lons, names, colors]))\n",
"t.show()\n",
- "Circle.map_table(t, radius=20)"
+ "Circle.map_table(t, area=400 * math.pi)"
]
},
{
@@ -433,10 +434,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 13,
@@ -457,10 +458,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 14,
@@ -480,10 +481,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 15,
@@ -595,10 +596,10 @@
{
"data": {
"text/html": [
- ""
+ ""
],
"text/plain": [
- ""
+ ""
]
},
"execution_count": 18,
@@ -633,13 +634,13 @@
" \n",
" \n",
" \n",
- " AL | | \n",
+ " AL | | \n",
"
\n",
" \n",
- " AK | | \n",
+ " AK | | \n",
"
\n",
" \n",
- " AZ | | \n",
+ " AZ | | \n",
"
\n",
" \n",
"\n",