Repository: statsmodels/statsmodels (Python)

Issue:
Mistake in labels of qqplot_2samples
#### Describe the bug

statsmodels.graphics.gofplots.qqplot_2samples docs have a bug.
data1 appears on y-axis and data2 appears on x-axis. This is contrary to what is mentioned in the docs.

#### Code Sample, a copy-pastable example if possible



```python
import matplotlib.pypot as plt
import numpy as np
from statsmodels.graphics.gofplots import qqplot_2samples
x=np.random.normal(10,1,(100,))
y=np.random.normal(1,.1,(100,))
qqplot_2samples(xx, xy, 'x', 'y')
plt.show()
```





Hints:

Patch:
diff --git a/statsmodels/graphics/agreement.py b/statsmodels/graphics/agreement.py
--- a/statsmodels/graphics/agreement.py
+++ b/statsmodels/graphics/agreement.py
@@ -6,6 +6,7 @@
 '''
 
 import numpy as np
+
 from . import utils
 
 
diff --git a/statsmodels/graphics/api.py b/statsmodels/graphics/api.py
--- a/statsmodels/graphics/api.py
+++ b/statsmodels/graphics/api.py
@@ -1,13 +1,43 @@
-# flake8: noqa
-from .functional import hdrboxplot, fboxplot, rainbowplot
+from . import tsaplots as tsa
+from .agreement import mean_diff_plot
+from .boxplots import beanplot, violinplot
 from .correlation import plot_corr, plot_corr_grid
-from .gofplots import qqplot
-from .boxplots import violinplot, beanplot
-from .regressionplots import (abline_plot, plot_regress_exog, plot_fit,
-                              plot_partregress, plot_partregress_grid,
-                              plot_ccpr, plot_ccpr_grid, influence_plot,
-                              plot_leverage_resid2)
 from .factorplots import interaction_plot
+from .functional import fboxplot, hdrboxplot, rainbowplot
+from .gofplots import qqplot
 from .plottools import rainbow
-from . import tsaplots as tsa
-from .agreement import mean_diff_plot
+from .regressionplots import (
+    abline_plot,
+    influence_plot,
+    plot_ccpr,
+    plot_ccpr_grid,
+    plot_fit,
+    plot_leverage_resid2,
+    plot_partregress,
+    plot_partregress_grid,
+    plot_regress_exog,
+)
+
+__all__ = [
+    "abline_plot",
+    "beanplot",
+    "fboxplot",
+    "hdrboxplot",
+    "influence_plot",
+    "interaction_plot",
+    "mean_diff_plot",
+    "plot_ccpr",
+    "plot_ccpr_grid",
+    "plot_corr",
+    "plot_corr_grid",
+    "plot_fit",
+    "plot_leverage_resid2",
+    "plot_partregress",
+    "plot_partregress_grid",
+    "plot_regress_exog",
+    "qqplot",
+    "rainbow",
+    "rainbowplot",
+    "tsa",
+    "violinplot",
+]
diff --git a/statsmodels/graphics/boxplots.py b/statsmodels/graphics/boxplots.py
--- a/statsmodels/graphics/boxplots.py
+++ b/statsmodels/graphics/boxplots.py
@@ -8,7 +8,6 @@
 
 from . import utils
 
-
 __all__ = ['violinplot', 'beanplot']
 
 
diff --git a/statsmodels/graphics/dotplots.py b/statsmodels/graphics/dotplots.py
--- a/statsmodels/graphics/dotplots.py
+++ b/statsmodels/graphics/dotplots.py
@@ -1,4 +1,5 @@
 import numpy as np
+
 from . import utils
 
 
diff --git a/statsmodels/graphics/factorplots.py b/statsmodels/graphics/factorplots.py
--- a/statsmodels/graphics/factorplots.py
+++ b/statsmodels/graphics/factorplots.py
@@ -3,6 +3,7 @@
 Authors:    Josef Perktold, Skipper Seabold, Denis A. Engemann
 """
 from statsmodels.compat.python import lrange
+
 import numpy as np
 
 from statsmodels.graphics.plottools import rainbow
diff --git a/statsmodels/graphics/gofplots.py b/statsmodels/graphics/gofplots.py
--- a/statsmodels/graphics/gofplots.py
+++ b/statsmodels/graphics/gofplots.py
@@ -706,10 +706,12 @@ def qqplot_2samples(
     Parameters
     ----------
     data1 : {array_like, ProbPlot}
-        Data to plot along x axis.
+        Data to plot along x axis. If the sample sizes are unequal, the longer
+        series is always plotted along the x-axis.
     data2 : {array_like, ProbPlot}
         Data to plot along y axis. Does not need to have the same number of
-        observations as data 1.
+        observations as data 1. If the sample sizes are unequal, the longer
+        series is always plotted along the x-axis.
     xlabel : {None, str}
         User-provided labels for the x-axis. If None (default),
         other values are used.
@@ -772,7 +774,7 @@ def qqplot_2samples(
 
     if not isinstance(data2, ProbPlot):
         data2 = ProbPlot(data2)
-    if data2.data.shape[0] >= data1.data.shape[0]:
+    if data2.data.shape[0] > data1.data.shape[0]:
         fig = data1.qqplot(
             xlabel=ylabel, ylabel=xlabel, line=line, other=data2, ax=ax
         )
diff --git a/statsmodels/graphics/mosaicplot.py b/statsmodels/graphics/mosaicplot.py
--- a/statsmodels/graphics/mosaicplot.py
+++ b/statsmodels/graphics/mosaicplot.py
@@ -8,13 +8,15 @@
 # Author: Enrico Giampieri - 21 Jan 2013
 
 from statsmodels.compat.python import lrange, lzip
-import numpy as np
+
 from itertools import product
 
-from numpy import iterable, r_, cumsum, array
-from statsmodels.graphics import utils
+import numpy as np
+from numpy import array, cumsum, iterable, r_
 from pandas import DataFrame
 
+from statsmodels.graphics import utils
+
 __all__ = ["mosaic"]
 
 
@@ -620,6 +622,7 @@ def mosaic(data, index=None, ax=None, horizontal=True, gap=0.005,
                          " See examples.")
 
     from matplotlib.patches import Rectangle
+
     #from pylab import Rectangle
     fig, ax = utils.create_mpl_ax(ax)
     # normalize the data to a dict with tuple of strings as keys
diff --git a/statsmodels/graphics/plot_grids.py b/statsmodels/graphics/plot_grids.py
--- a/statsmodels/graphics/plot_grids.py
+++ b/statsmodels/graphics/plot_grids.py
@@ -16,7 +16,6 @@
 
 from . import utils
 
-
 __all__ = ['scatter_ellipse']
 
 
diff --git a/statsmodels/graphics/plottools.py b/statsmodels/graphics/plottools.py
--- a/statsmodels/graphics/plottools.py
+++ b/statsmodels/graphics/plottools.py
@@ -1,5 +1,6 @@
 import numpy as np
 
+
 def rainbow(n):
     """
     Returns a list of colors sampled at equal intervals over the spectrum.
diff --git a/statsmodels/graphics/regressionplots.py b/statsmodels/graphics/regressionplots.py
--- a/statsmodels/graphics/regressionplots.py
+++ b/statsmodels/graphics/regressionplots.py
@@ -10,27 +10,28 @@
 2011-10-27 : docstrings
 
 '''
