Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Violin Plot Example
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
shou = np.random.random(100)
chiku = np.log(shou)
bai = np.exp2(shou)
data=[shou, chiku, bai]
ll = ["shou (" + str(np.round(np.mean(shou),decimals=2))+")", "chiku (" + str(np.round(np.mean(chiku),decimals=2))+")", "bai (" + str(np.round(np.mean(bai),decimals=2))+")"]
plt.rcParams['figure.subplot.bottom'] = 0.23 # keep labels visible
fig = plt.figure()
fig.set_size_inches(15,9)
ax = fig.add_subplot(111)
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False)
for t in ax.xaxis.get_major_ticks():
t.tick2On = False
for t in ax.yaxis.get_major_ticks():
t.tick2On = False
sm.graphics.violinplot(data, ax=ax, labels=ll, show_boxplot=False, plot_opts={'label_fontsize':'large', 'label_rotation':0,'violin_fc':'#AAAAFF'})
ax.set_xlabel("Data")
ax.set_ylabel("Value")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment