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

Skip to content

Commit 36c14b5

Browse files
committed
Merge pull request #4050 from mdboom/issue4049
Fix : masked array handling
2 parents d044abe + c9e98c6 commit 36c14b5

5 files changed

Lines changed: 24 additions & 7 deletions

File tree

lib/matplotlib/path.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
172172
Parameters
173173
----------
174174
verts : numpy array
175-
codes : numpy array (may not be None)
175+
codes : numpy array
176176
internals : dict or None
177177
The attributes that the resulting path should have.
178178
Allowed keys are ``readonly``, ``should_simplify``,
@@ -182,6 +182,10 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
182182
"""
183183
internals = internals or {}
184184
pth = cls.__new__(cls)
185+
if ma.isMaskedArray(verts):
186+
verts = verts.astype(np.float_).filled(np.nan)
187+
else:
188+
verts = np.asarray(verts, np.float_)
185189
pth._vertices = verts
186190
pth._codes = codes
187191
pth._readonly = internals.pop('readonly', False)

lib/matplotlib/scale.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ def get_transform(self):
8787
def _mask_non_positives(a):
8888
"""
8989
Return a Numpy masked array where all non-positive values are
90-
masked. If there are no non-positive values, the original array
91-
is returned.
90+
replaced with NaNs. If there are no non-positive values, the
91+
original array is returned.
9292
"""
9393
mask = a <= 0.0
9494
if mask.any():
95-
return ma.MaskedArray(a, mask=mask)
95+
return np.where(mask, np.nan, a)
9696
return a
9797

9898

28.2 KB
Loading

lib/matplotlib/tests/test_path.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def test_point_in_path_nan():
7272
assert not contains[0]
7373

7474

75+
@image_comparison(baseline_images=['semi_log_with_zero'], extensions=['png'])
76+
def test_log_transform_with_zero():
77+
x = np.arange(-10, 10)
78+
y = (1.0 - 1.0/(x**2+1))**20
79+
80+
fig, ax = plt.subplots()
81+
ax.semilogy(x, y, "-o", lw=15)
82+
ax.grid(True)
83+
84+
7585
if __name__ == '__main__':
7686
import nose
7787
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

src/_backend_agg.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
502502
agg::rgba color)
503503
{
504504
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
505-
typedef PathSnapper<transformed_path_t> snap_t;
505+
typedef PathNanRemover<transformed_path_t> nan_removed_t;
506+
typedef PathSnapper<nan_removed_t> snap_t;
506507
typedef agg::conv_curve<snap_t> curve_t;
507508
typedef agg::conv_stroke<curve_t> stroke_t;
508509
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
@@ -515,14 +516,16 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
515516
trans *= agg::trans_affine_translation(0.5, (double)height + 0.5);
516517

517518
transformed_path_t marker_path_transformed(marker_path, marker_trans);
518-
snap_t marker_path_snapped(marker_path_transformed,
519+
nan_removed_t marker_path_nan_removed(marker_path_transformed, true, marker_path.has_curves());
520+
snap_t marker_path_snapped(marker_path_nan_removed,
519521
gc.snap_mode,
520522
marker_path.total_vertices(),
521523
points_to_pixels(gc.linewidth));
522524
curve_t marker_path_curve(marker_path_snapped);
523525

524526
transformed_path_t path_transformed(path, trans);
525-
snap_t path_snapped(path_transformed, SNAP_FALSE, path.total_vertices(), 0.0);
527+
nan_removed_t path_nan_removed(path_transformed, false, false);
528+
snap_t path_snapped(path_nan_removed, SNAP_FALSE, path.total_vertices(), 0.0);
526529
curve_t path_curve(path_snapped);
527530
path_curve.rewind(0);
528531

0 commit comments

Comments
 (0)