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

Skip to content

Commit cd0921c

Browse files
committed
Merge remote-tracking branch 'matplotlib/v1.5.x' into v2.x
2 parents ab191f8 + 1c690ee commit cd0921c

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import numpy as np
2525
import tornado
26+
import datetime
2627

2728
from matplotlib.backends import backend_agg
2829
from matplotlib.figure import Figure

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,8 @@ def _resample(self, lutsize):
852852
"""
853853
Return a new color map with *lutsize* entries.
854854
"""
855-
return ListedColormap(self.name, self.colors, lutsize)
855+
colors = self(np.linspace(0, 1, lutsize))
856+
return ListedColormap(colors, name=self.name)
856857

857858

858859
class Normalize(object):

lib/matplotlib/tests/test_colors.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@
1818
cleanup, knownfailureif)
1919

2020

21+
def test_resample():
22+
"""
23+
Github issue #6025 pointed to incorrect ListedColormap._resample;
24+
here we test the method for LinearSegmentedColormap as well.
25+
"""
26+
n = 101
27+
colorlist = np.empty((n, 4), float)
28+
colorlist[:, 0] = np.linspace(0, 1, n)
29+
colorlist[:, 1] = 0.2
30+
colorlist[:, 2] = np.linspace(1, 0, n)
31+
colorlist[:, 3] = 0.7
32+
lsc = mcolors.LinearSegmentedColormap.from_list('lsc', colorlist)
33+
lc = mcolors.ListedColormap(colorlist)
34+
lsc3 = lsc._resample(3)
35+
lc3 = lc._resample(3)
36+
expected = np.array([[0.0, 0.2, 1.0, 0.7],
37+
[0.5, 0.2, 0.5, 0.7],
38+
[1.0, 0.2, 0.0, 0.7]], float)
39+
assert_array_almost_equal(lsc3([0, 0.5, 1]), expected)
40+
assert_array_almost_equal(lc3([0, 0.5, 1]), expected)
41+
42+
2143
def test_colormap_endian():
2244
"""
2345
Github issue #1005: a bug in putmask caused erroneous

lib/matplotlib/tests/test_transforms.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ def test_clipping_of_log():
208208
simplify=False)
209209

210210
tpoints, tcodes = list(zip(*result))
211-
# Because y coordinate -99 is outside the clip zone, the first
212-
# line segment is effectively removed. That means that the closepoly
213-
# operation must be replaced by a move to the first point.
214-
assert np.allclose(tcodes, [M, M, L, L, L, C])
211+
assert np.allclose(tcodes, [M, L, L, L, C])
215212

216213

217214
class NonAffineForTest(mtrans.Transform):

src/_backend_agg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,
484484

485485
transformed_path_t tpath(path, trans);
486486
nan_removed_t nan_removed(tpath, true, path.has_curves());
487-
clipped_t clipped(nan_removed, clip, width, height);
487+
clipped_t clipped(nan_removed, clip && !path.has_curves(), width, height);
488488
snapped_t snapped(clipped, gc.snap_mode, path.total_vertices(), snapping_linewidth);
489489
simplify_t simplified(snapped, simplify, path.simplify_threshold());
490490
curve_t curve(simplified);
@@ -1009,7 +1009,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
10091009

10101010
transformed_path_t tpath(path, trans);
10111011
nan_removed_t nan_removed(tpath, true, has_curves);
1012-
clipped_t clipped(nan_removed, do_clip, width, height);
1012+
clipped_t clipped(nan_removed, do_clip && !has_curves, width, height);
10131013
snapped_t snapped(
10141014
clipped, gc.snap_mode, path.total_vertices(), points_to_pixels(gc.linewidth));
10151015
if (has_curves) {

src/_path.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void convert_path_to_polygons(PathIterator &path,
885885

886886
transformed_path_t tpath(path, trans);
887887
nan_removal_t nan_removed(tpath, true, path.has_curves());
888-
clipped_t clipped(nan_removed, do_clip, width, height);
888+
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), width, height);
889889
simplify_t simplified(clipped, simplify, path.simplify_threshold());
890890
curve_t curve(simplified);
891891

@@ -950,7 +950,7 @@ void cleanup_path(PathIterator &path,
950950

951951
transformed_path_t tpath(path, trans);
952952
nan_removal_t nan_removed(tpath, remove_nans, path.has_curves());
953-
clipped_t clipped(nan_removed, do_clip, rect);
953+
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), rect);
954954
snapped_t snapped(clipped, snap_mode, path.total_vertices(), stroke_width);
955955
simplify_t simplified(snapped, do_simplify, path.simplify_threshold());
956956

@@ -1156,7 +1156,7 @@ int convert_to_string(PathIterator &path,
11561156

11571157
transformed_path_t tpath(path, trans);
11581158
nan_removal_t nan_removed(tpath, true, path.has_curves());
1159-
clipped_t clipped(nan_removed, do_clip, clip_rect);
1159+
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), clip_rect);
11601160
simplify_t simplified(clipped, simplify, path.simplify_threshold());
11611161

11621162
*buffersize = path.total_vertices() * (precision + 5) * 4;

src/path_cleanup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PathCleanupIterator
4343
: m_transform(trans),
4444
m_transformed(m_path_iter, m_transform),
4545
m_nan_removed(m_transformed, remove_nans, m_path_iter.has_curves()),
46-
m_clipped(m_nan_removed, do_clip, rect),
46+
m_clipped(m_nan_removed, do_clip && !m_path_iter.has_curves(), rect),
4747
m_snapped(m_clipped, snap_mode, m_path_iter.total_vertices(), stroke_width),
4848
m_simplify(m_snapped,
4949
do_simplify && m_path_iter.should_simplify(),

0 commit comments

Comments
 (0)