Skip to content

Commit

Permalink
Merge pull request #753 from zerothi/removeplot
Browse files Browse the repository at this point in the history
removed sisl.plot from the code base
  • Loading branch information
zerothi authored Apr 18, 2024
2 parents f8a90fe + 7da0684 commit 71360c5
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 347 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ we hit release version 1.0.0.
be done for assigning matrix elements (it fills with 0's).

### Removed
- `sisl.plot` is removed (`sisl.viz` is replacing it!)
- `cell` argument for `Geometry.translate/move` (it never worked)
- removed `Selector` and `TimeSelector`, they were never used internally

Expand Down
3 changes: 0 additions & 3 deletions src/sisl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@
# import the common options used
from ._common import *

# Import plot routine
from ._plot import plot as plot

# Import warning classes
# We currently do not import warn and info
# as they are too generic names in case one does from sisl import *
Expand Down
76 changes: 0 additions & 76 deletions src/sisl/_core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
)

import sisl._array as _a
import sisl._plot as plt
from sisl._category import Category, GenericCategory
from sisl._dispatch_class import _Dispatchs
from sisl._dispatcher import AbstractDispatch, ClassDispatcher, TypeDispatcher
Expand Down Expand Up @@ -3112,81 +3111,6 @@ def o2sc(self, orbitals: OrbitalsIndex) -> ndarray:
"""
return self.lattice.offset(self.o2isc(orbitals))

def __plot__(
self,
axis=None,
lattice: bool = True,
axes=False,
atom_indices: bool = False,
*args,
**kwargs,
):
"""Plot the geometry in a specified ``matplotlib.Axes`` object.
Parameters
----------
axis : array_like, optional
only plot a subset of the axis, defaults to all axis
lattice : bool, optional
If `True` also plot the lattice structure
atom_indices : bool, optional
if true, also add atomic numbering in the plot (0-based)
axes : bool or matplotlib.Axes, optional
the figure axes to plot in (if ``matplotlib.Axes`` object).
If `True` it will create a new figure to plot in.
If `False` it will try and grap the current figure and the current axes.
"""
# Default dictionary for passing to newly created figures
d = dict()

colors = np.linspace(0, 1, num=self.atoms.nspecies, endpoint=False)
colors = colors[self.atoms.species]
if "s" in kwargs:
area = kwargs.pop("s")
else:
area = _a.arrayd(self.atoms.Z)
area[:] *= 20 * np.pi / area.min()

if axis is None:
axis = [0, 1, 2]

# Ensure we have a new 3D Axes3D
if len(axis) == 3:
d["projection"] = "3d"

# The Geometry determines the axes, then we pass it to supercell.
axes = plt.get_axes(axes, **d)

# Start by plotting the supercell
if lattice:
axes = self.lattice.__plot__(axis, axes=axes, *args, **kwargs)

# Create short-hand
xyz = self.xyz

if axes.__class__.__name__.startswith("Axes3D"):
# We should plot in 3D plots
axes.scatter(xyz[:, 0], xyz[:, 1], xyz[:, 2], s=area, c=colors, alpha=0.8)
axes.set_zlabel("Ang")
if atom_indices:
for i, loc in enumerate(xyz):
axes.text(
loc[0], loc[1], loc[2], str(i), verticalalignment="bottom"
)

else:
axes.scatter(xyz[:, axis[0]], xyz[:, axis[1]], s=area, c=colors, alpha=0.8)
if atom_indices:
for i, loc in enumerate(xyz):
axes.text(
loc[axis[0]], loc[axis[1]], str(i), verticalalignment="bottom"
)

axes.set_xlabel("Ang")
axes.set_ylabel("Ang")

return axes

def equal(self, other: GeometryLike, R: bool = True, tol: float = 1e-4) -> bool:
"""Whether two geometries are the same (optional not check of the orbital radius)
Expand Down
67 changes: 0 additions & 67 deletions src/sisl/_core/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from numpy import dot, ndarray

import sisl._array as _a
import sisl._plot as plt
from sisl._dispatch_class import _Dispatchs
from sisl._dispatcher import AbstractDispatch, ClassDispatcher, TypeDispatcher
from sisl._internal import set_module
Expand Down Expand Up @@ -1062,72 +1061,6 @@ def __setstate__(self, d):
self.__init__(d["cell"], d["nsc"], d["origin"])
self.sc_off = d["sc_off"]

