Visualization#
Note
There are much better visualization software exist and wulfric is not intended to be used as one. simple visualization capabilities were written historically for quick debugging and later on used for the automatic creation of the examples in the Bravais lattices pages.
For the full technical reference see wulfric.visualization
More examples of the plots with the code snippets can be found in the Bravais lattices guide. All interactive plots there are created with plotly backend.
In the examples on this page we assume that wulfric is imported as
>>> import wulfric as wulf
And an example cell of the hexagonal lattice is created as
>>> cell = wulf.cell.HEX(2, 1)
Each backend is invoked as any other object in Python:
>>> mb = MatplotlibBackend()
>>> pb = PlotlyBackend()
Plotting with Plotly#
Plotly is considered to be the main plotting backend.
The creation of the plotly backend can take one optional argument: fig
:
>>> from plotly import graph_objects as go
>>> fig = go.Figure()
>>> pb = PlotlyBackend(fig=fig)
The typical usage scenario is to plot one or several cells and then show or save the figure:
>>> pb.plot(cell, kind="brillouin", label="Brillouin zone", color="red")
>>> pb.plot(cell, kind="kpath", label="K-path", color="black")
>>> pb.save('hex_cell.html')
>>> pb.show()
Plotting with Matplotlib#
matplotlib is considered to be the secondary plotting backend.
The creation of the matplotlib backend can take one optional arguments: fig
and ax
:
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure(figsize=(6, 6))
>>> ax = fig.add_subplot(projection="3d")
>>> mb = MatplotlibBackend(fig=fig, ax=ax)
The typical workflow consist in plotting one or several lattices and then showing or saving the figure:
>>> mb.plot(cell, kind="brillouin", label="Brillouin zone", color="red")
>>> mb.plot(cell, kind="kpath", label="K-path", color="black")
>>> mb.save('hex_cell.png')
>>> mb.show()