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

Skip to content

Fix masked array handling #4050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
Parameters
----------
verts : numpy array
codes : numpy array (may not be None)
codes : numpy array
internals : dict or None
The attributes that the resulting path should have.
Allowed keys are ``readonly``, ``should_simplify``,
Expand All @@ -182,6 +182,10 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
"""
internals = internals or {}
pth = cls.__new__(cls)
if ma.isMaskedArray(verts):
verts = verts.astype(np.float_).filled(np.nan)
else:
verts = np.asarray(verts, np.float_)
pth._vertices = verts
pth._codes = codes
pth._readonly = internals.pop('readonly', False)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def get_transform(self):
def _mask_non_positives(a):
"""
Return a Numpy masked array where all non-positive values are
masked. If there are no non-positive values, the original array
is returned.
replaced with NaNs. If there are no non-positive values, the
original array is returned.
"""
mask = a <= 0.0
if mask.any():
return ma.MaskedArray(a, mask=mask)
return np.where(mask, np.nan, a)
return a


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def test_point_in_path_nan():
assert not contains[0]


@image_comparison(baseline_images=['semi_log_with_zero'], extensions=['png'])
def test_log_transform_with_zero():
x = np.arange(-10, 10)
y = (1.0 - 1.0/(x**2+1))**20

fig, ax = plt.subplots()
ax.semilogy(x, y, "-o", lw=15)
ax.grid(True)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
9 changes: 6 additions & 3 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
agg::rgba color)
{
typedef agg::conv_transform<py::PathIterator> transformed_path_t;
typedef PathSnapper<transformed_path_t> snap_t;
typedef PathNanRemover<transformed_path_t> nan_removed_t;
typedef PathSnapper<nan_removed_t> snap_t;
typedef agg::conv_curve<snap_t> curve_t;
typedef agg::conv_stroke<curve_t> stroke_t;
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
Expand All @@ -515,14 +516,16 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
trans *= agg::trans_affine_translation(0.5, (double)height + 0.5);

transformed_path_t marker_path_transformed(marker_path, marker_trans);
snap_t marker_path_snapped(marker_path_transformed,
nan_removed_t marker_path_nan_removed(marker_path_transformed, true, marker_path.has_curves());
snap_t marker_path_snapped(marker_path_nan_removed,
gc.snap_mode,
marker_path.total_vertices(),
points_to_pixels(gc.linewidth));
curve_t marker_path_curve(marker_path_snapped);

transformed_path_t path_transformed(path, trans);
snap_t path_snapped(path_transformed, SNAP_FALSE, path.total_vertices(), 0.0);
nan_removed_t path_nan_removed(path_transformed, false, false);
snap_t path_snapped(path_nan_removed, SNAP_FALSE, path.total_vertices(), 0.0);
curve_t path_curve(path_snapped);
path_curve.rewind(0);

Expand Down