FatbandsPlot
[1]:
import sisl
import sisl.viz
For this notebook we will create a toy “Boron nitride” tight binding:
[2]:
# First, we create the geometry
BN = sisl.geom.graphene(atoms=["B", "N"])
# Create a hamiltonian with different on-site terms
H = sisl.Hamiltonian(BN)
H[0, 0] = 2
H[1, 1] = -2
H[0, 1] = -2.7
H[1, 0] = -2.7
H[0, 1, (-1, 0)] = -2.7
H[0, 1, (0, -1)] = -2.7
H[1, 0, (1, 0)] = -2.7
H[1, 0, (0, 1)] = -2.7
Note that we could have obtained this hamiltonian from any other source. Then we generate a path for the band structure:
[3]:
band = sisl.BandStructure(H, [[0., 0.], [2./3, 1./3],
[1./2, 1./2], [1., 1.]], 301,
[r'$\Gamma$', 'K', 'M', r'$\Gamma$'])
And finally we just ask for the fatbands plot:
[4]:
fatbands = band.plot.fatbands()
fatbands
We only see the bands here, but this is a fatbands plot, and it is ready to accept your requests on what to draw!
Requesting specific weights
The fatbands that the plot draws are controlled by the groups
setting.
[5]:
print(fatbands.get_param("groups").help)
The different groups that are displayed in the fatbands
Each item is a dict.
Structure of the dict: {
'name':
'species':
'atoms':
Structure of the dict: {
'index':
Structure of the dict: {
'in':
}
'fx':
'fy':
'fz':
'x':
'y':
'z':
'Z':
'neighbours':
Structure of the dict: {
'range':
'R':
'neigh_tag':
}
'tag':
'seq':
}
'orbitals':
'spin':
'normalize':
'color':
'scale':
}
This setting works exactly like the requests
setting in PdosPlot
, which is documented here. Therefore we won’t give an extended description of it, but just quickly show that you can autogenerate the groups:
[6]:
fatbands.split_groups(on="species")
Or write them yourself if you want the maximum flexibility:
[7]:
fatbands.update_settings(groups=[
{"species": "N", "color": "blue", "name": "Nitrogen"},
{"species": "B", "color": "red", "name": "Boron"}
])
Scaling fatbands
The visual appeal of fatbands depends a lot on the size of your plot, therefore there’s one global scale
setting that scales all fatbands at the same time:
[8]:
fatbands.update_settings(scale=2)
You can also use the scale_fatbands
method, which additionally lets you choose if you want to rescale from the current size or just set the value of scale
:
[9]:
fatbands.scale_fatbands(0.5, from_current=True)
Use BandsPlot settings
All settings of BandsPlot
work as well for FatbandsPlot
. Even spin texture!
We hope you enjoyed what you learned!
This next cell is just to create the thumbnail for the notebook in the docs
[10]:
thumbnail_plot = fatbands
if thumbnail_plot:
thumbnail_plot.show("png")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [10], in <cell line: 3>()
1 thumbnail_plot = fatbands
3 if thumbnail_plot:
----> 4 thumbnail_plot.show("png")
File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.2/sisl/viz/plot.py:1176, in Plot.show(self, listen, return_figWidget, *args, **kwargs)
1173 except Exception as e:
1174 warn(e)
-> 1176 return self._backend.show(*args, **kwargs)
File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.2/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.2/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.2/lib/python3.10/site-packages/plotly/io/_renderers.py:388, in show(fig, renderer, validate, **kwargs)
385 fig_dict = validate_coerce_fig_to_dict(fig, validate)
387 # Mimetype renderers
--> 388 bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
389 if bundle:
390 if not ipython_display:
File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.2/lib/python3.10/site-packages/plotly/io/_renderers.py:296, in RenderersConfig._build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
293 if hasattr(renderer, k):
294 setattr(renderer, k, v)
--> 296 bundle.update(renderer.to_mimebundle(fig_dict))
298 return bundle
File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.2/lib/python3.10/site-packages/plotly/io/_base_renderers.py:127, in ImageRenderer.to_mimebundle(self, fig_dict)
126 def to_mimebundle(self, fig_dict):
--> 127 image_bytes = to_image(
128 fig_dict,
129 format=self.format,
130 width=self.width,
131 height=self.height,
132 scale=self.scale,
133 validate=False,
134 engine=self.engine,
135 )
137 if self.b64_encode:
138 image_str = base64.b64encode(image_bytes).decode("utf8")
File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.2/lib/python3.10/site-packages/plotly/io/_kaleido.py:133, in to_image(fig, format, width, height, scale, validate, engine)
131 # Raise informative error message if Kaleido is not installed
132 if scope is None:
--> 133 raise ValueError(
134 """
135 Image export using the "kaleido" engine requires the kaleido package,
136 which can be installed using pip:
137 $ pip install -U kaleido
138 """
139 )
141 # Validate figure
142 # ---------------
143 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