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

Plotting capabilities #82

Open
martinfleis opened this issue Aug 30, 2024 · 11 comments
Open

Plotting capabilities #82

martinfleis opened this issue Aug 30, 2024 · 11 comments

Comments

@martinfleis
Copy link
Member

@e-marshall you have mentioned that plotting of vector data cubes is a bit cumbersome. I have to admit I never thought about including some plotting features as I assumed you just go via a GeoDataFrame and use its plot/explore methods but if you have ideas how we could improve plotting experience, I'm all ears.

Just two notes.

  1. Any plotting should use geopandas machinery as I'm not willing to maintain yet another plotting code. It is painful enough to have two in geopandas already :D.
  2. GeoPandas static plotting is due for an overhaul, so if we want to link xvec closely to geopandas, it may involve some changes in future.
@e-marshall
Copy link

Thanks for opening this issue, @martinfleis, and sorry for my delayed response!

I agree I think using geopandas plotting makes the most sense. When I was exploring/ trying out working with vector xarray datasets, I tried using Xarray plotting functions, and that's where I ran into it not accepting the dimension containing geometry arrays, but I don't see that kind of visualization being a main use-case of vector data cubes.

If anything, maybe there could be a utility function that wraps the steps to create a parallel dimension and swap from the geometry dim for xarray plotting purposes? Working on this kind of thing is relatively new for me so I'd love to hear any thoughts on why that may or may not be a useful feature. If it would be helpful, it's definitely something I'd be interested in working on, though I probably won't have a ton of time to do so in the next ~ 1 month.

@dcherian
Copy link
Contributor

Since you now have n dimensions, stuff like faceting could be useful. We'll need to make xarray;s plotting module a bit more resilient to unknown data types.

@e-marshall
Copy link

Faceting with the vector cubes would be cool! I was imagining a function to create a dummy dim of int types, or something like that, to pass to xarray's plotting module, but if you think it would be better to address it on the xarray plotting side, that would be great as well

@martinfleis
Copy link
Member Author

Is there a way we can expand the functionality of Xarray's plot from the Xvec's side? Or would it need to be something like .xvec.plot()?

@benbovy
Copy link
Member

benbovy commented Sep 27, 2024

Is there a way we can expand the functionality of Xarray's plot from the Xvec's side? Or would it need to be something like .xvec.plot()?

I guess it would need the latter, but...

We'll need to make xarray;s plotting module a bit more resilient to unknown data types.

I'm wondering if it would make sense to make xarray's plotting work with geometries directly. Xarray has already a couple of tests using Cartopy, and Cartopy can plot shapely geometries. Perhaps it wouldn't be hard / big maintenance burden to add a special case in Xarray? Maybe Xarray's plotting functions would then just work for basic plotting of geometries? Not sure as I'm not very familiar with the Xarray plotting code.

One possible annoying thing is the different CRS objects used here vs. in Cartopy, something I guess you already have to deal with in geopandas.

@martinfleis
Copy link
Member Author

Perhaps it wouldn't be hard / big maintenance burden to add a special case in Xarray?

Plotting code for vector geometries is completely different beast than rasters as we need to create the whole maptlotlib object ourselves from patches, assigning colours to each... Knowing how this looks in geopandas I would recommend leaving that alone.

@benbovy
Copy link
Member

benbovy commented Sep 27, 2024

I was more thinking about plotting via cartopy (i.e., add_geometries()) than re-implementing all of that with matplotlib... I'd totally follow your recommendation otherwise :-) !

@dcherian
Copy link
Contributor

Oh add_geometries is quite the plot twist!

@ahuang11
Copy link
Member

Perhaps HoloViz could serve as the default plotting library for xvec, so that xvec_ds.plot() -> xvec_ds.hvplot().

A basic demo of this is available in a hvPlot PR, where the data is converted to GeoPandas and plotted using hvPlot's existing support for GeoPandas. However, I believe there's potential for a more impactful implementation involving GeoViews.

@benbovy
Copy link
Member

benbovy commented Oct 22, 2024

hvPlot is great and it would be nice if it could work seamlessly with xvec (i.e., your open hvplot PR) or vector data cubes in general!

That said, using hvPlot (HoloViz) as a default plotting library here would be a pretty strong opinionated choice IMO. I know that Holoviz supports multiple backend libraries including matplotlib, but from my experience it seems to work best (and by default uses) Bokeh.

Cartopy / Matplotlib seems a bit less opinionated for basic (static) plots to me.

@martinfleis
Copy link
Member Author

The easiest option is likely to use Matplotlib via GeoPandas. You will probably need to convert to a GeoDataFrame anyway.

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

No branches or pull requests

5 participants