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

Skip to content

Commit b68cc51

Browse files
committed
factor existing scatter tests into a class
1 parent c77ee58 commit b68cc51

1 file changed

Lines changed: 53 additions & 55 deletions

File tree

lib/matplotlib/tests/test_axes.py

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,63 +1660,61 @@ def test_hist2d_transpose():
16601660
ax.hist2d(x, y, bins=10, rasterized=True)
16611661

16621662

1663-
@image_comparison(baseline_images=['scatter', 'scatter'])
1664-
def test_scatter_plot():
1665-
fig, ax = plt.subplots()
1666-
data = {"x": [3, 4, 2, 6], "y": [2, 5, 2, 3], "c": ['r', 'y', 'b', 'lime'],
1667-
"s": [24, 15, 19, 29]}
1668-
1669-
ax.scatter(data["x"], data["y"], c=data["c"], s=data["s"])
1670-
1671-
# Reuse testcase from above for a labeled data test
1672-
fig, ax = plt.subplots()
1673-
ax.scatter("x", "y", c="c", s="s", data=data)
1674-
1675-
1676-
@image_comparison(baseline_images=['scatter_marker'], remove_text=True,
1677-
extensions=['png'])
1678-
def test_scatter_marker():
1679-
fig, (ax0, ax1, ax2) = plt.subplots(ncols=3)
1680-
ax0.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1681-
c=[(1, 0, 0), 'y', 'b', 'lime'],
1682-
s=[60, 50, 40, 30],
1683-
edgecolors=['k', 'r', 'g', 'b'],
1684-
marker='s')
1685-
ax1.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1686-
c=[(1, 0, 0), 'y', 'b', 'lime'],
1687-
s=[60, 50, 40, 30],
1688-
edgecolors=['k', 'r', 'g', 'b'],
1689-
marker=mmarkers.MarkerStyle('o', fillstyle='top'))
1690-
# unit area ellipse
1691-
rx, ry = 3, 1
1692-
area = rx * ry * np.pi
1693-
theta = np.linspace(0, 2 * np.pi, 21)
1694-
verts = np.column_stack([np.cos(theta) * rx / area,
1695-
np.sin(theta) * ry / area])
1696-
ax2.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1697-
c=[(1, 0, 0), 'y', 'b', 'lime'],
1698-
s=[60, 50, 40, 30],
1699-
edgecolors=['k', 'r', 'g', 'b'],
1700-
marker=verts)
1701-
1702-
1703-
@image_comparison(baseline_images=['scatter_2D'], remove_text=True,
1704-
extensions=['png'])
1705-
def test_scatter_2D():
1706-
x = np.arange(3)
1707-
y = np.arange(2)
1708-
x, y = np.meshgrid(x, y)
1709-
z = x + y
1710-
fig, ax = plt.subplots()
1711-
ax.scatter(x, y, c=z, s=200, edgecolors='face')
1663+
class TestScatter(object):
1664+
@image_comparison(baseline_images=['scatter', 'scatter'])
1665+
def test_scatter_plot(self):
1666+
fig, ax = plt.subplots()
1667+
data = {"x": [3, 4, 2, 6], "y": [2, 5, 2, 3],
1668+
"c": ['r', 'y', 'b', 'lime'], "s": [24, 15, 19, 29]}
17121669

1670+
ax.scatter(data["x"], data["y"], c=data["c"], s=data["s"])
17131671

1714-
def test_scatter_color():
1715-
# Try to catch cases where 'c' kwarg should have been used.
1716-
with pytest.raises(ValueError):
1717-
plt.scatter([1, 2], [1, 2], color=[0.1, 0.2])
1718-
with pytest.raises(ValueError):
1719-
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])
1672+
# Reuse testcase from above for a labeled data test
1673+
fig, ax = plt.subplots()
1674+
ax.scatter("x", "y", c="c", s="s", data=data)
1675+
1676+
@image_comparison(baseline_images=['scatter_marker'], remove_text=True,
1677+
extensions=['png'])
1678+
def test_scatter_marker(self):
1679+
fig, (ax0, ax1, ax2) = plt.subplots(ncols=3)
1680+
ax0.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1681+
c=[(1, 0, 0), 'y', 'b', 'lime'],
1682+
s=[60, 50, 40, 30],
1683+
edgecolors=['k', 'r', 'g', 'b'],
1684+
marker='s')
1685+
ax1.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1686+
c=[(1, 0, 0), 'y', 'b', 'lime'],
1687+
s=[60, 50, 40, 30],
1688+
edgecolors=['k', 'r', 'g', 'b'],
1689+
marker=mmarkers.MarkerStyle('o', fillstyle='top'))
1690+
# unit area ellipse
1691+
rx, ry = 3, 1
1692+
area = rx * ry * np.pi
1693+
theta = np.linspace(0, 2 * np.pi, 21)
1694+
verts = np.column_stack([np.cos(theta) * rx / area,
1695+
np.sin(theta) * ry / area])
1696+
ax2.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1697+
c=[(1, 0, 0), 'y', 'b', 'lime'],
1698+
s=[60, 50, 40, 30],
1699+
edgecolors=['k', 'r', 'g', 'b'],
1700+
verts=verts)
1701+
1702+
@image_comparison(baseline_images=['scatter_2D'], remove_text=True,
1703+
extensions=['png'])
1704+
def test_scatter_2D(self):
1705+
x = np.arange(3)
1706+
y = np.arange(2)
1707+
x, y = np.meshgrid(x, y)
1708+
z = x + y
1709+
fig, ax = plt.subplots()
1710+
ax.scatter(x, y, c=z, s=200, edgecolors='face')
1711+
1712+
def test_scatter_color(self):
1713+
# Try to catch cases where 'c' kwarg should have been used.
1714+
with pytest.raises(ValueError):
1715+
plt.scatter([1, 2], [1, 2], color=[0.1, 0.2])
1716+
with pytest.raises(ValueError):
1717+
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])
17201718

17211719

17221720
def test_as_mpl_axes_api():

0 commit comments

Comments
 (0)