Download IPython notebook here. Binder badge.

GitHub issues by-label

GeometryPlot

[1]:
import sisl
import sisl.viz
import numpy as np

First of all, we will create a geometry to work with

[2]:
geom = sisl.geom.graphene_nanoribbon(9)

GeometryPlot allows you to quickly visualize a geometry. You can create a GeometryPlot out of a geometry very easily:

[3]:
# GeometryPlot is the default plot of a geometry, so one can just do
plot = geom.plot()
info:0: SislInfo: The plot has been initialized correctly, but the current settings were not enough to generate the figure.
Error: The attribute 'data' was not found either in the plot, its backend, or in shared attributes.

Now let’s see what we got:

[4]:
plot
'<sisl.viz.plots.geometry.GeometryPlot object at 0x7f3e8a8ee440>'

Plotting in 3D, 2D and 1D

The 3D view is great, but for big geometries it can take some time to render. If we have a 2d material, a 2D view might be more practical instead. We can get it by specifying the axes that we want:

[5]:
plot.update_settings(axes="xy")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [5], in <module>
----> 1 plot.update_settings(axes="xy")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

The next section goes more in depth on what the axes setting accepts. The important part for now is that asking for two axes gets you a 2D representation. Samewise, asking for 1 axis gets you a 1D representation:

[6]:
plot.update_settings(axes="x")

Notice how asking for a 1D representation leaves the Y axis of the plot at your disposal. You can control the values in the second axis using the dataaxis_1d setting.

It can be an array that explicitly sets the values:

[7]:
plot.update_settings(axes="x", dataaxis_1d=plot.geometry.atoms.Z)

Or a function that accepts the projected coordinates and returns the values.

[8]:
plot.update_settings(dataaxis_1d=np.sin)

Asking for three axes would bring us back to the 3D representation:

[9]:
plot.update_settings(axes="xyz")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [9], in <module>
----> 1 plot.update_settings(axes="xyz")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Specifying the axes

There are many ways in which you may want to display the coordinates of your geometry. The most common one is to display the cartesian coordinates. You indicate that you want cartesian coordinates by passing (+-){"x", "y", "z"}. You can pass them as a list:

[10]:
plot.update_settings(axes=["x", "y"])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [10], in <module>
----> 1 plot.update_settings(axes=["x", "y"])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

But it is usually more convenient to pass them as a multicharacter string:

[11]:
plot.update_settings(axes="xy")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [11], in <module>
----> 1 plot.update_settings(axes="xy")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Notice that you can order axes in any way you want. The first one will go to the X axis of the plot, and the second to the Y axis:

[12]:
plot.update_settings(axes="yx")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [12], in <module>
----> 1 plot.update_settings(axes="yx")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

You are not limited to cartesian coordinates though. Passing (+-){"a", "b", "c"} will display the fractional coordinates:

[13]:
plot.update_settings(axes="ab")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [13], in <module>
----> 1 plot.update_settings(axes="ab")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

And you can also pass an arbitrary direction as an axis:

[14]:
plot.update_settings(axes=[[1,1,0], [1, -1, 0]])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [14], in <module>
----> 1 plot.update_settings(axes=[[1,1,0], [1, -1, 0]])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

In this case, we have projected the coordinates into the [1,1,0] and [1, -1, 0] directions. Notice that the modulus of the vector is important for the scaling. See for example what happens when we scale the second vector by a factor of two:

[15]:
plot.update_settings(axes=[[1,1,0], [2, -2, 0]])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [15], in <module>
----> 1 plot.update_settings(axes=[[1,1,0], [2, -2, 0]])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Finally, you can even mix the different possibilities!

[16]:
plot.update_settings(axes=["x", [1,1,0]])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [16], in <module>
----> 1 plot.update_settings(axes=["x", [1,1,0]])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

To summarize the different possibilities:

  • (+-){"x", "y", "z"}: The cartesian coordinates are displayed.

  • (+-){"a", "b", "c"}: The fractional coordinates are displayed. Same for {0,1,2}.

  • np.array of shape (3, ): The coordinates are projected into that direction. If two directions are passed, the coordinates are not projected to each axis separately. The displayed coordinates are then the coefficients of the linear combination to get that point (or the projection of that point into the plane formed by the two axes).

