tcassou / mapsplotlib

Custom Python plots on a Google Maps background. A flexible matplotlib like interface to generate many types of plots on top of Google Maps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

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

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

  1. The scatter method (as well as other plot methods) expect pandas.Series objects as arguments for both latitudes and longitudes (you can see this in the docstring). When accessing the ith element with df_geo['latitude'][i], what you get is a float 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 the iloc method (so df_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!

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

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