def __plot__(self, axis=None, axes=False, *args, **kwargs):
"""Plot the supercell in a specified ``matplotlib.Axes`` object.
Parameters
----------
axis : array_like, optional
only plot a subset of the axis, defaults to all axis
axes : bool or matplotlib.Axes, optional
the figure axes to plot in (if ``matplotlib.Axes`` object).
If ``True`` it will create a new figure to plot in.
If ``False`` it will try and grap the current figure and the current axes.
"""
# Default dictionary for passing to newly created figures
d = dict()

# Try and default the color and alpha
if "color" not in kwargs and len(args) == 0:
kwargs["color"] = "k"
if "alpha" not in kwargs:
kwargs["alpha"] = 0.5

if axis is None:
axis = [0, 1, 2]

# Ensure we have a new 3D Axes3D
if len(axis) == 3:
d["projection"] = "3d"

axes = plt.get_axes(axes, **d)

# Create vector objects
o = self.origin
v = []
for a in axis:
v.append(np.vstack((o[axis], o[axis] + self.cell[a, axis])))
v = np.array(v)

if axes.__class__.__name__.startswith("Axes3D"):
# We should plot in 3D plots
for vv in v:
axes.plot(vv[:, 0], vv[:, 1], vv[:, 2], *args, **kwargs)

v0, v1 = v[0], v[1] - o
axes.plot(
v0[1, 0] + v1[:, 0],
v0[1, 1] + v1[:, 1],
v0[1, 2] + v1[:, 2],
*args,
**kwargs,
)

axes.set_zlabel("Ang")

else:
for vv in v:
axes.plot(vv[:, 0], vv[:, 1], *args, **kwargs)

v0, v1 = v[0], v[1] - o[axis]
axes.plot(v0[1, 0] + v1[:, 0], v0[1, 1] + v1[:, 1], *args, **kwargs)
axes.plot(v1[1, 0] + v0[:, 0], v1[1, 1] + v0[:, 1], *args, **kwargs)

axes.set_xlabel("Ang")
axes.set_ylabel("Ang")

return axes


new_dispatch = Lattice.new
to_dispatch = Lattice.to
Expand Down
47 changes: 0 additions & 47 deletions src/sisl/_core/orbital.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from scipy.interpolate import UnivariateSpline

import sisl._array as _a
import sisl._plot as plt
from sisl._internal import set_module
from sisl.constant import a0
from sisl.messages import warn
Expand Down Expand Up @@ -279,52 +278,6 @@ def equal(self, other, psi: bool = False, radial: bool = False):
def __eq__(self, other):
return self.equal(other)

def __plot__(self, harmonics: bool = False, axes=False, *args, **kwargs):
"""Plot the orbital radial/spherical harmonics
Parameters
----------
harmonics : bool, optional
if `True` the spherical harmonics will be plotted in a 3D only plot a subset of the axis, defaults to all axis
axes : bool or matplotlib.Axes, optional
the figure axes to plot in (if ``matplotlib.Axes`` object).
If ``True`` it will create a new figure to plot in.
If ``False`` it will try and grap the current figure and the current axes.
"""
d = dict()

if harmonics:
# We are plotting the harmonic part
d["projection"] = "polar"

axes = plt.get_axes(axes, **d)

# Add plots
if harmonics:
# Calculate the spherical harmonics
theta, phi = np.meshgrid(np.arange(360), np.arange(180) - 90)
s = self.spher(np.radians(theta), np.radians(phi))

# Plot data
cax = axes.contourf(theta, phi, s, *args, **kwargs)
cax.set_clim(s.min(), s.max())
axes.get_figure().colorbar(cax)
axes.set_title(r"${}$".format(self.name(True)))
# I don't know how exactly to handle this...
# axes.set_xlabel(r"Azimuthal angle $\theta$")
# axes.set_ylabel(r"Polar angle $\phi$")

else:
# Plot the radial function and 5% above 0 value
r = np.linspace(0, self.R * 1.05, 1000)
f = self.radial(r)
axes.plot(r, f, *args, **kwargs)
axes.set_xlim(left=0)
axes.set_xlabel("Radius [Ang]")
axes.set_ylabel(r"$f(r)$ [1/Ang$^{3/2}$]")

return axes

def toGrid(
self, precision: float = 0.05, c: float = 1.0, R=None, dtype=np.float64, atom=1
):
Expand Down
56 changes: 0 additions & 56 deletions src/sisl/_plot.py

This file was deleted.

Loading

0 comments on commit 71360c5

Please sign in to comment.