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

Skip to content

Commit ba52cd1

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

File tree

4 files changed

+126
-176
lines changed

4 files changed

+126
-176
lines changed

lib/mpl_toolkits/axisartist/floating_axes.py

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -542,179 +542,3 @@ def floatingaxes_class_factory(axes_class):
542542

543543
import matplotlib.axes as maxes
544544
FloatingSubplot = maxes.subplot_class_factory(FloatingAxes)
545-
546-
# def test(fig):
547-
# from mpl_toolkits.axes_grid.axislines import Subplot
548-
# ax = Subplot(fig, 111)
549-
550-
# fig.add_subplot(ax)
551-
552-
# plt.draw()
553-
554-
555-
def curvelinear_test3(fig):
556-
"""
557-
polar projection, but in a rectangular box.
558-
"""
559-
global ax1, axis
560-
import numpy as np
561-
from . import angle_helper
562-
from matplotlib.projections import PolarAxes
563-
564-
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
565-
# system in degree
566-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
567-
568-
# polar projection, which involves cycle, and also has limits in
569-
# its coordinates, needs a special method to find the extremes
570-
# (min, max of the coordinate within the view).
571-
572-
573-
grid_locator1 = angle_helper.LocatorDMS(15)
574-
# Find a grid values appropriate for the coordinate (degree,
575-
# minute, second).
576-
577-
tick_formatter1 = angle_helper.FormatterDMS()
578-
# And also uses an appropriate formatter. Note that,the
579-
# acceptable Locator and Formatter class is a bit different than
580-
# that of mpl's, and you cannot directly use mpl's Locator and
581-
# Formatter here (but may be possible in the future).
582-
583-
from .grid_finder import FixedLocator
584-
grid_locator2 = FixedLocator([2, 4, 6, 8, 10])
585-
586-
587-
grid_helper = GridHelperCurveLinear(tr,
588-
extremes=(0, 360, 10, 3),
589-
grid_locator1=grid_locator1,
590-
grid_locator2=grid_locator2,
591-
tick_formatter1=tick_formatter1,
592-
tick_formatter2=None,
593-
)
594-
595-
ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper)
596-
597-
598-
#ax1.axis["top"].set_visible(False)
599-
#ax1.axis["bottom"].major_ticklabels.set_axis_direction("top")
600-
601-
fig.add_subplot(ax1)
602-
603-
604-
#ax1.grid(True)
605-
606-
607-
r_scale = 10.
608-
tr2 = Affine2D().scale(1., 1./r_scale) + tr
609-
grid_locator2 = FixedLocator([30, 60, 90])
610-
grid_helper2 = GridHelperCurveLinear(tr2,
611-
extremes=(0, 360,
612-
10.*r_scale, 3.*r_scale),
613-
grid_locator2=grid_locator2,
614-
)
615-
616-
ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1)
617-
618-
ax1.axis["left"].label.set_text("Test 1")
619-
ax1.axis["right"].label.set_text("Test 2")
620-
621-
622-
for an in [ "left", "right"]:
623-
ax1.axis[an].set_visible(False)
624-
625-
626-
#grid_helper2 = ax1.get_grid_helper()
627-
ax1.axis["z"] = axis = grid_helper.new_floating_axis(1, 7,
628-
axes=ax1,
629-
axis_direction="bottom")
630-
axis.toggle(all=True, label=True)
631-
#axis.label.set_axis_direction("top")
632-
axis.label.set_text("z = ?")
633-
axis.label.set_visible(True)
634-
axis.line.set_color("0.5")
635-
#axis.label.set_visible(True)
636-
637-
638-
ax2 = ax1.get_aux_axes(tr)
639-
640-
xx, yy = [67, 90, 75, 30], [2, 5, 8, 4]
641-
ax2.scatter(xx, yy)
642-
l, = ax2.plot(xx, yy, "k-")
643-
l.set_clip_path(ax1.patch)
644-
645-
646-
def curvelinear_test4(fig):
647-
"""
648-
polar projection, but in a rectangular box.
649-
"""
650-
global ax1, axis
651-
import numpy as np
652-
from . import angle_helper
653-
from matplotlib.projections import PolarAxes
654-
655-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
656-
657-
grid_locator1 = angle_helper.LocatorDMS(5)
658-
tick_formatter1 = angle_helper.FormatterDMS()
659-
660-
from .grid_finder import FixedLocator
661-
grid_locator2 = FixedLocator([2, 4, 6, 8, 10])
662-
663-
grid_helper = GridHelperCurveLinear(tr,
664-
extremes=(120, 30, 10, 0),
665-
grid_locator1=grid_locator1,
666-
grid_locator2=grid_locator2,
667-
tick_formatter1=tick_formatter1,
668-
tick_formatter2=None,
669-
)
670-
671-
ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper)
672-
673-
674-
#ax1.axis["top"].set_visible(False)
675-
#ax1.axis["bottom"].major_ticklabels.set_axis_direction("top")
676-
677-
fig.add_subplot(ax1)
678-
679-
680-
#ax1.grid(True)
681-
682-
683-
ax1.axis["left"].label.set_text("Test 1")
684-
ax1.axis["right"].label.set_text("Test 2")
685-
686-
687-
for an in [ "top"]:
688-
ax1.axis[an].set_visible(False)
689-
690-
691-
#grid_helper2 = ax1.get_grid_helper()
692-
ax1.axis["z"] = axis = grid_helper.new_floating_axis(1, 70,
693-
axes=ax1,
694-
axis_direction="bottom")
695-
axis.toggle(all=True, label=True)
696-
axis.label.set_axis_direction("top")
697-
axis.label.set_text("z = ?")
698-
axis.label.set_visible(True)
699-
axis.line.set_color("0.5")
700-
#axis.label.set_visible(True)
701-
702-
703-
ax2 = ax1.get_aux_axes(tr)
704-
705-
xx, yy = [67, 90, 75, 30], [2, 5, 8, 4]
706-
ax2.scatter(xx, yy)
707-
l, = ax2.plot(xx, yy, "k-")
708-
l.set_clip_path(ax1.patch)
709-
710-
if __name__ == "__main__":
711-
import matplotlib.pyplot as plt
712-
fig = plt.figure(1, figsize=(5, 5))
713-
fig.clf()
714-
715-
#test(fig)
716-
#curvelinear_test1(fig)
717-
curvelinear_test4(fig)
718-
719-
#plt.draw()
720-
plt.show()
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import numpy as np
5+
6+
import matplotlib.pyplot as plt
7+
import matplotlib.projections as mprojections
8+
import matplotlib.transforms as mtransforms
9+
from matplotlib.testing.decorators import image_comparison
10+
from mpl_toolkits.axisartist.axislines import Subplot
11+
from mpl_toolkits.axisartist.floating_axes import (
12+
FloatingSubplot,
13+
GridHelperCurveLinear)
14+
from mpl_toolkits.axisartist.grid_finder import FixedLocator
15+
from mpl_toolkits.axisartist import angle_helper
16+
17+
18+
def test_subplot():
19+
fig = plt.figure(figsize=(5, 5))
20+
fig.clf()
21+
22+
ax = Subplot(fig, 111)
23+
fig.add_subplot(ax)
24+
25+
26+
@image_comparison(baseline_images=['curvelinear3'],
27+
extensions=['png'], style='default', tol=0.01)
28+
def test_curvelinear3():
29+
fig = plt.figure(figsize=(5, 5))
30+
fig.clf()
31+
32+
tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) +
33+
mprojections.PolarAxes.PolarTransform())
34+
35+
grid_locator1 = angle_helper.LocatorDMS(15)
36+
tick_formatter1 = angle_helper.FormatterDMS()
37+
38+
grid_locator2 = FixedLocator([2, 4, 6, 8, 10])
39+
40+
grid_helper = GridHelperCurveLinear(tr,
41+
extremes=(0, 360, 10, 3),
42+
grid_locator1=grid_locator1,
43+
grid_locator2=grid_locator2,
44+
tick_formatter1=tick_formatter1,
45+
tick_formatter2=None)
46+
47+
ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper)
48+
fig.add_subplot(ax1)
49+
50+
r_scale = 10
51+
tr2 = mtransforms.Affine2D().scale(1, 1 / r_scale) + tr
52+
grid_locator2 = FixedLocator([30, 60, 90])
53+
grid_helper2 = GridHelperCurveLinear(tr2,
54+
extremes=(0, 360,
55+
10 * r_scale, 3 * r_scale),
56+
grid_locator2=grid_locator2)
57+
58+
ax1.axis["right"] = axis = grid_helper2.new_fixed_axis("right", axes=ax1)
59+
60+
ax1.axis["left"].label.set_text("Test 1")
61+
ax1.axis["right"].label.set_text("Test 2")
62+
63+
for an in ["left", "right"]:
64+
ax1.axis[an].set_visible(False)
65+
66+
axis = grid_helper.new_floating_axis(1, 7, axes=ax1,
67+
axis_direction="bottom")
68+
ax1.axis["z"] = axis
69+
axis.toggle(all=True, label=True)
70+
axis.label.set_text("z = ?")
71+
axis.label.set_visible(True)
72+
axis.line.set_color("0.5")
73+
74+
ax2 = ax1.get_aux_axes(tr)
75+
76+
xx, yy = [67, 90, 75, 30], [2, 5, 8, 4]
77+
ax2.scatter(xx, yy)
78+
l, = ax2.plot(xx, yy, "k-")
79+
l.set_clip_path(ax1.patch)
80+
81+
82+
@image_comparison(baseline_images=['curvelinear4'],
83+
extensions=['png'], style='default', tol=0.01)
84+
def test_curvelinear4():
85+
fig = plt.figure(figsize=(5, 5))
86+
fig.clf()
87+
88+
tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) +
89+
mprojections.PolarAxes.PolarTransform())
90+
91+
grid_locator1 = angle_helper.LocatorDMS(5)
92+
tick_formatter1 = angle_helper.FormatterDMS()
93+
94+
grid_locator2 = FixedLocator([2, 4, 6, 8, 10])
95+
96+
grid_helper = GridHelperCurveLinear(tr,
97+
extremes=(120, 30, 10, 0),
98+
grid_locator1=grid_locator1,
99+
grid_locator2=grid_locator2,
100+
tick_formatter1=tick_formatter1,
101+
tick_formatter2=None)
102+
103+
ax1 = FloatingSubplot(fig, 111, grid_helper=grid_helper)
104+
fig.add_subplot(ax1)
105+
106+
ax1.axis["left"].label.set_text("Test 1")
107+
ax1.axis["right"].label.set_text("Test 2")
108+
109+
for an in ["top"]:
110+
ax1.axis[an].set_visible(False)
111+
112+
axis = grid_helper.new_floating_axis(1, 70, axes=ax1,
113+
axis_direction="bottom")
114+
ax1.axis["z"] = axis
115+
axis.toggle(all=True, label=True)
116+
axis.label.set_axis_direction("top")
117+
axis.label.set_text("z = ?")
118+
axis.label.set_visible(True)
119+
axis.line.set_color("0.5")
120+
121+
ax2 = ax1.get_aux_axes(tr)
122+
123+
xx, yy = [67, 90, 75, 30], [2, 5, 8, 4]
124+
ax2.scatter(xx, yy)
125+
l, = ax2.plot(xx, yy, "k-")
126+
l.set_clip_path(ax1.patch)

0 commit comments

Comments
 (0)