import statistics
import numpy as np
import pandas as pd
from statistics import median
import matplotlib.pyplot as plt

x = [-5.0, -1.1, 0.1, 2.0, 8.0, 12.8, 21.0, 25.8, 41.0]
y=np.array(x)
z=pd.Series(y)
print("Median of the dataset is % s" % (median(x))) 

########################### using statistics ###########
print("statistics quantiles: ",statistics.quantiles(x, n=4))
#output [-0.5, 8.0, 23.4] -> 25% of the data falls below -0.5, 50% below 8, and 75% below 23.4

################### using Numpy #########################
print("")
print("np.quantile1: ",np.quantile(y, 0.05)) # 5th percentile
print("np.quantile2: ",np.quantile(y, 0.95)) # 95th percentile. The value below which 95% of the data falls
print("np.quantile3: ",np.quantile(y, 0.5))  # 50th percentile. The same as median!!!

v=np.quantile(y, [0.25, 0.5, 0.75])          # Q1, Q2(Median), Q3
print("np.quantile3: ",np.quantile(y, [0.25, 0.5, 0.75]))
print("")
print("interquartile range1: ",v[2] - v[0])

#################################### pd.Series ###############
z=pd.Series(y)

print("")
print("pd.Series .quantile(0.05): ",z.quantile(0.05))
print("pd.Series .quantile(0.95): ",z.quantile(0.95))
print("pd.Series .quantile([0.25, 0.5, 0.75]):\n",z.quantile([0.25, 0.5, 0.75]))

quartiles = z.quantile([0.25, 0.75])
print("interquartile range: ",quartiles[0.75] - quartiles[0.25])

################ Plot Code ####################################
# Create a box plot
plt.boxplot(x, vert=False, patch_artist=True, boxprops=dict(facecolor='lightblue'))

# Add labels and title
plt.title('Horizontal Box Plot of the Dataset')
plt.xlabel('Values')
plt.yticks([1], ['Dataset 1']) 

# Show the plot
plt.grid(axis='x')
plt.show()