Some non-obvious behavior

Fractional coordinates are only displayed if all axes are lattice vectors. Otherwise, the plot works as if you had passed the direction of the lattice vector. Also, for now, the 3D representation only displays cartesian coordinates.

2D perspective

It is not trivial to notice that the axes you choose determine what is your point of view. For example, if you choose to view "xy", the z axis will be pointing “outside of the screen”, while if you had chosen "yx" the z axis will point “inside the screen”. This affects the depth of the atoms, i.e. which atoms are on top and which are on the bottom.

To visualize it, we build a bilayer of graphene and boron nitride:

[17]:
bilayer = sisl.geom.bilayer(top_atoms="C", bottom_atoms=["B", "N"], stacking="AA")

If we want to see the "xy" axes, we would be viewing the structure from the top:

[18]:
bilayer.plot(axes="xy")
info:0: SislInfo:

The plot has been initialized correctly, but the current settings were not enough to generate the figure.
Error: The attribute 'data' was not found either in the plot, its backend, or in shared attributes.

'<sisl.viz.plots.geometry.GeometryPlot object at 0x7f3e8037f070>'

but if we set the axes to yx, -xy or x-y, we will see it from the bottom:

[19]:
bilayer.plot(axes="-xy")
info:0: SislInfo:

The plot has been initialized correctly, but the current settings were not enough to generate the figure.
Error: The attribute 'data' was not found either in the plot, its backend, or in shared attributes.

'<sisl.viz.plots.geometry.GeometryPlot object at 0x7f3e8037e140>'

That is, we are flipping the geometry. In the above example we are doing it around the Y axis. Notice that trying to view ``xy`` from the ``-z`` perspective would show you a mirrored view of your structure!

Non-cartesian axes

The above behavior is also true for all valid axes that you can pass. However, we have made lattice vectors follow the same rules as cartesian vectors. That is, abc cross products follow the rules of xyz cross products. As a result, if you ask for axes="ab" you will see the structure from the c perspective.

Toggling bonds, atoms and cell

You might have noticed that, by default, the cell, atoms and bonds are displayed. Thanks to plotly’s capabilities, you can interactively toggle them by clicking at the names in the legend, which is great!

However, if you want to make sure they are not displayed in the first place, you can set the show_bonds, show_cell and show_atoms settings to False.

[20]:
plot.update_settings(axes="xy", show_cell=False, show_atoms=False)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [20], in <module>
----> 1 plot.update_settings(axes="xy", show_cell=False, show_atoms=False)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Picking which atoms to display

The atoms setting of GeometryPlot allows you to pick which atoms to display. It accepts exactly the same possibilities as the atoms argument in Geometry’s methods.

Therefore, you can ask for certain indices:

[21]:
plot.update_settings(atoms=[1,2,3,4,5], show_atoms=True, show_cell="axes")
#show_cell accepts "box", "axes" and False
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [21], in <module>
----> 1 plot.update_settings(atoms=[1,2,3,4,5], show_atoms=True, show_cell="axes")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

or use sisl categories to filter the atoms, for example.

We can use it to display only those atoms that have 3 neighbours:

[22]:
plot.update_settings(atoms={"neighbours": 3}, show_cell="box")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [22], in <module>
----> 1 plot.update_settings(atoms={"neighbours": 3}, show_cell="box")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Notice that when we picked particular atoms, only the bonds of those atoms are displayed. You can change this by using the bind_bonds_to_ats setting.

