Integrate into subplot
omerfarukeker opened this issue · comments
Hi tcassou,
Thank you very much for the work!
I am new to Python. I invoke mplt.scatter function in a for loop, each time inputting with the corresponding row of my dataframe. 2 problems I encounter so far:
-
When I pass the dataframe's ith row in the for loop mplt.scatter(df_geo['latitude'][i],df_geo['longitude'][i]) it throws the following error "numpy.float64' object has no attribute 'index". I wanted to put ith dot on the map within the loop.
-
In the for loop, each time it creates a figure, how can I put it one of my subplots and update the map in the for loop.
Cheers,
Hi @slayomer, thanks for asking!
-
The
scatter
method (as well as other plot methods) expectpandas.Series
objects as arguments for both latitudes and longitudes (you can see this in the docstring). When accessing the ith element withdf_geo['latitude'][i]
, what you get is afloat
instead, which causes the program to fail.
So in your case if you need to plot only 1 point on the map, you could for example use this instead:df_geo['latitude'][i:i+1]
, which is the sub series from ith (included) to (i+1)th (excluded) element. I would on top suggest to explicitly use theiloc
method (sodf_geo['latitude'].iloc[i:i+1]
) to avoid confusion.
On my end I'll think of ways to validate the input and print out more explicit error messages! -
In the current setup the figure is defined inside plotting methods, and the
show
method is called, causing the plot to be rendered.
If you have suggestion on how to add support for subplots while keeping compatibility with current use cases, happy to hear them!
Hi @tcassou thanks for your swift response, it worked well.
Also managed to solve the other issues which are:
- Commented out the line 79: plt.figure(figsize=(10, 10)) as it creates new figure each time scatter function of the mapsplot.py is invoked.
- Also zoom of the map wasn't working properly in the for loop (it was too wide), I changed it to 20 which worked well.
Thanks again creating such nice library for google maps plotting.
Cheers,
Omer
Hi @slayomer
Good to hear it worked out - and thanks for the nice words!
About subplots if you think of an elegant way of enabling this option through the package while keeping compatibility with the current API, feel free to send a pull request.
I'll close this issue for now, don't hesitate to reopen it if needed,
Thomas