Skip to content

Commit 85cd138

Browse files
authored
Merge pull request #221 from ppsp-team/fix-matplotlib-colormap-api
Fix deprecated matplotlib.cm.get_cmap() calls for compatibility with …
2 parents 4be03a7 + f06fb71 commit 85cd138

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

hypyp/viz.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,11 @@ def plot_bezier_curve(x1, y1, x2, y2, ctr1, ctr2, color, weight, steps):
805805
threshold = threshold
806806

807807
# define colormap
808-
cmap_p = matplotlib.cm.get_cmap('Reds')
808+
cmap_p = matplotlib.colormaps['Reds']
809+
809810
norm_p = matplotlib.colors.Normalize(vmin=threshold, vmax=np.nanmax(C[:]))
810-
cmap_n = matplotlib.cm.get_cmap('Blues_r')
811+
cmap_n = matplotlib.colormaps['Blues_r']
812+
811813
norm_n = matplotlib.colors.Normalize(vmin=np.min(C[:]), vmax=-threshold)
812814

813815
# plot links
@@ -955,9 +957,10 @@ def plot_bezier_curve(x1, y1, x2, y2, ctr, color, weight, steps):
955957
threshold = threshold
956958

957959
# Define colormap for both participants
958-
cmap_p = matplotlib.cm.get_cmap('Reds')
960+
cmap_p = matplotlib.colormaps['Reds']
961+
959962
norm_p = matplotlib.colors.Normalize(vmin=threshold, vmax=vmax)
960-
cmap_n = matplotlib.cm.get_cmap('Blues_r')
963+
cmap_n = matplotlib.colormaps['Blues_r']
961964
norm_n = matplotlib.colors.Normalize(vmin=vmin, vmax=-threshold)
962965

963966
# plot links for participant 1
@@ -1113,9 +1116,10 @@ def plot_bezier_curve_3d(x1, y1, z1, x2, y2, z2, ctr1, ctr2, color, weight, step
11131116
threshold = threshold
11141117

11151118
# define colormap
1116-
cmap_p = matplotlib.cm.get_cmap('Reds')
1119+
cmap_p = matplotlib.colormaps['Reds']
1120+
11171121
norm_p = matplotlib.colors.Normalize(vmin=threshold, vmax=np.nanmax(C[:]))
1118-
cmap_n = matplotlib.cm.get_cmap('Blues_r')
1122+
cmap_n = matplotlib.colormaps['Blues_r']
11191123
norm_n = matplotlib.colors.Normalize(vmin=np.min(C[:]), vmax=-threshold)
11201124

11211125
# plot links
@@ -1274,9 +1278,10 @@ def plot_bezier_curve_3d(x1, y1, z1, x2, y2, z2, ctr1, ctr2, color, weight, step
12741278
threshold = threshold
12751279

12761280
# Define colormap for both participant
1277-
cmap_p = matplotlib.cm.get_cmap('Reds')
1281+
cmap_p = matplotlib.colormaps['Reds']
1282+
12781283
norm_p = matplotlib.colors.Normalize(vmin=threshold, vmax=vmax)
1279-
cmap_n = matplotlib.cm.get_cmap('Blues_r')
1284+
cmap_n = matplotlib.colormaps['Blues_r']
12801285
norm_n = matplotlib.colors.Normalize(vmin=vmin, vmax=-threshold)
12811286

12821287
for e1 in range(len(loc1)):
@@ -2481,23 +2486,26 @@ def plot_xwt(sig1: mne.Epochs, sig2: mne.Epochs,
24812486
data = xwt(sig1, sig2, sfreq, freqs, analysis='phase')
24822487
analysis_title = 'Cross Wavelet Transform (Phase Angle)'
24832488
cbar_title = 'Phase Difference'
2484-
my_cm = matplotlib.cm.get_cmap('hsv')
2489+
my_cm = matplotlib.colormaps['hsv']
2490+
24852491
plt.imshow(data, aspect='auto', cmap=my_cm, interpolation='nearest')
24862492

24872493
elif analysis == 'power':
24882494
data = xwt(sig1, sig2, sfreq, freqs, analysis='power')
24892495
normed_data = (data - np.min(data)) / (np.max(data) - np.min(data))
24902496
analysis_title = 'Cross Wavelet Transform (Power)'
24912497
cbar_title = 'Cross Power'
2492-
my_cm = matplotlib.cm.get_cmap('viridis')
2498+
my_cm = matplotlib.colormaps['viridis']
2499+
24932500
plt.imshow(normed_data, aspect='auto', cmap=my_cm,
24942501
interpolation='lanczos')
24952502

24962503
elif analysis == 'wtc':
24972504
data = xwt(sig1, sig2, sfreq, freqs, analysis='wtc')
24982505
analysis_title = 'Wavelet Coherence'
24992506
cbar_title = 'Coherence'
2500-
my_cm = matplotlib.cm.get_cmap('plasma')
2507+
my_cm = matplotlib.colormaps['plasma']
2508+
25012509
plt.imshow(data, aspect='auto', cmap=my_cm, interpolation='lanczos')
25022510

25032511
else:

0 commit comments

Comments
 (0)