Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix matplotlib deprecation #69

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/spherical_harmonics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
" n, m = spharpy.spherical.acn2nm(acn)\n",
" idx_m = int(np.floor(n_max/2+1)) + m\n",
" ax = plt.subplot(gs[n, idx_m], projection='3d')\n",
" balloon = spharpy.plot.balloon_wireframe(sampling, Y[:, acn], phase=True, show=False, colorbar=False, ax=ax)\n",
" balloon = spharpy.plot.balloon_wireframe(sampling, Y[:, acn], phase=True, colorbar=False, ax=ax)\n",
" ax.set_title('$Y_{' + str(n) + '}^{' + str(m) + '}(\\\\theta, \\\\phi)$')\n",
" plt.axis('off')\n",
" cax = plt.subplot(gs[n_max+1, :])\n",
Expand Down Expand Up @@ -376,7 +376,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions spharpy/plot/cmap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from matplotlib import cm
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np

Expand All @@ -8,7 +8,7 @@ def phase_twilight(lut=512):
version of the twilight color map from matplotlib.
"""
lut = int(np.ceil(lut/4)*4)
twilight = cm.get_cmap('twilight', lut=lut)
twilight = plt.get_cmap('twilight', lut=lut)

twilight_r_colors = np.array(twilight.reversed().colors)

Expand Down
47 changes: 7 additions & 40 deletions spharpy/plot/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.tri as mtri
import numpy as np
import scipy.spatial as sspat
from matplotlib import cm, colors
from matplotlib import colors
from mpl_toolkits.mplot3d import Axes3D
__all__ = [Axes3D]
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
Expand Down Expand Up @@ -70,8 +70,6 @@ def scatter(coordinates, ax=None):
np.ptp(coordinates.y),
np.ptp(coordinates.z)])

plt.show()


def _triangulation_sphere(sampling, data):
"""Triangulation for data points sampled on a spherical surface.
Expand Down Expand Up @@ -222,7 +220,6 @@ def pcolor_sphere(
data,
cmap=None,
colorbar=True,
show=True,
phase=False,
ax=None,
*args,
Expand Down Expand Up @@ -250,8 +247,6 @@ def pcolor_sphere(
ax : matplotlib.axis, None, optional
The matplotlib axis object used for plotting. By default `None`, which
will create a new axis object.
show : boolean, optional
Whether to show the figure or not

""" # noqa: 501
coordinates = convert_coordinates(coordinates)
Expand All @@ -272,7 +267,7 @@ def pcolor_sphere(
else:
itype = 'amplitude'
if cmap is None:
cmap = cm.viridis
cmap = plt.get_cmap('viridis')
clabel = 'Amplitude'

cdata, vmin, vmax = _balloon_color_data(tri, data, itype)
Expand All @@ -298,9 +293,6 @@ def pcolor_sphere(
np.ptp(coordinates.y),
np.ptp(coordinates.z)])

if show:
plt.show()

return plot


Expand All @@ -309,7 +301,6 @@ def balloon_wireframe(
data,
cmap=None,
phase=False,
show=True,
colorbar=True,
ax=None):
"""Plot data on a sphere defined by the coordinate angles
Expand All @@ -334,8 +325,6 @@ def balloon_wireframe(
phase : boolean, optional
Encode the phase of the data in the colormap. This option will be
activated by default of the data is complex valued.
show : boolean, optional
Whether to show the figure or not
""" # noqa: 501
coordinates = convert_coordinates(coordinates)
tri, xyz = _triangulation_sphere(coordinates, data)
Expand All @@ -355,7 +344,7 @@ def balloon_wireframe(
else:
itype = 'amplitude'
if cmap is None:
cmap = cm.viridis
cmap = plt.get_cmap('viridis')
clabel = 'Amplitude'

cdata, vmin, vmax = _balloon_color_data(tri, data, itype)
Expand Down Expand Up @@ -389,9 +378,6 @@ def balloon_wireframe(
np.ptp(xyz[1]),
np.ptp(xyz[2])])

if show:
plt.show()

plot.set_facecolor([0.9, 0.9, 0.9, 0.9])

return plot
Expand All @@ -402,7 +388,6 @@ def balloon(
data,
cmap=None,
phase=False,
show=True,
colorbar=True,
ax=None,
*args,
Expand Down Expand Up @@ -430,8 +415,6 @@ def balloon(
phase : boolean, optional
Encode the phase of the data in the colormap. This option will be
activated by default of the data is complex valued.
show : boolean, optional
Wheter to show the figure or not
""" # noqa: 501
coordinates = convert_coordinates(coordinates)

Expand All @@ -452,7 +435,7 @@ def balloon(
else:
itype = 'amplitude'
if cmap is None:
cmap = cm.viridis
cmap = plt.get_cmap('viridis')
clabel = 'Amplitude'

cdata, vmin, vmax = _balloon_color_data(tri, data, itype)
Expand Down Expand Up @@ -480,9 +463,6 @@ def balloon(
ax.set_ylabel('y[m]')
ax.set_zlabel('z[m]')

if show:
plt.show()

return plot


Expand Down Expand Up @@ -597,7 +577,6 @@ def pcolor_map(
projection='mollweide',
limits=None,
cmap=plt.get_cmap('viridis'),
show=True,
refine=False,
ax=None,
**kwargs):
Expand All @@ -617,8 +596,6 @@ def pcolor_map(
data: ndarray, double
Data for each angle, must have size corresponding to the number of
points given in coordinates.
show : boolean, optional
Wheter to show the figure or not

""" # noqa: 501
coordinates = convert_coordinates(coordinates)
Expand Down Expand Up @@ -665,8 +642,6 @@ def pcolor_map(
plt.grid(True)
cb = fig.colorbar(cf, ax=ax, extend=extend)
cb.set_label('Amplitude')
if show:
plt.show()

return cf

Expand All @@ -676,9 +651,8 @@ def contour_map(
data,
projection='mollweide',
limits=None,
cmap=cm.viridis,
cmap=plt.get_cmap('viridis'),
colorbar=True,
show=True,
levels=None,
ax=None):
"""
Expand All @@ -699,8 +673,6 @@ def contour_map(
data: ndarray, double
Data for each angle, must have size corresponding to the number of
points given in coordinates.
show : boolean, optional
Wheter to show the figure or not

"""
coordinates = convert_coordinates(coordinates)
Expand Down Expand Up @@ -750,14 +722,13 @@ def contour_map(
if colorbar:
cb = fig.colorbar(cf, ax=ax, ticks=levels)
cb.set_label('Amplitude')
if show:
plt.show()

return cf


def contour(
coordinates, data, limits=None, cmap=cm.viridis, show=True, ax=None):
coordinates, data, limits=None, cmap=plt.get_cmap('viridis'),
ax=None):
"""
Plot the map projection of data points sampled on a spherical surface.
The data has to be real-valued.
Expand All @@ -774,8 +745,6 @@ def contour(
data: ndarray, double
Data for each angle, must have size corresponding to the number of
points given in coordinates.
show : boolean, optional
Wheter to show the figure or not

""" # noqa: 501
coordinates = convert_coordinates(coordinates)
Expand All @@ -792,8 +761,6 @@ def contour(
plt.grid(True)
cb = fig.colorbar(cf, ax=ax)
cb.set_label('Amplitude')
if show:
plt.show()

return cf

Expand Down
6 changes: 3 additions & 3 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def test_balloon_plot(icosahedron, make_coordinates, implementation):
coords = make_coordinates.create_coordinates(
implementation, rad, theta, phi)
data = np.cos(phi)*np.sin(theta)
spharpy.plot.balloon(coords, data, show=False)
spharpy.plot.balloon(coords, data)

spharpy.plot.balloon(coords, data, phase=True, show=False)
spharpy.plot.balloon(coords, data, phase=True)


@pytest.mark.parametrize("implementation", ['spharpy', 'pyfar'])
Expand All @@ -31,7 +31,7 @@ def test_contour_plot(icosahedron, make_coordinates, implementation):
implementation, rad, theta, phi)
data = np.cos(phi)*np.sin(theta)

spharpy.plot.contour(coords, np.abs(data), show=False)
spharpy.plot.contour(coords, np.abs(data))


@pytest.mark.parametrize("implementation", ['spharpy', 'pyfar'])
Expand Down