@@ -605,3 +605,80 @@ def test_subfigure_clabel():
605605 CS = ax .contour (X , Y , Z )
606606 ax .clabel (CS , inline = True , fontsize = 10 )
607607 ax .set_title ("Simplest default with labels" )
608+
609+
610+ @pytest .mark .parametrize (
611+ "style" , ['solid' , 'dashed' , 'dashdot' , 'dotted' ])
612+ def test_linestyles (style ):
613+ delta = 0.025
614+ x = np .arange (- 3.0 , 3.0 , delta )
615+ y = np .arange (- 2.0 , 2.0 , delta )
616+ X , Y = np .meshgrid (x , y )
617+ Z1 = np .exp (- X ** 2 - Y ** 2 )
618+ Z2 = np .exp (- (X - 1 )** 2 - (Y - 1 )** 2 )
619+ Z = (Z1 - Z2 ) * 2
620+
621+ # Positive contour defaults to solid
622+ fig1 , ax1 = plt .subplots ()
623+ CS1 = ax1 .contour (X , Y , Z , 6 , colors = 'k' )
624+ ax1 .clabel (CS1 , fontsize = 9 , inline = True )
625+ ax1 .set_title ('Single color - positive contours solid (default)' )
626+ assert CS1 .linestyles is None # default
627+
628+ # Change linestyles using linestyles kwarg
629+ fig2 , ax2 = plt .subplots ()
630+ CS2 = ax2 .contour (X , Y , Z , 6 , colors = 'k' , linestyles = style )
631+ ax2 .clabel (CS2 , fontsize = 9 , inline = True )
632+ ax2 .set_title (f'Single color - positive contours { style } ' )
633+ assert CS2 .linestyles == style
634+
635+ # Ensure linestyles do not change when negative_linestyles is defined
636+ fig3 , ax3 = plt .subplots ()
637+ CS3 = ax3 .contour (X , Y , Z , 6 , colors = 'k' , linestyles = style ,
638+ negative_linestyles = 'dashdot' )
639+ ax3 .clabel (CS3 , fontsize = 9 , inline = True )
640+ ax3 .set_title (f'Single color - positive contours { style } ' )
641+ assert CS3 .linestyles == style
642+
643+
644+ @pytest .mark .parametrize (
645+ "style" , ['solid' , 'dashed' , 'dashdot' , 'dotted' ])
646+ def test_negative_linestyles (style ):
647+ delta = 0.025
648+ x = np .arange (- 3.0 , 3.0 , delta )
649+ y = np .arange (- 2.0 , 2.0 , delta )
650+ X , Y = np .meshgrid (x , y )
651+ Z1 = np .exp (- X ** 2 - Y ** 2 )
652+ Z2 = np .exp (- (X - 1 )** 2 - (Y - 1 )** 2 )
653+ Z = (Z1 - Z2 ) * 2
654+
655+ # Negative contour defaults to dashed
656+ fig1 , ax1 = plt .subplots ()
657+ CS1 = ax1 .contour (X , Y , Z , 6 , colors = 'k' )
658+ ax1 .clabel (CS1 , fontsize = 9 , inline = True )
659+ ax1 .set_title ('Single color - negative contours dashed (default)' )
660+ assert CS1 .negative_linestyles == 'dashed' # default
661+
662+ # Change negative_linestyles using rcParams
663+ plt .rcParams ['contour.negative_linestyle' ] = style
664+ fig2 , ax2 = plt .subplots ()
665+ CS2 = ax2 .contour (X , Y , Z , 6 , colors = 'k' )
666+ ax2 .clabel (CS2 , fontsize = 9 , inline = True )
667+ ax2 .set_title (f'Single color - negative contours { style } '
668+ '(using rcParams)' )
669+ assert CS2 .negative_linestyles == style
670+
671+ # Change negative_linestyles using negative_linestyles kwarg
672+ fig3 , ax3 = plt .subplots ()
673+ CS3 = ax3 .contour (X , Y , Z , 6 , colors = 'k' , negative_linestyles = style )
674+ ax3 .clabel (CS3 , fontsize = 9 , inline = True )
675+ ax3 .set_title (f'Single color - negative contours { style } ' )
676+ assert CS3 .negative_linestyles == style
677+
678+ # Ensure negative_linestyles do not change when linestyles is defined
679+ fig4 , ax4 = plt .subplots ()
680+ CS4 = ax4 .contour (X , Y , Z , 6 , colors = 'k' , linestyles = 'dashdot' ,
681+ negative_linestyles = style )
682+ ax4 .clabel (CS4 , fontsize = 9 , inline = True )
683+ ax4 .set_title (f'Single color - negative contours { style } ' )
684+ assert CS4 .negative_linestyles == style
0 commit comments