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

Skip to content

Commit 0228cf0

Browse files
committed
Make axisartist.grid_helper_curvelinear pseudo-tests real.
The results seem to be acceptable, though the tick direction of the axis appears to be broken.
1 parent d6a83e5 commit 0228cf0

File tree

5 files changed

+222
-298
lines changed

5 files changed

+222
-298
lines changed

lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py

Lines changed: 0 additions & 298 deletions
Original file line numberDiff line numberDiff line change
@@ -474,301 +474,3 @@ def f():
474474
# yield xy, a, ""
475475

476476
return f()
477-
478-
479-
480-
def test3():
481-
482-
import numpy as np
483-
from matplotlib.transforms import Transform
484-
from matplotlib.path import Path
485-
486-
class MyTransform(Transform):
487-
input_dims = 2
488-
output_dims = 2
489-
is_separable = False
490-
491-
def __init__(self, resolution):
492-
"""
493-
Create a new Aitoff transform. Resolution is the number of steps
494-
to interpolate between each input line segment to approximate its
495-
path in curved Aitoff space.
496-
"""
497-
Transform.__init__(self)
498-
self._resolution = resolution
499-
500-
def transform(self, ll):
501-
x = ll[:, 0:1]
502-
y = ll[:, 1:2]
503-
504-
return np.concatenate((x, y-x), 1)
505-
506-
transform.__doc__ = Transform.transform.__doc__
507-
508-
transform_non_affine = transform
509-
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
510-
511-
def transform_path(self, path):
512-
vertices = path.vertices
513-
ipath = path.interpolated(self._resolution)
514-
return Path(self.transform(ipath.vertices), ipath.codes)
515-
transform_path.__doc__ = Transform.transform_path.__doc__
516-
517-
transform_path_non_affine = transform_path
518-
transform_path_non_affine.__doc__ = Transform.transform_path_non_affine.__doc__
519-
520-
def inverted(self):
521-
return MyTransformInv(self._resolution)
522-
inverted.__doc__ = Transform.inverted.__doc__
523-
524-
class MyTransformInv(Transform):
525-
input_dims = 2
526-
output_dims = 2
527-
is_separable = False
528-
529-
def __init__(self, resolution):
530-
Transform.__init__(self)
531-
self._resolution = resolution
532-
533-
def transform(self, ll):
534-
x = ll[:, 0:1]
535-
y = ll[:, 1:2]
536-
537-
return np.concatenate((x, y+x), 1)
538-
transform.__doc__ = Transform.transform.__doc__
539-
540-
def inverted(self):
541-
return MyTransform(self._resolution)
542-
inverted.__doc__ = Transform.inverted.__doc__
543-
544-
545-
546-
import matplotlib.pyplot as plt
547-
fig = plt.figure(1)
548-
fig.clf()
549-
tr = MyTransform(1)
550-
grid_helper = GridHelperCurveLinear(tr)
551-
552-
553-
from mpl_toolkits.axes_grid1.parasite_axes import host_subplot_class_factory
554-
from .axislines import Axes
555-
556-
SubplotHost = host_subplot_class_factory(Axes)
557-
558-
ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper)
559-
560-
fig.add_subplot(ax1)
561-
562-
ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal")
563-
ax1.parasites.append(ax2)
564-
ax2.plot([3, 6], [5.0, 10.])
565-
566-
ax1.set_aspect(1.)
567-
ax1.set_xlim(0, 10)
568-
ax1.set_ylim(0, 10)
569-
570-
ax1.grid(True)
571-
plt.draw()
572-
573-
574-
575-
def curvelinear_test2(fig):
576-
"""
577-
polar projection, but in a rectangular box.
578-
"""
579-
global ax1
580-
import numpy as np
581-
from . import angle_helper
582-
from matplotlib.projections import PolarAxes
583-
from matplotlib.transforms import Affine2D
584-
585-
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost, \
586-
ParasiteAxesAuxTrans
587-
import matplotlib.cbook as cbook
588-
589-
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
590-
# system in degree
591-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
592-
593-
# polar projection, which involves cycle, and also has limits in
594-
# its coordinates, needs a special method to find the extremes
595-
# (min, max of the coordinate within the view).
596-
597-
# 20, 20 : number of sampling points along x, y direction
598-
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
599-
lon_cycle = 360,
600-
lat_cycle = None,
601-
lon_minmax = None,
602-
lat_minmax = (0, np.inf),
603-
)
604-
605-
grid_locator1 = angle_helper.LocatorDMS(5)
606-
# Find a grid values appropriate for the coordinate (degree,
607-
# minute, second).
608-
609-
tick_formatter1 = angle_helper.FormatterDMS()
610-
# And also uses an appropriate formatter. Note that,the
611-
# acceptable Locator and Formatter class is a bit different than
612-
# that of mpl's, and you cannot directly use mpl's Locator and
613-
# Formatter here (but may be possible in the future).
614-
615-
grid_helper = GridHelperCurveLinear(tr,
616-
extreme_finder=extreme_finder,
617-
grid_locator1=grid_locator1,
618-
tick_formatter1=tick_formatter1
619-
)
620-
621-
622-
ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper)
623-
624-
# make ticklabels of right and top axis visible.
625-
ax1.axis["right"].major_ticklabels.set_visible(True)
626-
ax1.axis["top"].major_ticklabels.set_visible(True)
627-
628-
# let right axis shows ticklabels for 1st coordinate (angle)
629-
ax1.axis["right"].get_helper().nth_coord_ticks=0
630-
# let bottom axis shows ticklabels for 2nd coordinate (radius)
631-
ax1.axis["bottom"].get_helper().nth_coord_ticks=1
632-
633-
fig.add_subplot(ax1)
634-
635-
grid_helper = ax1.get_grid_helper()
636-
ax1.axis["lat"] = axis = grid_helper.new_floating_axis(0, 60, axes=ax1)
637-
axis.label.set_text("Test")
638-
axis.label.set_visible(True)
639-
#axis._extremes = 2, 10
640-
#axis.label.set_text("Test")
641-
#axis.major_ticklabels.set_visible(False)
642-
#axis.major_ticks.set_visible(False)
643-
axis.get_helper()._extremes=2, 10
644-
645-
ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 6, axes=ax1)
646-
#axis.major_ticklabels.set_visible(False)
647-
#axis.major_ticks.set_visible(False)
648-
axis.label.set_text("Test 2")
649-
axis.get_helper()._extremes=-180, 90
650-
651-
# A parasite axes with given transform
652-
ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal")
653-
# note that ax2.transData == tr + ax1.transData
654-
# Anthing you draw in ax2 will match the ticks and grids of ax1.
655-
ax1.parasites.append(ax2)
656-
intp = cbook.simple_linear_interpolation
657-
ax2.plot(intp(np.array([0, 30]), 50),
658-
intp(np.array([10., 10.]), 50))
659-
660-
ax1.set_aspect(1.)
661-
ax1.set_xlim(-5, 12)
662-
ax1.set_ylim(-5, 10)
663-
664-
ax1.grid(True)
665-
666-
667-
def curvelinear_test3(fig):
668-
"""
669-
polar projection, but in a rectangular box.
670-
"""
671-
global ax1, axis
672-
import numpy as np
673-
from . import angle_helper
674-
from matplotlib.projections import PolarAxes
675-
from matplotlib.transforms import Affine2D
676-
677-
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
678-
679-
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
680-
# system in degree
681-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
682-
683-
# polar projection, which involves cycle, and also has limits in
684-
# its coordinates, needs a special method to find the extremes
685-
# (min, max of the coordinate within the view).
686-
687-
# 20, 20 : number of sampling points along x, y direction
688-
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
689-
lon_cycle = 360,
690-
lat_cycle = None,
691-
lon_minmax = None,
692-
lat_minmax = (0, np.inf),
693-
)
694-
695-
grid_locator1 = angle_helper.LocatorDMS(12)
696-
# Find a grid values appropriate for the coordinate (degree,
697-
# minute, second).
698-
699-
tick_formatter1 = angle_helper.FormatterDMS()
700-
# And also uses an appropriate formatter. Note that,the
701-
# acceptable Locator and Formatter class is a bit different than
702-
# that of mpl's, and you cannot directly use mpl's Locator and
703-
# Formatter here (but may be possible in the future).
704-
705-
grid_helper = GridHelperCurveLinear(tr,
706-
extreme_finder=extreme_finder,
707-
grid_locator1=grid_locator1,
708-
tick_formatter1=tick_formatter1
709-
)
710-
711-
712-
ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper)
713-
714-
for axis in list(six.itervalues(ax1.axis)):
715-
axis.set_visible(False)
716-
717-
fig.add_subplot(ax1)
718-
719-
grid_helper = ax1.get_grid_helper()
720-
ax1.axis["lat1"] = axis = grid_helper.new_floating_axis(0, 130,
721-
axes=ax1,
722-
axis_direction="left"
723-
)
724-
axis.label.set_text("Test")
725-
axis.label.set_visible(True)
726-
axis.get_helper()._extremes=0.001, 10
727-
728-
729-
730-
grid_helper = ax1.get_grid_helper()
731-
ax1.axis["lat2"] = axis = grid_helper.new_floating_axis(0, 50, axes=ax1,
732-
axis_direction="right")
733-
axis.label.set_text("Test")
734-
axis.label.set_visible(True)
735-
axis.get_helper()._extremes=0.001, 10
736-
737-
ax1.axis["lon"] = axis = grid_helper.new_floating_axis(1, 10,
738-
axes=ax1,
739-
axis_direction="bottom")
740-
axis.label.set_text("Test 2")
741-
axis.get_helper()._extremes= 50, 130
742-
axis.major_ticklabels.set_axis_direction("top")
743-
axis.label.set_axis_direction("top")
744-
745-
grid_helper.grid_finder.grid_locator1.den = 5
746-
grid_helper.grid_finder.grid_locator2._nbins = 5
747-
748-
749-
# # A parasite axes with given transform
750-
# ax2 = ParasiteAxesAuxTrans(ax1, tr, "equal")
751-
# # note that ax2.transData == tr + ax1.transData
752-
# # Anthing you draw in ax2 will match the ticks and grids of ax1.
753-
# ax1.parasites.append(ax2)
754-
# intp = cbook.simple_linear_interpolation
755-
# ax2.plot(intp(np.array([0, 30]), 50),
756-
# intp(np.array([10., 10.]), 50))
757-
758-
ax1.set_aspect(1.)
759-
ax1.set_xlim(-5, 12)
760-
ax1.set_ylim(-5, 10)
761-
762-
ax1.grid(True)
763-
764-
if __name__ == "__main__":
765-
import matplotlib.pyplot as plt
766-
fig = plt.figure(1, figsize=(5, 5))
767-
fig.clf()
768-
769-
#test3()
770-
#curvelinear_test2(fig)
771-
curvelinear_test3(fig)
772-
773-
#plt.draw()
774-
plt.show()

0 commit comments

Comments
 (0)