This Python tool helps visualizing statistical significance on existing Matplotlib plots by adding significance bars and p-value labels between chosen pairs of columns.
MIT License
8
stars
2
forks
source link
“IndexError: list index out of range” for hue plot #5
Hi there! Thanks for reporting this issue. It seems like seaborn<0.13.0 does not work, upgrading to seaborn>=0.13.0 should fix the problem. I will make the error message clearer :)
pip install starbars
version:python==3.8.8
import starbars
Example with hue used in plots
data = { 'Student': ['A', 'B', 'C', 'D', 'E', 'F'], 'Score': [85, 90, 88, 72, 95, 78], 'Subject': ['Math', 'Math', 'Science', 'Science', 'Math', 'Science'], 'Gender': ['Male', 'Female', 'Male', 'Female', 'Male', 'Female'] } df = pd.DataFrame(data) plt.figure(figsize=(8, 6)) plot = sns.barplot(data=df, x='Subject', y='Score', hue='Gender', palette='deep') plt.title("Average Scores by Subject and Gender") plt.xlabel("Subject") plt.ylabel("Score")
annotations = [(('Male', 'Math'), ('Female', 'Science'), 0.01), ('Science', 'Math', 0.03)] starbars.draw_annotation(annotations)
plt.show()
IndexError Traceback (most recent call last) Cell In[3], line 22 19 plt.ylabel("Score") 21 annotations = [(('Male', 'Math'), ('Female', 'Science'), 0.01), ('Science', 'Math', 0.03)] ---> 22 starbars.draw_annotation(annotations) 24 plt.show()
File ~/anaconda3/lib/python3.8/site-packages/starbars/init.py:37, in draw_annotation(annotations, ax, ns_show, bar_margin, tip_length, fontsize, top_margin) 35 # Get the positions of the values 36 for (x1, x2, pvalue) in annotations: ---> 37 x1_position, x2_position = get_positions(ax, x1, x2) 38 y1 = height + bar_margin 0.8 (height - y_min) 39 h = tip_length 0.8 (height - y_min)
File ~/anaconda3/lib/python3.8/site-packages/starbars/utils.py:73, in get_positions(ax, x1, x2) 70 group1_position, group2_position = get_tick_position(ax, group1, group2) 72 x1_position = cleaned_positions[x1][group1_position] ---> 73 x2_position = cleaned_positions[x2][group2_position] 75 else: 76 x1_position, x2_position = get_tick_position(ax, x1, x2)
IndexError: list index out of range