-
-
Notifications
You must be signed in to change notification settings - Fork 62
Description
I don't know if this belongs to this discussion, but since I already said something about it, I'm going to comment it here. It's regarding this:
By the way, this kind of functionality is very similar to what a pandas dataframe would do isn't it?
This is a wild idea, I know, but maybe it could be useful to generate dataframes containing some attributes of the geometry:
df = geom.to_df(cols=["Z", "neighs", "angles", "force"])
Geometry would know how to build these dataframes because it knows what the attributes mean. Then the user would have all the power of dataframes to do not only complex filters but also groupby, describe, etc...
I just thought that, apart from filtering, this feature in sisl objects could be extremely useful for visualizing. Here's why: For the visualization module I am using plotly. Plotly has a high-level API under plotly.express
(https://plotly.com/python/plotly-express/). Plotly express implements some plots like scatter, line, histograms, polar, maps... and more. Basically how it works is that, given a pandas DataFrame
, you define your plot as columns of this dataframe. An example of this:
import plotly.express as px
px.scatter3d(df, x="The x column", y="The y column", z="The z column",
color="Column that defines color", animation_frame="The column that defines the frames",
symbol=..., etc )
So, if sisl objects had a to_df
method as proposed, it would be trivial to implement a "sisl.express" in the visualization module that would just parse the object into a dataframe before passing it to any plotly.express
method. The possibilities would be endless with very simple code:
import sisl
import sisl.viz.express as sx
geom = sisl.Geometry()
sx.scatter(geom, x="z", y="neighs", color="species")
# or
sx.histogram(geom, x="z", color="species",
...other very useful kwargs of plotly express like marginal="violin")
And really all that would be happening would be that this line:
sx.*(sisl_obj, x="z", y="neighs", color="species")
is converted into this other line:
px.*(sisl_obj.to_df(cols=["z", "neighs", "species"]), x="z", y="neighs", color="species")
I don't know, seems pretty exciting to me :)
Originally posted by @pfebrer96 in #218 (comment)