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 filled polygons with holes #101

Open
jreniel opened this issue Jun 23, 2024 · 6 comments
Open

Plotting filled polygons with holes #101

jreniel opened this issue Jun 23, 2024 · 6 comments

Comments

@jreniel
Copy link

jreniel commented Jun 23, 2024

I am trying to replicate this: https://stackoverflow.com/a/56375007/7432462
Assuming we already have converted the geo_types::Polygon into a single path, as described in the referenced link, how do we use the gnuplot api to plot this fill curve?
Thanks!

@jreniel jreniel changed the title Plotting filled polygons Plotting filled polygons with holes Jun 23, 2024
@SiegeLord
Copy link
Owner

This isn't supported currently, but it's easy to add. Here's a WIP branch I can finish soon: #102

@jreniel
Copy link
Author

jreniel commented Jun 24, 2024

Thanks for looking into this!
I have tested several plotting solutions for Rust, but I am inclined to think that gnuplot could be the de-facto plotting library for Rust, similar to what matplotlib is to Python.

One question, does your solution require me to pass the Polygon as a single path, or does your solution know how to plot polygons with holes implicitly?
I haven't actually finished the code for connecting the polygons as a single path, so it would be helpful to know if it will still be required on my end.

@SiegeLord
Copy link
Owner

It'll be passed straight to gnuplot, so you'll need to deal with holes yourself.

@jreniel
Copy link
Author

jreniel commented Jun 25, 2024

Thanks!
So I guess if I wanted to replicate the functionality of matplotlib.pyplot.tricontourf I would have to compute each polygon, and a color ramp and pass each of them to gnuplot? That's not particularly difficult, but my question is, how can we organize or make a project that will wrap around this crate to provide the higher level functionality? Right now, I am compiling my stuff here. You can, for example, see the (still barely tested) code for changing a geo_types::Polygon into a single path here. I know that this functionality is a necessity for anyone coming to Rust for data science (we need to plot a lot!). I think gnuplot crate provides the lower level functionality, but we still need wrappers for repetitive higher level things like computing contour levels and plotting them through gnuplot. I'm sure that geopolars will eventually need this if they plan to replicate all the functionality from geopandas (incl plotting of geo_types objects).

I'm still testing, and I am glad you took care of this so quickly. What I am asking for now is merely guidance into how to organize/create functions that will provide higher level plotting for this crate.

Thanks!

@SiegeLord
Copy link
Owner

If you want contour plots, there's already some support for that via show_contours and surface functions on Axis3D, although I note they are not working as well as I recall them working (new gnuplot broke a few things). I can investigate.

@jreniel
Copy link
Author

jreniel commented Jun 27, 2024

If you want contour plots, there's already some support for that via show_contours and surface functions on Axis3D, although I note they are not working as well as I recall them working (new gnuplot broke a few things). I can investigate.

If you have some insights, I will greatly appreciate it! I think plotting is currently Rust's Achilles heel, but I think that can be remediated. In practice what I am looking for is the family of 2D plots for triangulation and surfaces, (tricontour, trincontourf and triplot), because my work revolves around geoplanetary unstructured meshes. I also want to see if I can replicate contextily. I guess I could get away with using Axes3D, but strictly speaking, I am looking for 2D surfaces and triangulation plots, along with contextily-like basemap images. I know it's a super tall order! But Rust needs this!

Personally, if I had the funding, I would be happily sponsoring a team to bring Rust plotting up to speed, particuarly, through a gnuplot-like interface, which is extremely similar to matplotlib and would essentially work as the Rust equivalent. Lots of people would probably switch from Py to Rust if we had solid plotting!

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

2 participants