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

Issue with Map Plot #6

Closed
joeborrello opened this issue Jan 4, 2019 · 14 comments
Closed

Issue with Map Plot #6

joeborrello opened this issue Jan 4, 2019 · 14 comments
Labels
bug Something isn't working

Comments

@joeborrello
Copy link

When I try to run the Mapplot example, I get the following error when I try to use plot_bokeh.map:

AttributeError: 'function' object has no attribute 'map'

The whole code is as follows:

import pandas as pd
import pandas_bokeh
pandas_bokeh.output_notebook()

df_mapplot = pd.read_csv(r"https://raw.githubusercontent.com/PatrikHlobil/Pandas-Bokeh/master/Documentation/Testdata/populated%20places/populated_places.csv")

df_mapplot["size"] = df_mapplot["pop_max"] / 1000000
df_mapplot.plot_bokeh.map(
    x="longitude",
    y="latitude",
    hovertool_string="""<h2> @{name} </h2> 
    
                        <h3> Population: @{pop_max} </h3>""",
    tile_provider="STAMEN_TERRAIN_RETINA",
    size="size", 
    figsize=(900, 600),
    title="World cities with more than 1.000.000 inhabitants")
@PatrikHlobil PatrikHlobil added the bug Something isn't working label Jan 5, 2019
@PatrikHlobil
Copy link
Owner

You have to use version 0.1 for the map plots. You can check the version with

import pandas_bokeh
print(pandas_bokeh.__version__)

You can then upgrade via pip:

pip install --upgrade pandas-bokeh

If it works, please close the issue. Otherwise, please provide me the error message such that I can check the problem.

@joeborrello
Copy link
Author

Okay, that worked. The originally installed version was 0.0.2, so the pip upgrade fixed that issue. However, I'm not getting the following error:

ValueError: All values of the -columns have to be restricted to (-90, 90). The value corresponds to the longitude in WGS84 projection.

Which doesn't seem to make sense because the data set itself has values that are both above and below 90 and -90, respectively.

@PatrikHlobil
Copy link
Owner

Thas is weird, I cannot reproduce your problem. I used the code you pasted above (works both with output_notebook and output_file):

import pandas as pd
import pandas_bokeh
pandas_bokeh.output_file("mapplot.html")

df_mapplot = pd.read_csv(r"https://raw.githubusercontent.com/PatrikHlobil/Pandas-Bokeh/master/Documentation/Testdata/populated%20places/populated_places.csv")

df_mapplot["size"] = df_mapplot["pop_max"] / 1000000
df_mapplot.plot_bokeh.map(
    x="longitude",
    y="latitude",
    hovertool_string="""<h2> @{name} </h2> 
    
                        <h3> Population: @{pop_max} </h3>""",
    tile_provider="STAMEN_TERRAIN_RETINA",
    size="size", 
    figsize=(900, 600),
    title="World cities with more than 1.000.000 inhabitants")

that creates the plot below on my computer:
mapplot.zip

The error message comes from restriction of the latitude (this is actually an error in the ValueError-message since it is not the longitude restriction) of the WGS84 coordinates. The data however does not contain values that exceed this boundaries:

df_mapplot.describe()
pop_max latitude longitude size
count 5.000000e+02 500.000000 500.000000 500.000000
mean 2.786597e+06 25.000442 37.206103 2.786597
std 3.108616e+06 21.067590 77.569481 3.108616
min 1.002000e+06 -37.818085 -123.123590 1.002000
25% 1.283250e+06 17.247772 -7.031884 1.283250
50% 1.720500e+06 30.661972 46.535048 1.720500
75% 2.920250e+06 38.591966 110.388075 2.920250
max 3.567600e+07 60.177509 174.763027 35.676000

which created the plot. Can you check your DataFrame with the describe() method?

@joeborrello
Copy link
Author

joeborrello commented Jan 8, 2019

Okay, so one set of apt updates, and upgrades later, the example code works properly. But I'm still getting that error with a data set of my own. Here's what happens when I use describe() on that data frame:

_ Latitude Longitude
count 663784.000000 663784.000000
mean 40.765353 -73.921533
std 0.089083 0.050768
min 40.499440 -74.250642
25% 40.680547 -73.953867
50% 40.786001 -73.924239
75% 40.845376 -73.889728
max 40.911587 -73.701025

@PatrikHlobil
Copy link
Owner

Could you provide me your dataframe (e.g. as pickle or as parquet)? Then I could try it on my computer and figure out what the problem is. Otherwise, I would propose that you try:
df_mapplot.head(100).plot_bokeh.map(...)

and if that works you can try to increase the number of rows that you use for the plot to figure out when the problem occurs.

@joeborrello
Copy link
Author

Okay, so using head(100) worked, so maybe there's just too many rows in the data set? It is fairly large data from NYC. I'm including the dataframe also: https://we.tl/t-FBr853It7n

@PatrikHlobil
Copy link
Owner

Ok, I found the problem. Your x and y columns contain NaN values. Therefore, checking the min/max values gives NaN and this violates the conditions for latitude and longitude. One should implement a warning that one cannot plot NaN values.

The solution for you would be to filter out the rows with NaN values in Latitude or Longitude:

df_mapplot = df_mapplot[df_mapplot["Latitude"].notnull()&df_mapplot["Longitude"].notnull()]

and then to plot the data. Note however that you shouldn't use output_notebook, but output_file. On my computer the notebook crashed because the output was to big. Also, 600.000 points will probably crash your browser, even when using WebGL which is the default for Pandas Bokeh.

@joeborrello
Copy link
Author

Thanks for helping with that - I thought I had gotten rid of all of the NaN values, but I guess not. And thanks for the heads up about notebook versus file output.

@PatrikHlobil
Copy link
Owner

You’re welcome. Maybe have a look at the Output and Layouts section of the README.md. This could also be interesting for you...

@Rendiere
Copy link

Rendiere commented May 7, 2019

Hey @PatrikHlobil, I'm running into a potentially related issue on the map plot example.

Using the exact code as in the github readme, I get the error:

AttributeError: 'FramePlotMethods' object has no attribute '_data'

Version:

print(pandas_bokeh.__version__)
> 0.1.1

@PatrikHlobil
Copy link
Owner

Hi @Rendiere ,

thanks for the bug report. This happens when you don't catch up with all your tests :(.

Thisis a new bug and is different from the one desribed above. I already fixed it and it will be available with the next release.

If you don't want to wait, just upgrade on the dev version via:

pip install git+https://github.com/PatrikHlobil/Pandas-Bokeh.git

Best,

Patrik

@boustrephon
Copy link

Hi @PatrikHlobil : I am on 0.3 (from conda on a Mac) and I have the same problem as @Rendiere (AttributeError: 'FramePlotMethods' object has no attribute '_data'). I am using the same code as above.

Python version 3.7.7 (default, Mar 23 2020, 17:31:31)
[Clang 4.0.1 (tags/RELEASE_401/final)]
Pandas version 0.23.4
Bokeh version 2.0.1
Pandas-bokeh version 0.3

@PatrikHlobil
Copy link
Owner

PatrikHlobil commented Apr 5, 2020

Hi @boustrephon,

The conda package is out of date at the moment because there are problems with a dependency relation in used packages. Please install the latest version via pip and report If the issue I solved.

Best Patrik

@PatrikHlobil
Copy link
Owner

Hi @boustrephon, @joeborrello,

I just fixed the conda build problem and you can now also install the most recent version of pandas-bokeh (0.4.3) via conda via:

conda install -c patrikhlobil pandas-bokeh

Best Patrik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants