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 plotting multiple gv.Points with different opts arguments #618

Closed
Michael-Barletta opened this issue Feb 7, 2023 · 7 comments · Fixed by #631
Closed

Issue with plotting multiple gv.Points with different opts arguments #618

Michael-Barletta opened this issue Feb 7, 2023 · 7 comments · Fixed by #631

Comments

@Michael-Barletta
Copy link

Michael-Barletta commented Feb 7, 2023

I am plotting multiple different pandas dataframe datasets in geoviews. One dataset I want a different marker shape, two of them I want with different color outlines and one remains plotted as is.

When I plot each of these separately the plots work fine, however, when all plotted together, things get weird. In my example I use a minimal dataset so that anyone could reproduce but the errors are much larger when I am using my larger dataset with a few hundred points.

I have time as a dimension that goes back about 24 hours and a slider is automatically added to the plot, when iterating over that slider everything is good for about 2-3 hours. However as I progress, certain points become the wrong color, entire datasets are not able to be hovered over, sometimes the points that are supposed to be circles become squares, and points that aren’t supposed to have outlines get outlines. The background map also disappears sometimes.

In going through the example I gave, the only aforementioned issue is that only one of the dots is hoverable, the other issues don’t seem to pop up on my end. So maybe it’s a size of data issue? Again, if you need me to provide the full .CSV files with a working example I would be happy to do so.

Complete, minimal, self-contained example code that reproduces the issue

from datetime import datetime
import pandas as pd
import geoviews as gv
from geoviews import opts

gv.extension('bokeh', 'matplotlib')

MPING_data = [  [-124.375755, 47.956669, 'Rain', '#169c2f', '2023-02-06 14:00:00+00:00'],
  [-111.917605, 41.111007, 'Snow', '#1f48cf', '2023-02-06 15:00:00+00:00'],
  [-106.707462, 44.357188, 'Snow', '#1f48cf', '2023-02-06 16:00:00+00:00'],
  [-96.782831, 43.522773, 'Rain', '#169c2f', '2023-02-06 17:00:00+00:00'],
  [-96.440108, 45.298713, 'Mix', '#ac6cd9', '2023-02-06 18:00:00+00:00']
]

MPING_data_test = pd.DataFrame(MPING_data, columns=['Lon', 'Lat', 'Current WX', 'color', 'Time'])
MPING_data_test['Time'] = pd.to_datetime(MPING_data_test['Time'])

ASOS_ptype_data =[['ORER',  36.1500, 44.0000, 'Rain', '#169c2f', '2023-02-06 14:00:00+00:00'],
['PAHY',  55.2061, -132.8281, 'Rain',  '#169c2f', '2023-02-06 15:00:00+00:00'],
['CYPX',  60.0506, -77.2869, 'Snow and/or Graupel', '#1f48cf', '2023-02-06 16:00:00+00:00'],
['PAVA',  61.5408, -165.6009, 'Snow and/or Graupel',  '#1f48cf', '2023-02-06 17:00:00+00:00'],
['MZBZ',  17.5391, -88.3082, 'Rain',  '#169c2f', '2023-02-06 18:00:00+00:00']]
ASOS_ptype_test = pd.DataFrame(ASOS_ptype_data, columns=['Station',  'Lat', 'Lon', 'Current WX',  'color', 'Time'])
ASOS_ptype_test['Time'] = pd.to_datetime(ASOS_ptype_test['Time'])

ASOS_ts_data =[
    ['HRYR',  -1.965, 30.1328, 'Rain with Thunderstorm',  '#169c2f', '2023-02-06 14:00:00+00:00'],
    ['WAHS',  -6.9708, 110.3739, 'Rain with Thunderstorm',  '#169c2f', '2023-02-06 15:00:00+00:00'],
    ['DXXX',  6.1656, 1.2545, 'Rain with Thunderstorm',  '#169c2f', '2023-02-06 16:00:00+00:00'],
    ['SBVH',  -12.6944, -60.0983, 'Rain with Thunderstorm',  '#169c2f', '2023-02-06 17:00:00+00:00'],
    ['ORER',  36.15, 44.0, 'Rain with Thunderstorm',  '#169c2f', '2023-02-06 18:00:00+00:00']
]
ASOS_ts_test = pd.DataFrame(ASOS_ts_data, columns=['Station',  'Lat', 'Lon', 'Current WX',  'color', 'Time'])
ASOS_ts_test['Time'] = pd.to_datetime(ASOS_ts_test['Time'])

ASOS_dataset_ptype_test = gv.Dataset(ASOS_ptype_test, kdims=['Lon','Lat','Time'],vdims=['Current WX','color'])
ASOS_points_ptype_test = ASOS_dataset_ptype_test.to(gv.Points, ['Lon','Lat'],['Current WX','color'])

ASOS_dataset_ts_test = gv.Dataset(ASOS_ts_test, kdims=['Lon','Lat','Time'],vdims=['Current WX','color'])
ASOS_points_ts_test = ASOS_dataset_ts_test.to(gv.Points, ['Lon','Lat'],['Current WX','color'])

MPING_dataset_ptype_test = gv.Dataset(MPING_data_test, kdims=['Lon','Lat','Time'],vdims=['Current WX','color'])
MPING_points_ptype_test = MPING_dataset_ptype_test.to(gv.Points, ['Lon','Lat'],['Current WX','color'])

(gv.tile_sources.OSM() * MPING_points_ptype_test.opts(opts.Points(marker='square')) *ASOS_points_ts_test.opts(opts.Points(line_color='red'))*ASOS_points_ptype_test).opts(opts.Points(color='color',tools=['hover'], size=10))

Screenshots or screencasts of the bug in action

Here is a good example of what I am talking about, the data looks normal when plotted here, besides the fact that only certain pointer are hoverable

image

But when Traversing through the dataset, most of the points are now the wrong color/shape/ have the wrong outline color, and the background map has disappeared.

image

Also of note from the holoviz discourse: If we run

from hvplot import pandas
MPING_data_test.hvplot.points('Lon', 'Lat', geo=True, tiles='OSM', color='color')

Then we get the following hint about shapely:

/Users/droumis/opt/miniconda3/envs/hvplot-env/lib/python3.10/site-packages/shapely/constructive.py:181: RuntimeWarning: invalid value encountered in buffer
  return lib.buffer(
/Users/droumis/opt/miniconda3/envs/hvplot-env/lib/python3.10/site-packages/shapely/set_operations.py:133: RuntimeWarning: invalid value encountered in intersection
  return lib.intersection(a, b, **kwargs)
/Users/droumis/opt/miniconda3/envs/hvplot-env/lib/python3.10/site-packages/shapely/constructive.py:181: RuntimeWarning: invalid value encountered in buffer
  return lib.buffer(
/Users/droumis/opt/miniconda3/envs/hvplot-env/lib/python3.10/site-packages/shapely/constructive.py:181: RuntimeWarning: invalid value encountered in buffer
  return lib.buffer(
@hoxbro
Copy link
Member

hoxbro commented Feb 7, 2023

Have you tried updating to the latest geoviews version 1.9.6? Because I don't get the blank plot or the error like you do.

Though, I see you missing hover for some of your points.

@Michael-Barletta
Copy link
Author

Michael-Barletta commented Feb 7, 2023

@hoxbro yes I am on the latest version, the map disappearing happens when I am plotting my larger dataset. I can post them here as they are just a collection of .CSV files. that are all formatted exactly the same as the dummy ones I included. This could give better insight to what exactly is happening as the problem can more easily be replicable. This initially sounds like it may be a memory issue. However, I've been able to plot datasets much larger than the ones I am using here with no issues. The issue seems to only come up when I am plotting multiple gv.points.

@hoxbro
Copy link
Member

hoxbro commented Feb 7, 2023

Try to do it with fake data, make it as minimal as possible (5-10 lines), and verify that you can run the example and recreate the problem.

There could be multiple issues, and if you can separate those it will be a big help.

@Michael-Barletta
Copy link
Author

Michael-Barletta commented Feb 7, 2023

@hoxbro I have slightly updated the code in my MRE and believe I have gotten some of the issues to replicate. The only thing I have failed to replicate has been the background map disappearing.

To explain a bit there are two main issues that occur.

  1. Only the MPING_points_ptype_test points seem hoverable. The other two datapoints you cannot hover over:

The main issue seems to be, when calling multiple gv.points, only the first point called is hoverable,
(gv.tile_sources.OSM() * MPING_points_ptype_test.opts(opts.Points(marker='square')) *ASOS_points_ts_test.opts(opts.Points(line_color='red'))*ASOS_points_ptype_test).opts(opts.Points(color='color',tools=['hover'], size=10))

In this example MPING_points_ptype_test is the hoverable option, but in my testing, whatever points dataset you call first, will be the only one you can hover over.

  1. After a certain amount of time, the wrong colors begin to show for the datapoints:
    When prompted with the slider, move it to 2023-02-06 18:00:00, the point that is appearing in Mexico is blue when it should not be, the hexidecimal color that is being called there is #169c2f, which is green, but the color that it is showing up as is blue.

@Michael-Barletta
Copy link
Author

Michael-Barletta commented Feb 8, 2023

As I have continued to play around with larger datasets, I have found that wrapping all points in () alleviates the issue of the map disappearing weirdly? The other problems still persist however.

A syntax like this won't make the map disappear

(gv.tile_sources.OSM * (MPING_points2 *ASOS_points_HV*ASOS_points_TS*ASOS_points_ptype)).opts(opts.Points(frame_width=2000, frame_height=1200, size=10, color='color',tools=['hover']))

But this will

(gv.tile_sources.OSM * MPING_points2 *ASOS_points_HV*ASOS_points_TS*ASOS_points_ptype).opts(opts.Points(frame_width=2000, frame_height=1200, size=10, color='color',tools=['hover']))

@Michael-Barletta
Copy link
Author

I have also noticed, within these largest datasets, I am moving the slider from left (the past) to right (current time), the errors I have previously spoke about occur. However, if I am moving my slider from right (current time) to left (the past). Take a look at the difference in plots when I move left to right vs right to left for the same timestamp.

Left to right:
image

Right to left:
image

Certain points still aren't hover-able regardless, but the data at least now looks correct.

@hoxbro
Copy link
Member

hoxbro commented Apr 27, 2023

@Michael-Barletta, I have got a fix for the hover problem in #631

When that PR is merged, this issue will be automatically closed because I'm unsure if the other problems you observed are still there.

If they are, please feel free to open another issue with a small minimal, reproducible example (MRE).

And great presentation yesterday 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants