SiegeLord / RustGnuplot

A Rust library for drawing plots, powered by Gnuplot.
GNU Lesser General Public License v3.0
405 stars 46 forks source link

Plotting filled polygons with holes #101

Open jreniel opened 1 week ago

jreniel commented 1 week ago

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!

SiegeLord commented 1 week ago

This isn't supported currently, but it's easy to add. Here's a WIP branch I can finish soon: https://github.com/SiegeLord/RustGnuplot/pull/102

jreniel commented 1 week ago

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 commented 1 week ago

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

jreniel commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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!