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

Skip to content

Commit 8fbadce

Browse files
committed
2 parents a0fe33b + b62f318 commit 8fbadce

5 files changed

Lines changed: 49 additions & 8 deletions

File tree

doc/faq/howto_faq.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ Plotting: howto
1919
Plot `numpy.datetime64` values
2020
------------------------------
2121

22-
For Matplotlib to plot dates (or any scalar with units) a converter
23-
to float needs to be registered with the `matplolib.units` module. The
24-
current best converters for `datetime64` values are in `pandas`. To enable the
25-
converter, import it from pandas::
22+
As of Matplotlib 2.2, `numpy.datetime64` objects are handled the same way
23+
as `datetime.datetime` objects.
24+
25+
If you prefer the pandas converters and locators, you can register their
26+
converter with the `matplolib.units` module::
2627

2728
from pandas.tseries import converter as pdtc
2829
pdtc.register()

examples/lines_bars_and_markers/arctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def f(t):
1818
t1 = np.arange(0.0, 5.0, .2)
1919

2020
l = plt.plot(t1, f(t1), 'ro')
21-
plt.setp(l, 'markersize', 30)
22-
plt.setp(l, 'markerfacecolor', 'C0')
21+
plt.setp(l, markersize=30)
22+
plt.setp(l, markerfacecolor='C0')
2323

2424
plt.show()

examples/lines_bars_and_markers/stem_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
x = np.linspace(0.1, 2 * np.pi, 10)
1212
markerline, stemlines, baseline = plt.stem(x, np.cos(x), '-.')
13-
plt.setp(baseline, 'color', 'r', 'linewidth', 2)
13+
plt.setp(baseline, color='r', linewidth=2)
1414

1515
plt.show()

lib/matplotlib/patches.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,30 @@ def contains(self, mouseevent, radius=None):
143143

144144
def contains_point(self, point, radius=None):
145145
"""
146-
Returns *True* if the given point is inside the path
146+
Returns ``True`` if the given *point* is inside the path
147147
(transformed with its transform attribute).
148+
149+
*radius* allows the path to be made slightly larger or smaller.
148150
"""
149151
radius = self._process_radius(radius)
150152
return self.get_path().contains_point(point,
151153
self.get_transform(),
152154
radius)
153155

156+
def contains_points(self, points, radius=None):
157+
"""
158+
Returns a bool array which is ``True`` if the (closed) path
159+
contains the corresponding point.
160+
(transformed with its transform attribute).
161+
162+
*points* must be Nx2 array.
163+
*radius* allows the path to be made slightly larger or smaller.
164+
"""
165+
radius = self._process_radius(radius)
166+
return self.get_path().contains_points(points,
167+
self.get_transform(),
168+
radius)
169+
154170
def update_from(self, other):
155171
"""
156172
Updates this :class:`Patch` from the properties of *other*.

lib/matplotlib/tests/test_patches.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,27 @@ def test_datetime_datetime_fails():
386386

387387
with pytest.raises(TypeError):
388388
mpatches.Rectangle((0, start), 1, dt_delta)
389+
390+
391+
def test_contains_point():
392+
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0, 0)
393+
points = [(0.0, 0.5), (0.2, 0.5), (0.25, 0.5), (0.5, 0.5)]
394+
path = ell.get_path()
395+
transform = ell.get_transform()
396+
radius = ell._process_radius(None)
397+
expected = np.array([path.contains_point(point,
398+
transform,
399+
radius) for point in points])
400+
result = np.array([ell.contains_point(point) for point in points])
401+
assert np.all(result == expected)
402+
403+
404+
def test_contains_points():
405+
ell = mpatches.Ellipse((0.5, 0.5), 0.5, 1.0, 0)
406+
points = [(0.0, 0.5), (0.2, 0.5), (0.25, 0.5), (0.5, 0.5)]
407+
path = ell.get_path()
408+
transform = ell.get_transform()
409+
radius = ell._process_radius(None)
410+
expected = path.contains_points(points, transform, radius)
411+
result = ell.contains_points(points)
412+
assert np.all(result == expected)

0 commit comments

Comments
 (0)