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

Skip to content

Commit 181042e

Browse files
committed
Make axisartist.axis_artist pseudo-tests real.
The results seem to be acceptable, though one outside ticks are broken.
1 parent 1dcb040 commit 181042e

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
@@ -338,23 +338,6 @@ def draw(self, renderer):
338338
gc.restore()
339339

340340

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

468451

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

850806

851-
852-
def test_ticklabels():
853-
import matplotlib.pyplot as plt
854-
fig = plt.figure(1)
855-
fig.clf()
856-
ax = fig.add_subplot(111)
857-
ax.xaxis.set_visible(False)
858-
ax.yaxis.set_visible(False)
859-
ax.plot([0.2, 0.4], [0.5, 0.5], "o")
860-
ticks = Ticks(ticksize=10, axis=ax.xaxis)
861-
ax.add_artist(ticks)
862-
locs_angles_labels = [((0.2, 0.5), -90, "0.2"),
863-
((0.4, 0.5), -120, "0.4")]
864-
tick_locs_angles = [(xy, a+180) for xy, a, l in locs_angles_labels]
865-
ticks.set_locs_angles(tick_locs_angles)
866-
867-
868-
ax.plot([0.5], [0.5], ",")
869-
axislabel = AxisLabel(0.5, 0.5, "Test")
870-
axislabel._set_offset_radius(20)
871-
axislabel._set_ref_angle(0)
872-
axislabel.set_axis_direction("bottom")
873-
#axislabel._text_follow_ref_angle = True
874-
#axislabel.set(va="center", ha="right")
875-
ax.add_artist(axislabel)
876-
877-
if 1:
878-
ticklabels = TickLabels(axis_direction="left")
879-
ticklabels._locs_angles_labels = locs_angles_labels
880-
#ticklabels.set_rotation(90)
881-
ticklabels.set_pad(10)
882-
883-
ax.add_artist(ticklabels)
884-
885-
ax.set_xlim(0, 1); ax.set_ylim(0, 1)
886-
887-
plt.draw()
888-
889-
890-
891-
892807
class GridlinesCollection(LineCollection):
893808
def __init__(self, *kl, **kwargs):
894809
"""
@@ -1614,81 +1529,3 @@ def toggle(self, all=None, ticks=None, ticklabels=None, label=None):
16141529
self.minor_ticklabels.set_visible(_ticklabels)
16151530
if _label is not None:
16161531
self.label.set_visible(_label)
1617-
1618-
1619-
1620-
1621-
1622-
def test_axis_artist():
1623-
global axisline
1624-
1625-
#self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes)
1626-
from mpl_toolkits.axisartist import AxisArtistHelperRectlinear
1627-
fig = plt.figure(1)
1628-
fig.clf()
1629-
ax=fig.add_subplot(111)
1630-
ax.xaxis.set_visible(False)
1631-
ax.yaxis.set_visible(False)
1632-
1633-
if 1:
1634-
1635-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="left")
1636-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="left")
1637-
ax.add_artist(axisline)
1638-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="right")
1639-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="right")
1640-
ax.add_artist(axisline)
1641-
1642-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom")
1643-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom")
1644-
axisline.set_label("TTT")
1645-
#axisline.label.set_visible(False)
1646-
ax.add_artist(axisline)
1647-
1648-
#axisline.major_ticklabels.set_axis_direction("bottom")
1649-
axisline.major_ticks.set_tick_out(False)
1650-
1651-
ax.set_ylabel("Test")
1652-
1653-
axisline.label.set_pad(5)
1654-
1655-
1656-
plt.draw()
1657-
1658-
def test_axis_artist2():
1659-
global axisline
1660-
1661-
#self._axislines[loc] = new_fixed_axis(loc=loc, axes=axes)
1662-
from mpl_toolkits.axislines import AxisArtistHelperRectlinear
1663-
fig = plt.figure(1)
1664-
fig.clf()
1665-
ax=fig.add_subplot(111)
1666-
ax.xaxis.set_visible(False)
1667-
ax.yaxis.set_visible(False)
1668-
1669-
1670-
_helper = AxisArtistHelperRectlinear.Fixed(ax, loc="bottom")
1671-
axisline = AxisArtist(ax, _helper, offset=None, axis_direction="bottom")
1672-
axisline.set_label("TTT")
1673-
ax.add_artist(axisline)
1674-
1675-
#axisline.major_ticklabels.set_axis_direction("bottom")
1676-
axisline.major_ticks.set_tick_out(False)
1677-
1678-
1679-
ax.set_ylabel("Test")
1680-
1681-
plt.draw()
1682-
1683-
if __name__ == "__main__":
1684-
#test_labelbase()
1685-
#test_ticklabels()
1686-
test_axis_artist()
1687-
#test_axis_artist2()
1688-
1689-
1690-
# DONE
1691-
# *. ticks, ticklabels, axislabels
1692-
# *. workon axisartist
1693-
1694-
# 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(0, 11)]
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)