World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Sahil Parrvez
a year ago
import numpy as np
import matplotlib.pyplot as plt
# generate some random data
sample1= np.random.normal(5, 90, 1000)
sample2= np.random.normal(5, 95, 1000)
sample3= np.random.normal(5, 100, 1000)
sample4= np.random.normal(5, 95, 1000)
sample= list([sample1, sample2, sample3, sample4])
fig, ax = plt.subplots()
# build a violin plot
ax.violinplot(sample, showmeans=False, showmedians=True)
# add title and axis labels
ax.set_title('violin plot')
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
# add x-tick labels
xticklabels = ['sample 1', 'sample 2', 'sample 3', 'sample 4']
ax.set_xticks([1,2,3,4])
ax.set_xticklabels(xticklabels)
# add horizontal grid lines
ax.yaxis.grid(True)
# show the plot
plt.show()