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