Flipping the x & y axis in diagram resulting from plot_simultaneous() in a Tukey HSD test

82 views Asked by At

I have a data set and I need to check significant differences between 5 groups. The resulting diagram shows test groups on the y-axis and the response on the x-axis. However I want the figure to show the reverse, that is response on the y-axis and test groups on the x-axis. So the confidence interval bars should be vertical as opposed to the horizontal shown below. How can this be achieved?

Here is a fully reproducible sample of my code:

import pandas as pd
from statsmodels.stats.multicomp import MultiComparison
from statsmodels.stats.multicomp import pairwise_tukeyhsd

response = [4,5, 7,6, 2,3, 12,9, 7,7]
groups = ["test1","test1","test2","test2","test3","test3","test4","test4","test5","test5"]

result = pairwise_tukeyhsd(response, groups, alpha=0.05)

# Plot the results
fig, ax = plt.subplots(figsize=(1, 1))

# Customize the plot appearance
result.plot_simultaneous(
    comparison_name='test3',
    ax = ax,
    figsize = (8,5),
    xlabel = "Response",     # X-axis label
    ylabel = 'Test Group',   # Y-axis label
)

# Reverse the order of labels on the y-axis
ax.invert_yaxis()

# Add a title to the plot
ax.set_title(f'Tukey\'s HSD Test for Response')

# Show the plot
plt.show()

enter image description here

0

There are 0 answers