-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
DataFrame extraction from Geometry and friends #220
Comments
My part of the deal is ready for when this is implemented :) It's this simple: from functools import wraps
import plotly.express as px
from sisl._dispatcher import AbstractDispatch, ClassDispatcher
class WithSislManagement(AbstractDispatch):
def __init__(self, px):
self._obj = px
def dispatch(self, method):
@wraps(method)
def with_plot_update(*args, **kwargs):
if len(args) > 0:
# The first arg is the sisl object
args = list(args)
args[0] = args[0].to_df() #In fact, we should generate only the corresponding df
ret = method(*args, **kwargs)
return ret
return with_plot_update
sx = WithSislManagement(px) And this powerful (you can try it): import sisl
import pandas as pd
geom = sisl.geom.graphene_nanoribbon(20, atom=("N", "B"))
# Fake implementation of to_df
geom.to_df = lambda: pd.DataFrame({"x": geom.xyz[:,0], "y": geom.xyz[:,1], "z": geom.xyz[:,2],
"Z": geom.atom.Z, "tag": [atom.tag for atom in geom.atom]}) And the magic begins: sx.histogram(geom, x="x", color="tag", nbins=20, marginal="violin") sx.scatter(geom, x="x", y="y", size="y", color="tag", facet_col="tag") fig = sx.scatter_3d(geom, x="x", y="y", z="z", color="tag")
# Set aspect-ratio to 1:1:1
fig.update_layout(scene={"aspectmode": "data"}) Other cool keywords that you can play with: I hope that this visual demo can convince you of the capabilities and get you excited about it :) |
And by the way, this would also be supported by the GUI. |
I think we should rename this function to |
Yes, sure 👍 |
Yes this is solved for now 👍 |
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:
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 pandasDataFrame
, you define your plot as columns of this dataframe. An example of this: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 anyplotly.express
method. The possibilities would be endless with very simple code:And really all that would be happening would be that this line:
is converted into this other line:
I don't know, seems pretty exciting to me :)
Originally posted by @pfebrer96 in #218 (comment)
The text was updated successfully, but these errors were encountered: