Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d38f70

Browse files
committed
Fix bad histogramming bins in mri/eeg example.
The previous version of the histogram showed regular "spikes" which are entirely artefactual; they come from the fact that we were binning (effectively) integer data with floating point bins that did not all cover the same number of ints (even though they have the same floating point width). Using an explicit, integer binsize avoids this issue.
1 parent 2aee6cc commit 1d38f70

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

galleries/examples/specialty_plots/mri_with_eeg.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import matplotlib.cbook as cbook
1414
import matplotlib.cm as cm
1515
from matplotlib.collections import LineCollection
16-
from matplotlib.ticker import MultipleLocator
1716

1817
fig = plt.figure("MRI_with_EEG")
1918

@@ -28,15 +27,10 @@
2827

2928
# Plot the histogram of MRI intensity
3029
ax1 = fig.add_subplot(2, 2, 2)
31-
im = np.ravel(im)
32-
im = im[np.nonzero(im)] # Ignore the background
33-
im = im / (2**16 - 1) # Normalize
34-
ax1.hist(im, bins=100)
35-
ax1.xaxis.set_major_locator(MultipleLocator(0.4))
30+
im = im[im.nonzero()] # Ignore the background
31+
ax1.hist(im, bins=np.arange(0, 2**16+1, 512))
32+
ax1.set(xlabel='Intensity (a.u.)', ylabel='MRI density', yticks=[])
3633
ax1.minorticks_on()
37-
ax1.set_yticks([])
38-
ax1.set_xlabel('Intensity (a.u.)')
39-
ax1.set_ylabel('MRI density')
4034

4135
# Load the EEG data
4236
n_samples, n_rows = 800, 4
@@ -72,6 +66,5 @@
7266

7367
ax2.set_xlabel('Time (s)')
7468

75-
7669
plt.tight_layout()
7770
plt.show()

0 commit comments

Comments
 (0)