@@ -3778,7 +3778,7 @@ def test_horiz_violinplot_baseline():
3778
3778
# First 9 digits of frac(sqrt(19))
3779
3779
np .random .seed (358898943 )
3780
3780
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3781
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = False ,
3781
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = False ,
3782
3782
showextrema = False , showmedians = False )
3783
3783
3784
3784
@@ -3788,7 +3788,7 @@ def test_horiz_violinplot_showmedians():
3788
3788
# First 9 digits of frac(sqrt(23))
3789
3789
np .random .seed (795831523 )
3790
3790
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3791
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = False ,
3791
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = False ,
3792
3792
showextrema = False , showmedians = True )
3793
3793
3794
3794
@@ -3798,7 +3798,7 @@ def test_horiz_violinplot_showmeans():
3798
3798
# First 9 digits of frac(sqrt(29))
3799
3799
np .random .seed (385164807 )
3800
3800
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3801
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = True ,
3801
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = True ,
3802
3802
showextrema = False , showmedians = False )
3803
3803
3804
3804
@@ -3808,7 +3808,7 @@ def test_horiz_violinplot_showextrema():
3808
3808
# First 9 digits of frac(sqrt(31))
3809
3809
np .random .seed (567764362 )
3810
3810
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3811
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = False ,
3811
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = False ,
3812
3812
showextrema = True , showmedians = False )
3813
3813
3814
3814
@@ -3818,7 +3818,7 @@ def test_horiz_violinplot_showall():
3818
3818
# First 9 digits of frac(sqrt(37))
3819
3819
np .random .seed (82762530 )
3820
3820
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3821
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = True ,
3821
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = True ,
3822
3822
showextrema = True , showmedians = True ,
3823
3823
quantiles = [[0.1 , 0.9 ], [0.2 , 0.8 ], [0.3 , 0.7 ], [0.4 , 0.6 ]])
3824
3824
@@ -3829,7 +3829,7 @@ def test_horiz_violinplot_custompoints_10():
3829
3829
# First 9 digits of frac(sqrt(41))
3830
3830
np .random .seed (403124237 )
3831
3831
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3832
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = False ,
3832
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = False ,
3833
3833
showextrema = False , showmedians = False , points = 10 )
3834
3834
3835
3835
@@ -3839,7 +3839,7 @@ def test_horiz_violinplot_custompoints_200():
3839
3839
# First 9 digits of frac(sqrt(43))
3840
3840
np .random .seed (557438524 )
3841
3841
data = [np .random .normal (size = 100 ) for _ in range (4 )]
3842
- ax .violinplot (data , positions = range (4 ), vert = False , showmeans = False ,
3842
+ ax .violinplot (data , positions = range (4 ), orientation = 'horizontal' , showmeans = False ,
3843
3843
showextrema = False , showmedians = False , points = 200 )
3844
3844
3845
3845
@@ -3850,11 +3850,11 @@ def test_violinplot_sides():
3850
3850
data = [np .random .normal (size = 100 )]
3851
3851
# Check horizontal violinplot
3852
3852
for pos , side in zip ([0 , - 0.5 , 0.5 ], ['both' , 'low' , 'high' ]):
3853
- ax .violinplot (data , positions = [pos ], vert = False , showmeans = False ,
3853
+ ax .violinplot (data , positions = [pos ], orientation = 'horizontal' , showmeans = False ,
3854
3854
showextrema = True , showmedians = True , side = side )
3855
3855
# Check vertical violinplot
3856
3856
for pos , side in zip ([4 , 3.5 , 4.5 ], ['both' , 'low' , 'high' ]):
3857
- ax .violinplot (data , positions = [pos ], vert = True , showmeans = False ,
3857
+ ax .violinplot (data , positions = [pos ], orientation = 'vertical' , showmeans = False ,
3858
3858
showextrema = True , showmedians = True , side = side )
3859
3859
3860
3860
@@ -9065,3 +9065,40 @@ def test_latex_pie_percent(fig_test, fig_ref):
9065
9065
9066
9066
ax1 = fig_ref .subplots ()
9067
9067
ax1 .pie (data , autopct = r"%1.0f\%%" , textprops = {'usetex' : True })
9068
+
9069
+
9070
+ @check_figures_equal (extensions = ['png' ])
9071
+ def test_violinplot_orientation (fig_test , fig_ref ):
9072
+ # Test the `orientation : {'vertical', 'horizontal'}`
9073
+ # parameter and deprecation of `vert: bool`.
9074
+ fig , axs = plt .subplots (nrows = 1 , ncols = 3 )
9075
+ np .random .seed (19680801 )
9076
+ all_data = [np .random .normal (0 , std , 100 ) for std in range (6 , 10 )]
9077
+
9078
+ axs [0 ].violinplot (all_data ) # Default vertical plot.
9079
+ # xticks and yticks should be at their default position.
9080
+ assert all (axs [0 ].get_xticks () == np .array (
9081
+ [0.5 , 1. , 1.5 , 2. , 2.5 , 3. , 3.5 , 4. , 4.5 ]))
9082
+ assert all (axs [0 ].get_yticks () == np .array (
9083
+ [- 30. , - 20. , - 10. , 0. , 10. , 20. , 30. ]))
9084
+
9085
+ # Horizontal plot using new `orientation` keyword.
9086
+ axs [1 ].violinplot (all_data , orientation = 'horizontal' )
9087
+ # xticks and yticks should be swapped.
9088
+ assert all (axs [1 ].get_xticks () == np .array (
9089
+ [- 30. , - 20. , - 10. , 0. , 10. , 20. , 30. ]))
9090
+ assert all (axs [1 ].get_yticks () == np .array (
9091
+ [0.5 , 1. , 1.5 , 2. , 2.5 , 3. , 3.5 , 4. , 4.5 ]))
9092
+
9093
+ plt .close ()
9094
+
9095
+ # Deprecation of `vert: bool` keyword
9096
+ with pytest .warns (mpl .MatplotlibDeprecationWarning ,
9097
+ match = 'vert: bool was deprecated in Matplotlib 3.10' ):
9098
+ # Compare images between a figure that
9099
+ # uses vert and one that uses orientation.
9100
+ ax_ref = fig_ref .subplots ()
9101
+ ax_ref .violinplot (all_data , vert = False )
9102
+
9103
+ ax_test = fig_test .subplots ()
9104
+ ax_test .violinplot (all_data , orientation = 'horizontal' )
0 commit comments