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