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

Skip to content

Commit a580008

Browse files
committed
Make axisartist.axis_artist pseudo-tests real.
The results seem to be acceptable.
1 parent ba52cd1 commit a580008

File tree

6 files changed

+97
-163
lines changed

6 files changed

+97
-163
lines changed

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,6 @@ def draw(self, renderer):
337337
gc.restore()
338338

339339

340-
def test_ticks():
341-
import matplotlib.pyplot as plt
342-
fig = plt.figure(1)
343-
fig.clf()
344-
ax = fig.add_subplot(111)
345-
ax.xaxis.set_visible(False)
346-
ax.yaxis.set_visible(False)
347-
ticks = Ticks(ticksize=10, axis=ax.xaxis)
348-
ax.add_artist(ticks)
349-
locs_angles = [((0.2, 0.), 90),
350-
((0.4, 0.), 120)]
351-
ticks.set_locs_angles(locs_angles)
352-
plt.draw()
353-
354-
355-
356-
357340
class LabelBase(mtext.Text):
358341
"""
359342
A base class for AxisLabel and TickLabels. The position and angle
@@ -465,33 +448,6 @@ def get_window_extent(self, renderer):
465448
return bbox
466449

467450

468-
469-
def test_labelbase():
470-
import matplotlib.pyplot as plt
471-
fig = plt.figure(1)
472-
fig.clf()
473-
ax = fig.add_subplot(111)
474-
475-
ax.plot([0.5], [0.5], "o")
476-
label = LabelBase(0.5, 0.5, "Test")
477-
478-
a = -90
479-
label._set_ref_angle(a)
480-
label._set_offset_radius(offset_radius=50)
481-
label.set_rotation(-90)
482-
label.set(ha="center", va="top")
483-
484-
ax.add_artist(label)
485-
plt.draw()
486-
487-
488-
489-
490-
491-
492-
493-
494-
495451
class AxisLabel(LabelBase, AttributeCopier):
496452
"""
497453
Axis Label. Derived from Text. The position of the text is updated
@@ -847,47 +803,6 @@ def get_texts_widths_heights_descents(self, renderer):
847803
return whd_list
848804

849805