[23]:
plot.update_settings(bind_bonds_to_ats=False)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [23], in <module>
----> 1 plot.update_settings(bind_bonds_to_ats=False)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.
[24]:
plot = plot.update_settings(atoms=None, bind_bonds_to_ats=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [24], in <module>
----> 1 plot = plot.update_settings(atoms=None, bind_bonds_to_ats=True)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

In fact, when we set show_atoms to False, all that the plot does is to act as if atoms=[] and bind_bonds_to_ats=False.

Scaling atoms

In the following section you can find extensive detail about styling atoms, but if you just one a quick rescaling of all atoms, atoms_scale is your best ally. It is very easy to use:

[25]:
plot.update_settings(atoms_scale=0.6)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [25], in <module>
----> 1 plot.update_settings(atoms_scale=0.6)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.
[26]:
plot.update_settings(atoms_scale=1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [26], in <module>
----> 1 plot.update_settings(atoms_scale=1)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Custom styles for atoms.

It is quite common that you have an atom-resolved property that you want to display. With GeometryPlot this is extremely easy :)

All styles are controlled by the atoms_style setting. For example, if we want to color all atoms in green and with a size of 0.6 we can do it like this:

[27]:
plot.update_settings(atoms=None, axes="yx", atoms_style={"color": "green", "size": 14})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [27], in <module>
----> 1 plot.update_settings(atoms=None, axes="yx", atoms_style={"color": "green", "size": 14})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

In the following cell we show how these properties accept multiple values. In this case, we want to give different sizes to each atom. If the number of values passed is less than the number of atoms, the values are tiled:

[28]:
plot.update_settings(atoms_style={"color": "green", "size": [12, 20]})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [28], in <module>
----> 1 plot.update_settings(atoms_style={"color": "green", "size": [12, 20]})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

In this case, we have drawn atoms with alternating size of 0.6 and 0.8.

The best part about atoms_style is that you can very easily give different styles to selections of atoms. In this case, it is enough to pass a list of style specifications, including (optionally) the "atoms" key to select the atoms to which these styles will be applied:

[29]:
plot.update_settings(
    atoms_style=[
        {"color": "green", "size": [12, 20], "opacity": [1, 0.3]},
        {"atoms": [0,1], "color": "orange"}
    ]
)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [29], in <module>
----> 1 plot.update_settings(
      2     atoms_style=[
      3         {"color": "green", "size": [12, 20], "opacity": [1, 0.3]},
      4         {"atoms": [0,1], "color": "orange"}
      5     ]
      6 )

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Notice these aspects:

  • The first specification doesn’t contain "atoms", so it applies to all atoms.

  • Properties that were not specified for atoms [0, 1] are “inherited” from the previous specifications. For example, size of atoms 0 and 1 is still determined by the first style specification.

  • If some atom is selected in more than one specification, the last one remains, that’s why the color is finally set to orange for [0,1].

You don’t need to include general styles. For atoms that don’t have styles specified the defaults are used:

[30]:
plot.update_settings(atoms_style=[{"atoms": [0,1], "color": "orange"}])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [30], in <module>
----> 1 plot.update_settings(atoms_style=[{"atoms": [0,1], "color": "orange"}])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Finally, "atoms" accepts anything that Geometry can sanitize, so it can accept categories, for example. This is great because it gives you a great power to easily control complex styling situations:

[31]:
plot.update_settings(atoms_style=[
    {"atoms": {"fx": (None, 0.4)}, "color": "orange"},
    {"atoms": sisl.geom.AtomOdd(), "opacity":0.3},
])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [31], in <module>
----> 1 plot.update_settings(atoms_style=[
      2     {"atoms": {"fx": (None, 0.4)}, "color": "orange"},
      3     {"atoms": sisl.geom.AtomOdd(), "opacity":0.3},
      4 ])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

In this case, we color all atoms whose fractional X coordinate is below 0.4 (half the ribbon) in orange. We also give some transparency to odd atoms.

As a final remark, colors can also be passed as values. In this case, they are mapped to colors by a colorscale, specified in atoms_colorscale.

[32]:
# Get the Y coordinates
y = plot.geometry.xyz[:,1]
# And color atoms according to it
plot.update_settings(atoms_style=[
    {"color": y},
    {"atoms": sisl.geom.AtomOdd(), "opacity":0.3},
], atoms_colorscale="viridis")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [32], in <module>
      2 y = plot.geometry.xyz[:,1]
      3 # And color atoms according to it
----> 4 plot.update_settings(atoms_style=[
      5     {"color": y}, 
      6     {"atoms": sisl.geom.AtomOdd(), "opacity":0.3},
      7 ], atoms_colorscale="viridis")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Notice however that, for now, you can not mix values with strings and there is only one colorscale for all atoms.

Note that everything that we’ve done up to this moment is perfectly valid for the 3d view, we are just using the 2d view for convenience.

[33]:
plot.update_settings(axes="xyz")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [33], in <module>
----> 1 plot.update_settings(axes="xyz")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Custom styles for bonds

Just as atoms_style, there is a setting that allows you to tweak the styling of the bonds: bonds_style. Unlike atoms_style, for now only one style specification can be provided. That is, bonds_style only accepts a dictionary, not a list of dictionaries. The dictionary can contain the following keys: color, width and opacity, but you don’t need to provide all of them.

[34]:
plot.update_settings(axes="yx", bonds_style={"color": "orange", "width": 5, "opacity": 0.5})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [34], in <module>
----> 1 plot.update_settings(axes="yx", bonds_style={"color": "orange", "width": 5, "opacity": 0.5})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Coloring individual bonds

It is not possible to style bonds individually yet, e.g. using a colorscale. However, it is one of the goals to improve GeometryPlot and some thought has already been put into how to design the interface to make it as usable as possible. Rest assured that when the right interface is found, coloring individual bonds will be allowed, as well as drawing bicolor bonds, as most rendering softwares do.

[35]:
plot = plot.update_settings(axes="xyz", bonds_style={})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [35], in <module>
----> 1 plot = plot.update_settings(axes="xyz", bonds_style={})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Drawing arrows

It is very common that you want to display arrows on the atoms, to show some vector property such as a force or an electric field.

This can be specified quite easily in sisl with the arrows setting. All the information of the arrows that you want to draw is passed as a dictionary, where "data" is the most important key and there are other optional keys like name, color, width, scale, arrowhead_scale and arrowhead_angle that control the aesthetics.

[36]:
plot.update_settings(arrows={"data": [0,0,2], "name": "Upwards force"})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [36], in <module>
----> 1 plot.update_settings(arrows={"data": [0,0,2], "name": "Upwards force"})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Notice how we only provided one vector and it was used for all our atoms. We can either do that or pass all the data. Let’s build a fake forces array for the sake of this example:

[37]:
forces = np.linspace([0,0,2], [0,3,1], 18)
plot.update_settings(arrows={"data": forces, "name": "Force", "color": "orange", "width": 4})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [37], in <module>
      1 forces = np.linspace([0,0,2], [0,3,1], 18)
----> 2 plot.update_settings(arrows={"data": forces, "name": "Force", "color": "orange", "width": 4})

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Since there might be more than one vector property to display, you can also pass a list of arrow specifications, and each one will be drawn separately.

[38]:
plot.update_settings(arrows=[
    {"data": forces, "name": "Force", "color": "orange", "width": 4},
    {"data": [0,0,2], "name": "Upwards force", "color": "red"}
])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [38], in <module>
----> 1 plot.update_settings(arrows=[
      2     {"data": forces, "name": "Force", "color": "orange", "width": 4},
      3     {"data": [0,0,2], "name": "Upwards force", "color": "red"}
      4 ])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Much like we did in atoms_style, we can specify the atoms for which we want the arrow specification to take effect by using the "atoms" key.

[39]:
plot.update_settings(arrows=[
    {"data": forces, "name": "Force", "color": "orange", "width": 4},
    {"atoms": {"fy": (0, 0.5)} ,"data": [0,0,2], "name": "Upwards force", "color": "red"}
])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [39], in <module>
----> 1 plot.update_settings(arrows=[
      2     {"data": forces, "name": "Force", "color": "orange", "width": 4},
      3     {"atoms": {"fy": (0, 0.5)} ,"data": [0,0,2], "name": "Upwards force", "color": "red"}
      4 ])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:578, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    576 if self._ndim == 3:
    577     xaxis, yaxis, zaxis = axes
--> 578     backend_info = self._prepare3D(
    579         **atoms_kwargs, bonds_styles=bonds_style,
    580         bind_bonds_to_ats=bind_bonds_to_ats, **kwargs3d
    581     )
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1096, in GeometryPlot._prepare3D(self, wrap_atoms, wrap_bond, atoms, atoms_styles, bind_bonds_to_ats, atoms_scale, show_bonds, bonds_styles)
   1092 atoms_props["size"] *= atoms_scale
   1094 if show_bonds:
   1095     # Try to get the bonds colors (It might be that the user is not setting them)
-> 1096     bonds = self.bonds
   1097     if bind_bonds_to_ats:
   1098         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Finally, notice that in 2D and 1D views, and for axes other than {"x", "y", "z"}, the arrows get projected just as the rest of the coordinates:

[40]:
plot.update_settings(axes="yz")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [40], in <module>
----> 1 plot.update_settings(axes="yz")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1112, in Plot.set_data(self, update_fig, **kwargs)
   1104 @repeat_if_children
   1105 @vizplotly_settings('before')
   1106 def set_data(self, update_fig = True, **kwargs):
   1107     """ Method to process the data that has been read beforehand by read_data() and prepare the figure
   1108
   1109     If everything is succesful, it calls the next step in plotting (`get_figure`)
   1110     """
-> 1112     self._for_backend = self._set_data()
   1114     if update_fig:
   1115         self.get_figure()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:584, in GeometryPlot._set_data(self, axes, atoms, atoms_style, atoms_scale, atoms_colorscale, show_atoms, bind_bonds_to_ats, bonds_style, arrows, dataaxis_1d, show_cell, cell_style, nsc, kwargs3d, kwargs2d, kwargs1d)
    582 elif self._ndim == 2:
    583     xaxis, yaxis = axes
--> 584     backend_info = self._prepare2D(
    585         xaxis=xaxis, yaxis=yaxis, bonds_styles=bonds_style, **atoms_kwargs,
    586         bind_bonds_to_ats=bind_bonds_to_ats, nsc=nsc, **kwargs2d
    587     )
    588 elif self._ndim == 1:
    589     xaxis = axes[0]

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:1022, in GeometryPlot._prepare2D(self, xaxis, yaxis, atoms, atoms_styles, atoms_scale, show_bonds, bonds_styles, bind_bonds_to_ats, points_per_bond, wrap_atoms, wrap_bond, nsc)
   1018 # Add bonds
   1019 if show_bonds:
   1020     # Define the actual bonds that we are going to draw depending on which
   1021     # atoms are requested
-> 1022     bonds = self.bonds
   1023     if bind_bonds_to_ats:
   1024         bonds = self._get_atoms_bonds(bonds, self._tiled_atoms(atoms))

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'bonds' was not found either in the plot, its backend, or in shared attributes.

Coloring individual atoms

It is still not possible to color arrows individually, e.g. using a colorscale. Future developments will probably work towards this goal.

Drawing supercells

All the functionality showcased in this notebook is compatible with displaying supercells. The number of supercells displayed in each direction is controlled by the nsc setting:

[41]:
plot.update_settings(axes="xyz", nsc=[2,1,1])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [41], in <module>
----> 1 plot.update_settings(axes="xyz", nsc=[2,1,1])

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:437, in ConfigurableMeta.__new__.<locals>.update_settings(self, *args, **kwargs)
    436 def update_settings(self, *args, **kwargs):
--> 437     return self._update_settings(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:558, in Configurable._update_settings(self, run_updates, **kwargs)
    556     #Do things after updating the settings
    557     if len(self.settings_history.last_updated) > 0 and run_updates:
--> 558         self._run_updates(self.settings_history.last_updated)
    560 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:586, in Configurable._run_updates(self, for_keys)
    584 # Execute the functions that we need to execute.
    585 for f_name in func_names:
--> 586     getattr(self, f_name)()
    588 return self

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:829, in repeat_if_children.<locals>.apply_to_all_plots(obj, children_sel, *args, **kwargs)
    825     obj.get_figure()
    827 else:
--> 829     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:888, in vizplotly_settings.<locals>.decorator.<locals>.func(obj, *args, **kwargs)
    885 @wraps(method)
    886 def func(obj, *args, **kwargs):
    887     getattr(obj, method_name)(**kwargs, **extra_kwargs)
--> 888     return method(obj, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:777, in Plot.read_data(self, update_fig, **kwargs)
    774 if self.source is None:
    775     self.last_dataread = 0
--> 777 call_method_if_present(self, "_after_read")
    779 if self.source is not None:
    780     self.last_dataread = time.time()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plotutils.py:430, in call_method_if_present(obj, method_name, *args, **kwargs)
    428 method = getattr(obj, method_name, None)
    429 if callable(method):
--> 430     return method(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:440, in GeometryPlot._after_read(self, show_bonds, nsc)
    437     self._tiled_geometry = self._tiled_geometry.tile(reps, ax)
    439 if show_bonds:
--> 440     self.bonds = self.find_all_bonds(self._tiled_geometry)
    442 self.get_param("atoms").update_options(self.geometry)
    443 self.get_param("atoms_style").get_param("atoms").update_options(self.geometry)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/configurable.py:969, in _populate_with_settings.<locals>.f_default_setting_args(self, *args, **kwargs)
    966         except KeyError:
    967             pass
--> 969 return f(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plots/geometry.py:683, in GeometryPlot.find_all_bonds(geometry, tol)
    681 bonds = []
    682 for at in geometry:
--> 683     neighs = geometry.close(at, R=[0.1, 3])[-1]
    685     for neigh in neighs[neighs > at]:
    686         summed_radius = pt.radius([abs(geometry.atoms[at].Z), abs(geometry.atoms[neigh % geometry.na].Z)]).sum()

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:727, in Plot.__getattr__(self, key)
    724     except (KeyError, AttributeError):
    725         pass
--> 727 raise AttributeError(f"The attribute '{key}' was not found either in the plot, its backend, or in shared attributes.")

AttributeError: The attribute 'close' was not found either in the plot, its backend, or in shared attributes.

Notice however that you can’t specify different styles or arrows for the supercell atoms, they are just copied! Since what we are displaying here are supercells of a periodic system, this should make sense. If you want your supercells to have different specifications, tile the geometry before creating the plot.


This next cell is just to create the thumbnail for the notebook in the docs

[42]:
thumbnail_plot = plot

if thumbnail_plot:
    thumbnail_plot.show("png")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [42], in <module>
      1 thumbnail_plot = plot
      3 if thumbnail_plot:
----> 4     thumbnail_plot.show("png")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1180, in Plot.show(self, listen, return_figWidget, *args, **kwargs)
   1177     except Exception as e:
   1178         warn(e)
-> 1180 return self._backend.show(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/backends/plotly/backend.py:42, in PlotlyBackend.show(self, *args, **kwargs)
     41 def show(self, *args, **kwargs):
---> 42     return self.figure.show(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/basedatatypes.py:3398, in BaseFigure.show(self, *args, **kwargs)
   3365 """
   3366 Show a figure using either the default renderer(s) or the renderer(s)
   3367 specified by the renderer argument
   (...)
   3394 None
   3395 """
   3396 import plotly.io as pio
-> 3398 return pio.show(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_renderers.py:389, in show(fig, renderer, validate, **kwargs)
    386 fig_dict = validate_coerce_fig_to_dict(fig, validate)
    388 # Mimetype renderers
--> 389 bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
    390 if bundle:
    391     if not ipython_display:

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_renderers.py:297, in RenderersConfig._build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
    294             if hasattr(renderer, k):
    295                 setattr(renderer, k, v)
--> 297         bundle.update(renderer.to_mimebundle(fig_dict))
    299 return bundle

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_base_renderers.py:128, in ImageRenderer.to_mimebundle(self, fig_dict)
    127 def to_mimebundle(self, fig_dict):
--> 128     image_bytes = to_image(
    129         fig_dict,
    130         format=self.format,
    131         width=self.width,
    132         height=self.height,
    133         scale=self.scale,
    134         validate=False,
    135         engine=self.engine,
    136     )
    138     if self.b64_encode:
    139         image_str = base64.b64encode(image_bytes).decode("utf8")

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_kaleido.py:134, in to_image(fig, format, width, height, scale, validate, engine)
    132     # Raise informative error message if Kaleido is not installed
    133     if scope is None:
--> 134         raise ValueError(
    135             """
    136 Image export using the "kaleido" engine requires the kaleido package,
    137 which can be installed using pip:
    138     $ pip install -U kaleido
    139 """
    140         )
    142     # Validate figure
    143     # ---------------
    144     fig_dict = validate_coerce_fig_to_dict(fig, validate)

ValueError:
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
    $ pip install -U kaleido