@@ -585,6 +585,19 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs):
585
585
xmax += 0.05
586
586
return (xmin , xmax )
587
587
588
+ def _validate_axis_limits (self , limit , convert ):
589
+ """
590
+ If the axis limits being set are infinite, this function
591
+
592
+ raises an error.
593
+
594
+ """
595
+ if limit is not None :
596
+ if (isinstance (limit , float ) and
597
+ (not np .isreal (limit ) or not np .isfinite (limit ))):
598
+ raise ValueError ("NaN or Inf cannot be the argument values" )
599
+ return convert (limit )
600
+
588
601
def set_xlim3d (self , left = None , right = None , emit = True , auto = False , ** kw ):
589
602
"""
590
603
Set 3D x limits.
@@ -603,10 +616,8 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw):
603
616
left , right = left
604
617
605
618
self ._process_unit_info (xdata = (left , right ))
606
- if left is not None :
607
- left = self .convert_xunits (left )
608
- if right is not None :
609
- right = self .convert_xunits (right )
619
+ left = self ._validate_axis_limits (left , self .convert_xunits )
620
+ right = self ._validate_axis_limits (right , self .convert_xunits )
610
621
611
622
old_left , old_right = self .get_xlim ()
612
623
if left is None :
@@ -663,10 +674,8 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
663
674
top = self .convert_yunits (top )
664
675
665
676
old_bottom , old_top = self .get_ylim ()
666
- if bottom is None :
667
- bottom = old_bottom
668
- if top is None :
669
- top = old_top
677
+ bottom = self ._validate_axis_limits (bottom , self .convert_yunits )
678
+ top = self ._validate_axis_limits (top , self .convert_yunits )
670
679
671
680
if top == bottom :
672
681
warnings .warn (('Attempting to set identical bottom==top results\n '
@@ -711,10 +720,8 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw):
711
720
bottom , top = bottom
712
721
713
722
self ._process_unit_info (zdata = (bottom , top ))
714
- if bottom is not None :
715
- bottom = self .convert_zunits (bottom )
716
- if top is not None :
717
- top = self .convert_zunits (top )
723
+ bottom = self ._validate_axis_limits (bottom , self .convert_yunits )
724
+ top = self ._validate_axis_limits (top , self .convert_yunits )
718
725
719
726
old_bottom , old_top = self .get_zlim ()
720
727
if bottom is None :
0 commit comments