I'm pulling data from an API and viewing it in a pandas dataframe using a Jupyter Notebook. The data has several attributes including latitude and longitude. I can successfully convert the pandas dataframe to a spatially enabled dataframe, call the .head() method and see the new SHAPE column. I can create a map object but when I try to plot my dataframe on the map object, the map does not update and display the points. I've included my code below:
<SPAN class="comment token"># Define parameters for API call</SPAN>
headers <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'accept'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'application/json'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Api-Token'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'Key'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'Agency-ID'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'ID'</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Call API and save to a varialbe</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'URL'</SPAN><SPAN class="punctuation token">,</SPAN> headers<SPAN class="operator token">=</SPAN>headers<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>json<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Convert json to dataframe</SPAN>
df <SPAN class="operator token">=</SPAN> pd<SPAN class="punctuation token">.</SPAN>DataFrame<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Convert dataframe to spatially enabled dataframe</SPAN>
df <SPAN class="operator token">=</SPAN> pd<SPAN class="punctuation token">.</SPAN>DataFrame<SPAN class="punctuation token">.</SPAN>spatial<SPAN class="punctuation token">.</SPAN>from_xy<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> x_column <SPAN class="operator token">=</SPAN> <SPAN class="string token">'longitude'</SPAN><SPAN class="punctuation token">,</SPAN> y_column <SPAN class="operator token">=</SPAN> <SPAN class="string token">'latitude'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Create map object and display map</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
m <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
m<SPAN class="punctuation token">.</SPAN>center <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">36.081179</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">79.556955</SPAN><SPAN class="punctuation token">]</SPAN>
m<SPAN class="punctuation token">.</SPAN>zoom <SPAN class="operator token">=</SPAN> <SPAN class="number token">9</SPAN>
m
<SPAN class="comment token"># Plot dataframe</SPAN>
df<SPAN class="punctuation token">.</SPAN>spatial<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>map_widget<SPAN class="operator token">=</SPAN> m<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Line 22 returns a map and Line 25 returns 'True' but no updates to the map are made. I've also tried using the renderer and symbol_type and symbol_style attributes.
df<SPAN class="punctuation token">.</SPAN>spatial<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>map_widget<SPAN class="operator token">=</SPAN>m<SPAN class="punctuation token">,</SPAN>
symbol_type<SPAN class="operator token">=</SPAN><SPAN class="string token">'simple'</SPAN><SPAN class="punctuation token">,</SPAN>
symbol_style<SPAN class="operator token">=</SPAN><SPAN class="string token">'d'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="comment token"># d - for diamonds</SPAN>
colors<SPAN class="operator token">=</SPAN><SPAN class="string token">'Reds_r'</SPAN><SPAN class="punctuation token">,</SPAN>
cstep<SPAN class="operator token">=</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN>
outline_color<SPAN class="operator token">=</SPAN><SPAN class="string token">'Blues'</SPAN><SPAN class="punctuation token">,</SPAN>
marker_size<SPAN class="operator token">=</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>This block of code replaced Line 25 in the first section but did not display in the map either.
I've been through the documentation and the guide on GitHub but cannot find anything to make it work. Please advise.
Thanks,
Miguel Fernandez