Skip to content

Add new downsample method for lines #7632

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

Closed
wants to merge 16 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
adding test
  • Loading branch information
kbrose committed Dec 17, 2016
commit 99883edd0c213e9828163598531dffdc1eaa11c1
33 changes: 32 additions & 1 deletion lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import itertools
import matplotlib.lines as mlines
import nose
from nose.tools import assert_true, assert_raises
from nose.tools import assert_true, assert_raises, assert_equal
from timeit import repeat
import numpy as np
from cycler import cycler
Expand Down Expand Up @@ -191,5 +191,36 @@ def test_nan_is_sorted():
assert_true(not line._is_sorted([3, 5] + [np.nan] * 100 + [0, 2]))


@cleanup
def test_downsample_lines():
x = np.array([0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1.0])
y = np.array([2, 8, 3, 6, 1, 5, 5, 8, 7, 6, 6, 7.0])

line = mlines.Line2D(x, y, downsample=True)

fig, ax = plt.subplots()

# Adjust size of figure to ensure downsampling occurs
fig.set_dpi(1)
fig.set_size_inches([2,1])

ax.add_line(line)

tpath, _ = line._get_transformed_path().get_transformed_path_and_affine()
down_verts = line._downsample_path(tpath).vertices

expected_down_verts = np.array([
[0.0, 2.0],
[0.0, 1.0],
[0.0, 8.0],
[0.0, 5.0],
[1.0, 5.0],
[1.0, 5.0],
[1.0, 8.0],
[1.0, 7.0]
])
assert_equal(down_verts, expected_down_verts)


if __name__ == '__main__':
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)