850-
851-
def test_ticklabels():
852-
import matplotlib.pyplot as plt
853-
fig = plt.figure(1)
854-
fig.clf()
855-
ax = fig.add_subplot(111)
856-
ax.xaxis.set_visible(False)
857-
ax.yaxis.set_visible(False)
858-
ax.plot([0.2, 0.4], [0.5, 0.5], "o")
859-
ticks = Ticks(ticksize=10, axis=ax.xaxis)
860-
ax.add_artist(ticks)
861-
locs_angles_labels = [((0.2, 0.5), -90, "0.2"),
862-
((0.4, 0.5), -120, "0.4")]
863-
tick_locs_angles = [(xy, a+180) for xy, a, l in locs_angles_labels]
864-
ticks.set_locs_angles(tick_locs_angles)
865-
866-
867-
ax.plot([0.5], [0.5], ",")
868-
axislabel = AxisLabel(0.5, 0.5, "Test")
869-
axislabel._set_offset_radius(20)
870-
axislabel._set_ref_angle(0)
871-
axislabel.set_axis_direction("bottom")
872-
#axislabel._text_follow_ref_angle = True
873-
#axislabel.set(va="center", ha="right")
874-
ax.add_artist(axislabel)
875-
876-
if 1:
877-
ticklabels = TickLabels(axis_direction="left")
878-
ticklabels._locs_angles_labels = locs_angles_labels
879-
#ticklabels.set_rotation(90)
880-
ticklabels.set_pad(10)
881-
882-
ax.add_artist(ticklabels)
883-
884-
ax.set_xlim(0, 1); ax.set_ylim(0, 1)
885-
886-
plt.draw()
887-
888-
889-
890-
891806
class GridlinesCollection(LineCollection):
892807
def __init__(self, *kl, **kwargs):
893808
"""
@@ -1611,81 +1526,3 @@ def toggle(self, all=None, ticks=None, ticklabels=None, label=None):
16111526
self.minor_ticklabels.set_visible(_ticklabels)
16121527
if _label is not None:
16131528
self.label.set_visible(_label)
1614-
1615-
1616-
1617-
1618-
1619-
def test_axis_artist():
1620-
global axisline
1621-
1622-
#self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes)
1623-
from mpl_toolkits.axisartist import AxisArtistHelperRectlinear
1624-
fig = plt.figure(1)
1625-
fig.clf()
1626-
ax=fig.add_subplot(111)
1627-
ax.xaxis.set_visible(False)
1628-
ax.yaxis.set_visible(False)
1629-
1630-
if 1:
1631-
1632-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="left")
1633-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="left")
1634-
ax.add_artist(axisline)
1635-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="right")
1636-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="right")
1637-
ax.add_artist(axisline)
1638-
1639-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom")
1640-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom")
1641-
axisline.set_label("TTT")
1642-
#axisline.label.set_visible(False)
1643-
ax.add_artist(axisline)
1644-
1645-
#axisline.major_ticklabels.set_axis_direction("bottom")
1646-
axisline.major_ticks.set_tick_out(False)
1647-
1648-
ax.set_ylabel("Test")
1649-
1650-
axisline.label.set_pad(5)
1651-
1652-
1653-
plt.draw()
1654-
1655-
def test_axis_artist2():
1656-
global axisline
1657-
1658-
#self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes)
1659-
from mpl_toolkits.axislines import AxisArtistHelperRectlinear
1660-
fig = plt.figure(1)
1661-
fig.clf()
1662-
ax=fig.add_subplot(111)
1663-
ax.xaxis.set_visible(False)
1664-
ax.yaxis.set_visible(False)
1665-
1666-
1667-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom")
1668-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom")
1669-
axisline.set_label("TTT")
1670-
ax.add_artist(axisline)
1671-
1672-
#axisline.major_ticklabels.set_axis_direction("bottom")
1673-
axisline.major_ticks.set_tick_out(False)
1674-
1675-
1676-
ax.set_ylabel("Test")
1677-
1678-
plt.draw()
1679-
1680-
if __name__ == "__main__":
1681-
#test_labelbase()
1682-
#test_ticklabels()
1683-
test_axis_artist()
1684-
#test_axis_artist2()
1685-
1686-
1687-
# DONE
1688-
# *. ticks, ticklabels, axislabels
1689-
# *. workon axisartist
1690-
1691-
# TODO
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import matplotlib.pyplot as plt
5+
from matplotlib.testing.decorators import image_comparison
6+
7+
from mpl_toolkits.axisartist import AxisArtistHelperRectlinear
8+
from mpl_toolkits.axisartist.axis_artist import (AxisArtist, AxisLabel,
9+
LabelBase, Ticks, TickLabels)
10+
11+
12+
@image_comparison(baseline_images=['axis_artist_ticks'],
13+
extensions=['png'], style='default')
14+
def test_ticks():
15+
fig, ax = plt.subplots()
16+
17+
ax.xaxis.set_visible(False)
18+
ax.yaxis.set_visible(False)
19+
20+
locs_angles = [((i / 10, 0.0), i * 30) for i in range(-1, 12)]
21+
22+
ticks_in = Ticks(ticksize=10, axis=ax.xaxis)
23+
ticks_in.set_locs_angles(locs_angles)
24+
ax.add_artist(ticks_in)
25+
26+
ticks_out = Ticks(ticksize=10, tick_out=True, color='C3', axis=ax.xaxis)
27+
ticks_out.set_locs_angles(locs_angles)
28+
ax.add_artist(ticks_out)
29+
30+
31+
@image_comparison(baseline_images=['axis_artist_labelbase'],
32+
extensions=['png'], style='default')
33+
def test_labelbase():
34+
fig, ax = plt.subplots()
35+
36+
ax.plot([0.5], [0.5], "o")
37+
38+
label = LabelBase(0.5, 0.5, "Test")
39+
label._set_ref_angle(-90)
40+
label._set_offset_radius(offset_radius=50)
41+
label.set_rotation(-90)
42+
label.set(ha="center", va="top")
43+
ax.add_artist(label)
44+
45+
46+
@image_comparison(baseline_images=['axis_artist_ticklabels'],
47+
extensions=['png'], style='default')
48+
def test_ticklabels():
49+
fig, ax = plt.subplots()
50+
51+
ax.xaxis.set_visible(False)
52+
ax.yaxis.set_visible(False)
53+
54+
ax.plot([0.2, 0.4], [0.5, 0.5], "o")
55+
56+
ticks = Ticks(ticksize=10, axis=ax.xaxis)
57+
ax.add_artist(ticks)
58+
locs_angles_labels = [((0.2, 0.5), -90, "0.2"),
59+
((0.4, 0.5), -120, "0.4")]
60+
tick_locs_angles = [(xy, a + 180) for xy, a, l in locs_angles_labels]
61+
ticks.set_locs_angles(tick_locs_angles)
62+
63+
ticklabels = TickLabels(axis_direction="left")
64+
ticklabels._locs_angles_labels = locs_angles_labels
65+
ticklabels.set_pad(10)
66+
ax.add_artist(ticklabels)
67+
68+
ax.plot([0.5], [0.5], "s")
69+
axislabel = AxisLabel(0.5, 0.5, "Test")
70+
axislabel._set_offset_radius(20)
71+
axislabel._set_ref_angle(0)
72+
axislabel.set_axis_direction("bottom")
73+
ax.add_artist(axislabel)
74+
75+
ax.set_xlim(0, 1)
76+
ax.set_ylim(0, 1)
77+
78+
79+
@image_comparison(baseline_images=['axis_artist'],
80+
extensions=['png'], style='default')
81+
def test_axis_artist():
82+
fig, ax = plt.subplots()
83+
84+
ax.xaxis.set_visible(False)
85+
ax.yaxis.set_visible(False)
86+
87+
for loc in ('left', 'right', 'bottom'):
88+
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc=loc)
89+
axisline = AxisArtist(ax, _helper, offset=None, axis_direction=loc)
90+
ax.add_artist(axisline)
91+
92+
# Settings for bottom AxisArtist.
93+
axisline.set_label("TTT")
94+
axisline.major_ticks.set_tick_out(False)
95+
axisline.label.set_pad(5)
96+
97+
ax.set_ylabel("Test")

0 commit comments

Comments
 (0)