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

Skip to content
Merged
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
Add scatter color len mismatch ValueError test
  • Loading branch information
bcongdon committed Nov 8, 2016
commit e218bcfb31148f5d68e5bc75e4c802e69f1df140
17 changes: 6 additions & 11 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4800,15 +4800,10 @@ def test_fillbetween_cycle():


@cleanup
def test_log_margins():
plt.rcParams['axes.autolimit_mode'] = 'data'
def test_color_length_mismatch():
N = 500
x, y = np.random.rand(N), np.random.rand(N)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interest of keeping tests minimal and direct, you could reduce N to 5, and use arange instead of rand.
You could also add a test for the handling of c when it is an rgba or sequence of them.

colors = np.random.rand(N+1)
fig, ax = plt.subplots()
margin = 0.05
ax.set_xmargin(margin)
ax.semilogx([1, 10], [1, 10])
xlim0, xlim1 = ax.get_xlim()
transform = ax.xaxis.get_transform()
xlim0t, xlim1t = transform.transform([xlim0, xlim1])
x0t, x1t = transform.transform([1, 10])
delta = (x1t - x0t) * margin
assert_allclose([xlim0t + delta, xlim1t - delta], [x0t, x1t])
with pytest.raises(ValueError):
ax.scatter(x, y, c=colors)