#!/usr/bin/env python
# coding: utf-8
# # Box and whisker plot using Python
# # 1. Matplotlib:
# In[1]:
import matplotlib.pyplot as plt
# Sample data
data = [7, 2, 15, 9, 12, 4, 11, 8, 13, 6]
# Create boxplot
plt.boxplot(data)
# Customize labels and title
plt.xlabel("Data")
plt.ylabel("Value")
plt.title("Boxplot with Matplotlib")
plt.show()
# # 2. Pandas:
# In[2]:
import pandas as pd
import matplotlib.pyplot as plt
# Sample DataFrame
data = pd.DataFrame({"values": [7, 2, 15, 9, 12, 4, 11, 8, 13, 6]})
# Create boxplot
data.plot.box()
# Customize labels and title
plt.xlabel("Data")
plt.ylabel("Value")
plt.title("Boxplot with Pandas")
plt.show()
# # 3. Seaborn:
# In[3]:
import seaborn as sns
# Sample data (same as before)
data = [7, 2, 15, 9, 12, 4, 11, 8, 13, 6]
# Create boxplot
sns.boxplot(data=data)
# Customize with hue (category) plot
data = {"category": ["A", "B", "A", "A", "B", "A", "A", "B", "B", "A"], "values": data}
sns.boxplot(x="category", y="values", data=data)
plt.show()
# In[ ]:
0 Comments:
Post a Comment