How to rank plot in seaborn boxplot?
<p>Take the following seaborn boxplot for example, from <a href="https://stanford.edu/~mwaskom/software/seaborn/examples/horizontal_boxplot.html" rel="nofollow">https://stanford.edu/~mwaskom/software/seaborn/examples/horizontal_boxplot.html</a></p>

<pre><code>import numpy as np
import seaborn as sns
sns.set(style="ticks", palette="muted", color_codes=True)

# Load the example planets dataset
planets = sns.load_dataset("planets")

# Plot the orbital period with horizontal boxes
ax = sns.boxplot(x="distance", y="method", data=planets,
                 whis=np.inf, color="c")

# Add in points to show each observation
sns.stripplot(x="distance", y="method", data=planets,
              jitter=True, size=3, color=".3", linewidth=0)


# Make the quantitative axis logarithmic
ax.set_xscale("log")
sns.despine(trim=True)
</code></pre>

<p><a href="http://i.stack.imgur.com/O298h.png" rel="nofollow"><img src="http://i.stack.imgur.com/O298h.png" alt="enter image description here"></a></p>

<p>Is it possible to "rank" the entries, from greatest to lowest (or vice versa)? In this plot, "astrometry" should be the last entry, if ranking from greatest to lowest.</p>

<p>You can use the <code>order</code> argument in the <code>sns.boxplot</code> and <code>sns.stripplot</code> functions to order your "boxes". Here is an example of how to do this (since it is not completely clear what you mean by "greatest to lowest", i.e. which variable you want to sort the entries based on, I am assume you want to sort them based on the sum of their "distance" values, you should be able to edit the solution to fit your needs if you want to sort them based on a different value):</p>

<pre><code>import numpy as np
import seaborn as sns
sns.set(style="ticks", palette="muted", color_codes=True)

# Load the example planets dataset
planets = sns.load_dataset("planets")

# Determine the order of boxes
order = planets.groupby(by=["method"])["distance"].sum().iloc[::-1].index

# Plot the orbital period with horizontal boxes
ax = sns.boxplot(x="distance", y="method", data=planets,
                 order=order, whis=np.inf, color="c")

# Add in points to show each observation
sns.stripplot(x="distance", y="method", data=planets, order=order,
              jitter=True, size=3, color=".3", linewidth=0)


# Make the quantitative axis logarithmic
ax.set_xscale("log")
sns.despine(trim=True)
</code></pre>

<p>This modifed code (notice the use of the <code>order</code> argument in the <code>sns.boxplot</code> and <code>sns.stripplot</code> functions) will produce the following figure:</p>

<p><a href="http://i.stack.imgur.com/LEQgl.png" rel="nofollow"><img src="http://i.stack.imgur.com/LEQgl.png" alt="Ordered Boxplot"></a></p>

python pandas matplotlib seaborn