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

Skip to content

Commit fa03754

Browse files
committed
Fix bug in simplification code that was clipping peaks.
svn path=/trunk/matplotlib/; revision=7895
1 parent 1b84dab commit fa03754

6 files changed

Lines changed: 78 additions & 7 deletions

File tree

-57 Bytes
Loading
Binary file not shown.
3.92 KB
Loading
Lines changed: 50 additions & 0 deletions
Loading

lib/matplotlib/tests/test_simplification.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_noise():
7070
path = transform.transform_path(path)
7171
simplified = list(path.iter_segments(simplify=(800, 600)))
7272

73-
assert len(simplified) == 2662
73+
assert len(simplified) == 2675
7474

7575
def test_sine_plus_noise():
7676
np.random.seed(0)
@@ -87,7 +87,7 @@ def test_sine_plus_noise():
8787
path = transform.transform_path(path)
8888
simplified = list(path.iter_segments(simplify=(800, 600)))
8989

90-
assert len(simplified) == 279
90+
assert len(simplified) == 628
9191

9292
@image_comparison(baseline_images=['simplify_curve'])
9393
def test_simplify_curve():
@@ -116,6 +116,23 @@ def test_hatch():
116116

117117
fig.savefig('hatch_simplify')
118118

119+
@image_comparison(baseline_images=['fft_peaks'])
120+
def test_fft_peaks():
121+
fig = plt.figure()
122+
t = arange(65536)
123+
ax = fig.add_subplot(111)
124+
p1 = ax.plot(abs(fft(sin(2*pi*.01*t)*blackman(len(t)))))
125+
ax.set_xticks([])
126+
ax.set_yticks([])
127+
128+
fig.savefig('fft_peaks')
129+
130+
path = p1[0].get_path()
131+
transform = p1[0].get_transform()
132+
path = transform.transform_path(path)
133+
simplified = list(path.iter_segments(simplify=(800, 600)))
134+
135+
assert len(simplified) == 13
119136

120137
if __name__=='__main__':
121138
import nose

src/path_converters.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,15 @@ class PathSimplifier : protected EmbeddedQueue<9>
568568
}
569569
m_after_moveto = false;
570570

571+
/* NOTE: We used to skip this very short segments, but if
572+
you have a lot of them cumulatively, you can miss
573+
maxima or minima in the data. */
574+
571575
/* Don't render line segments less than one pixel long */
572-
if (fabs(*x - m_lastx) < 1.0 && fabs(*y - m_lasty) < 1.0)
573-
{
574-
continue;
575-
}
576+
/* if (fabs(*x - m_lastx) < 1.0 && fabs(*y - m_lasty) < 1.0) */
577+
/* { */
578+
/* continue; */
579+
/* } */
576580

577581
/* if we have no orig vector, set it to this vector and
578582
continue. this orig vector is the reference vector we
@@ -649,7 +653,7 @@ class PathSimplifier : protected EmbeddedQueue<9>
649653
}
650654
else
651655
{
652-
if (paradNorm2 > m_dnorm2Min)
656+
if (paradNorm2 < m_dnorm2Min)
653657
{
654658
m_dnorm2Min = paradNorm2;
655659
m_nextX = *x;

0 commit comments

Comments
 (0)