I would like to draw additional vertical lines that will separate grouped boxplots like in the right-hand picture. The left-hand picture is the original picture (source: https://www.originlab.com/doc/Origin-Help/DoubleY-Box-Chart). I would appreciate for help how to do that by using matplotlib or seaborn package. Thank you and best regards.
The simple code I am using to create example boxplot:
fig, ax = plt.subplots(1, sharex=False, sharey=False, gridspec_kw={'hspace': 0}, figsize=(10, 5))
bill = sns.load_dataset("tips")
sns.boxplot(x="day", y="total_bill", hue="sex", data=bill, palette="PRGn")
You can use this line to draw the vertical lines using matplotlib provided you have created axes or plots. I have put x in [1,2,3,4] as an example you can replace the elements of the list with desired widths.
[ax.axvline(x, color = 'r', linestyle='--') for x in [1,2,3,4]] # you can put your desired colour instead of red.
or
[plt.axvline(x, color = 'r', linestyle='--') for x in [1,2,3,4]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With