-from statsmodels.compat.python import lrange, lzip
 from statsmodels.compat.pandas import Appender
+from statsmodels.compat.python import lrange, lzip
 
 import numpy as np
 import pandas as pd
 from patsy import dmatrix
 
-from statsmodels.regression.linear_model import OLS, GLS, WLS
-from statsmodels.genmod.generalized_linear_model import GLM
 from statsmodels.genmod.generalized_estimating_equations import GEE
-from statsmodels.sandbox.regression.predstd import wls_prediction_std
+from statsmodels.genmod.generalized_linear_model import GLM
 from statsmodels.graphics import utils
 from statsmodels.nonparametric.smoothers_lowess import lowess
+from statsmodels.regression.linear_model import GLS, OLS, WLS
+from statsmodels.sandbox.regression.predstd import wls_prediction_std
 from statsmodels.tools.tools import maybe_unwrap_results
 
 from ._regressionplots_doc import (
     _plot_added_variable_doc,
-    _plot_partial_residuals_doc,
     _plot_ceres_residuals_doc,
     _plot_influence_doc,
-    _plot_leverage_resid2_doc)
+    _plot_leverage_resid2_doc,
+    _plot_partial_residuals_doc,
+)
 
 __all__ = ['plot_fit', 'plot_regress_exog', 'plot_partregress', 'plot_ccpr',
            'plot_regress_exog', 'plot_partregress_grid', 'plot_ccpr_grid',
@@ -929,7 +930,7 @@ def influence_plot(results, external=True, alpha=.05, criterion="cooks",
 def _plot_leverage_resid2(results, influence, alpha=.05, ax=None,
                          **kwargs):
 
-    from scipy.stats import zscore, norm
+    from scipy.stats import norm, zscore
     fig, ax = utils.create_mpl_ax(ax)
 
     infl = influence
diff --git a/statsmodels/graphics/tukeyplot.py b/statsmodels/graphics/tukeyplot.py
--- a/statsmodels/graphics/tukeyplot.py
+++ b/statsmodels/graphics/tukeyplot.py
@@ -1,6 +1,6 @@
-import numpy as np
-import matplotlib.pyplot as plt
 import matplotlib.lines as lines
+import matplotlib.pyplot as plt
+import numpy as np
 
 
 def tukeyplot(results, dim=None, yticklabels=None):


Test patch:
diff --git a/statsmodels/graphics/tests/test_agreement.py b/statsmodels/graphics/tests/test_agreement.py
--- a/statsmodels/graphics/tests/test_agreement.py
+++ b/statsmodels/graphics/tests/test_agreement.py
@@ -4,7 +4,6 @@
 
 from statsmodels.graphics.agreement import mean_diff_plot
 
-
 try:
     import matplotlib.pyplot as plt
 except ImportError:
diff --git a/statsmodels/graphics/tests/test_boxplots.py b/statsmodels/graphics/tests/test_boxplots.py
--- a/statsmodels/graphics/tests/test_boxplots.py
+++ b/statsmodels/graphics/tests/test_boxplots.py
@@ -1,8 +1,8 @@
 import numpy as np
 import pytest
 
-from statsmodels.graphics.boxplots import violinplot, beanplot
 from statsmodels.datasets import anes96
+from statsmodels.graphics.boxplots import beanplot, violinplot
 
 try:
     import matplotlib.pyplot as plt
diff --git a/statsmodels/graphics/tests/test_correlation.py b/statsmodels/graphics/tests/test_correlation.py
--- a/statsmodels/graphics/tests/test_correlation.py
+++ b/statsmodels/graphics/tests/test_correlation.py
@@ -1,8 +1,8 @@
 import numpy as np
 import pytest
 
-from statsmodels.graphics.correlation import plot_corr, plot_corr_grid
 from statsmodels.datasets import randhie
+from statsmodels.graphics.correlation import plot_corr, plot_corr_grid
 
 
 @pytest.mark.matplotlib
diff --git a/statsmodels/graphics/tests/test_dotplot.py b/statsmodels/graphics/tests/test_dotplot.py
--- a/statsmodels/graphics/tests/test_dotplot.py
+++ b/statsmodels/graphics/tests/test_dotplot.py
@@ -1,8 +1,8 @@
 import numpy as np
+import pandas as pd
 import pytest
 
 from statsmodels.graphics.dotplots import dot_plot
-import pandas as pd
 
 # If true, the output is written to a multi-page pdf file.
 pdf_output = False
diff --git a/statsmodels/graphics/tests/test_factorplots.py b/statsmodels/graphics/tests/test_factorplots.py
--- a/statsmodels/graphics/tests/test_factorplots.py
+++ b/statsmodels/graphics/tests/test_factorplots.py
@@ -1,9 +1,9 @@
 import numpy as np
-from numpy.testing import assert_raises, assert_equal
+from numpy.testing import assert_equal, assert_raises
 from pandas import Series
 import pytest
 
-from statsmodels.graphics.factorplots import interaction_plot, _recode
+from statsmodels.graphics.factorplots import _recode, interaction_plot
 
 try:
     import matplotlib.pyplot as plt
diff --git a/statsmodels/graphics/tests/test_gofplots.py b/statsmodels/graphics/tests/test_gofplots.py
--- a/statsmodels/graphics/tests/test_gofplots.py
+++ b/statsmodels/graphics/tests/test_gofplots.py
@@ -647,7 +647,7 @@ def test_correct_labels(
     ax = fig.get_axes()[0]
     x_label = ax.get_xlabel()
     y_label = ax.get_ylabel()
-    if x_size <= y_size:
+    if x_size < y_size:
         if not labels:
             assert "2nd" in x_label
             assert "1st" in y_label
@@ -661,3 +661,28 @@ def test_correct_labels(
         else:
             assert "X" in x_label
             assert "Y" in y_label
+
+
+@pytest.mark.matplotlib
+def test_axis_order(close_figures):
+    xx = np.random.normal(10, 1, (100,))
+    xy = np.random.normal(1, 0.01, (100,))
+    fig = qqplot_2samples(xx, xy, "x", "y")
+    ax = fig.get_axes()[0]
+    y_range = np.diff(ax.get_ylim())[0]
+    x_range = np.diff(ax.get_xlim())[0]
+    assert y_range < x_range
+
+    xx_long = np.random.normal(10, 1, (1000,))
+    fig = qqplot_2samples(xx_long, xy, "x", "y")
+    ax = fig.get_axes()[0]
+    y_range = np.diff(ax.get_ylim())[0]
+    x_range = np.diff(ax.get_xlim())[0]
+    assert y_range < x_range
+
+    xy_long = np.random.normal(1, 0.01, (1000,))
+    fig = qqplot_2samples(xx, xy_long, "x", "y")
+    ax = fig.get_axes()[0]
+    y_range = np.diff(ax.get_ylim())[0]
+    x_range = np.diff(ax.get_xlim())[0]
+    assert x_range < y_range
diff --git a/statsmodels/graphics/tests/test_regressionplots.py b/statsmodels/graphics/tests/test_regressionplots.py
--- a/statsmodels/graphics/tests/test_regressionplots.py
+++ b/statsmodels/graphics/tests/test_regressionplots.py
@@ -1,13 +1,23 @@
 import numpy as np
+from numpy.testing import assert_array_less, assert_equal, assert_raises
+from pandas import DataFrame, Series
 import pytest
+
 import statsmodels.api as sm
-from numpy.testing import assert_equal, assert_raises, assert_array_less
-from statsmodels.graphics.regressionplots import (plot_fit, plot_ccpr,
-                  plot_regress_exog, abline_plot,
-                  plot_partregress_grid, plot_ccpr_grid, add_lowess,
-                  plot_added_variable, plot_partial_residuals,
-                  plot_ceres_residuals, influence_plot, plot_leverage_resid2)
-from pandas import Series, DataFrame
+from statsmodels.graphics.regressionplots import (
+    abline_plot,
+    add_lowess,
+    influence_plot,
+    plot_added_variable,
+    plot_ccpr,
+    plot_ccpr_grid,
+    plot_ceres_residuals,
+    plot_fit,
+    plot_leverage_resid2,
+    plot_partial_residuals,
+    plot_partregress_grid,
+    plot_regress_exog,
+)
 
 try:
     import matplotlib.pyplot as plt