Bar Chart(products)
import [Link] as plt
# Sample data
products = ['Product A', 'Product B', 'Product C', 'Product D', 'Product E']
sales = [150, 200, 180, 220, 170]
colors = ['#5DADE2', '#F1948A', '#82E0AA', '#F7DC6F', '#AF7AC5']
# Plotting the bar chart
[Link](figsize=(10, 6))
bars = [Link](products, sales, color=colors, edgecolor='black')
# Adding title and labels
[Link]('Sales of Different Products', fontsize=16, fontweight='bold')
[Link]('Products', fontsize=12)
[Link]('Sales (in units)', fontsize=12)
# Adding a legend
[Link](['Sales Volume'], loc='upper right')
# Adding data labels on top of each bar
for bar in bars:
yval = bar.get_height()
[Link](bar.get_x() + bar.get_width()/2, yval + 5, int(yval), ha='center', va='bottom', fontsize=10, fontweight='bold')
# Displaying the chart
[Link]()
Pie chart (products)
import [Link] as plt
# Sample data
products = ['Product A', 'Product B', 'Product C', 'Product D', 'Product E']
sales = [150, 200, 180, 220, 170]
colors = ['#5DADE2', '#F1948A', '#82E0AA', '#F7DC6F', '#AF7AC5']
# Explode the highest sales product for emphasis
explode = [0, 0, 0, 0.1, 0] # Only "explode" the slice for 'Product D'
# Plotting the pie chart
[Link](figsize=(8, 8))
[Link](sales, labels=products, autopct='%1.1f%%', startangle=140, colors=colors, explode=explode,
wedgeprops={'edgecolor': 'black'}, textprops={'fontsize': 12, 'fontweight': 'bold'})
# Adding a title
[Link]('Sales Distribution of Different Products', fontsize=16, fontweight='bold')
# Adding a legend
[Link](products, title="Products", loc="best", bbox_to_anchor=(1, 0, 0.5, 1))
# Display the chart
plt.tight_layout() # Adjust layout to make room for the legend
[Link]()
Line Chart (Weather Dataset)
import [Link] as plt
import pandas as pd
# Sample data (date range with temperature and humidity values)
dates = pd.date_range(start="2023-01-01", end="2023-01-10")
temperature = [30, 32, 33, 29, 28, 31, 35, 34, 33, 32]
humidity = [45, 50, 55, 47, 52, 60, 65, 62, 58, 55]
# Creating the plot
[Link](figsize=(10, 6))
# Plotting temperature line
[Link](dates, temperature, marker='o', color='tomato', linestyle='-', linewidth=2, label='Temperature (°C)')
# Plotting humidity line
[Link](dates, humidity, marker='s', color='royalblue', linestyle='--', linewidth=2, label='Humidity (%)')
# Adding title and labels
[Link]('Weather Data: Temperature and Humidity Over Time', fontsize=16, fontweight='bold')
[Link]('Date', fontsize=12)
[Link]('Values', fontsize=12)
# Adding a legend
[Link](loc='upper left')
# Adding grid for readability
[Link](color='gray', linestyle=':', linewidth=0.5)
# Formatting the x-axis for better date display
[Link](rotation=45)
# Displaying the plot
plt.tight_layout() # Adjust layout for title, labels, and grid
[Link]()
Scatter plot (Employee Dataset)
import [Link] as plt
# Sample data
experience = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
salary = [35000, 42000, 50000, 52000, 60000, 65000, 70000, 78000, 82000, 90000]
departments = ['HR', 'Finance', 'IT', 'IT', 'HR', 'Finance', 'HR', 'IT', 'Finance', 'IT']
sizes = [70, 80, 90, 100, 110, 120, 130, 140, 150, 160] # Represents another variable (e.g., age)
# Define colors for each department
colors = {'HR': 'skyblue', 'Finance': 'orange', 'IT': 'green'}
color_values = [colors[dept] for dept in departments]
# Creating the scatter plot
[Link](figsize=(10, 6))
scatter = [Link](experience, salary, c=color_values, s=sizes, alpha=0.7, edgecolor='black')
# Adding title and labels
[Link]('Employee Experience vs. Salary', fontsize=16, fontweight='bold')
[Link]('Years of Experience', fontsize=12)
[Link]('Salary ($)', fontsize=12)
# Adding grid for readability
[Link](color='gray', linestyle=':', linewidth=0.5)
# Adding a legend for department colors
for dept in colors:
[Link]([], [], color=colors[dept], edgecolor='black', alpha=0.7, s=100, label=dept)
[Link](title="Department", loc="upper left")
# Displaying the plot
plt.tight_layout() # Adjust layout for better spacing
[Link]()
Histograms (weather dataset)
import [Link] as plt
import numpy as np
# Sample data (simulated temperature and humidity values)
temperature = [Link](25, 5, 100) # Mean temperature of 25°C with a std deviation of 5
humidity = [Link](60, 10, 100) # Mean humidity of 60% with a std deviation of 10
# Creating the plot
[Link](figsize=(12, 6))
# Plotting temperature histogram
[Link](temperature, bins=10, color='salmon', edgecolor='black', alpha=0.7, label='Temperature (°C)')
# Plotting humidity histogram
[Link](humidity, bins=10, color='skyblue', edgecolor='black', alpha=0.7, label='Humidity (%)')
# Adding title and labels
[Link]('Distribution of Temperature and Humidity', fontsize=16, fontweight='bold')
[Link]('Value', fontsize=12)
[Link]('Frequency', fontsize=12)
# Adding a legend
[Link](loc='upper right')
# Adding grid for readability
[Link](color='gray', linestyle=':', linewidth=0.5)
# Display the plot
plt.tight_layout() # Adjust layout for better spacing
[Link]()
Heat map (weather dataset)
import seaborn as sns
import [Link] as plt
import numpy as np
import pandas as pd
# Sample data: Temperature readings (randomly generated for illustration)
[Link](0)
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
hours = [f'{hour}:00' for hour in range(0, 24)]
# Generating a random temperature dataset (in °C)
temperature_data = [Link](20, 5, size=(7, 24))
# Creating a DataFrame for seaborn
temperature_df = [Link](temperature_data, index=days, columns=hours)
# Plotting the heatmap
[Link](figsize=(14, 8))
[Link](temperature_df, cmap='YlOrRd', annot=True, fmt=".1f", cbar_kws={'label': 'Temperature (°C)'})
# Adding title and labels
[Link]('Temperature Heatmap Over Days and Hours', fontsize=18, fontweight='bold', pad=20)
[Link]('Hour of Day', fontsize=14)
[Link]('Day of Week', fontsize=14)
# Display the plot
plt.tight_layout()
[Link]()
Box Plot (weather dataset)
import [Link] as plt
import seaborn as sns
import numpy as np
import pandas as pd
# Sample data: Simulated temperature and humidity values for four seasons
[Link](42)
data = {
'Temperature': [Link]([
[Link](10, 3, 50), # Winter
[Link](15, 4, 50), # Spring
[Link](25, 5, 50), # Summer
[Link](18, 4, 50) # Autumn
]),
'Humidity': [Link]([
[Link](65, 10, 50), # Winter
[Link](55, 8, 50), # Spring
[Link](50, 7, 50), # Summer
[Link](60, 9, 50) # Autumn
]),
'Season': ['Winter'] * 50 + ['Spring'] * 50 + ['Summer'] * 50 + ['Autumn'] * 50
}
# Creating a DataFrame
weather_df = [Link](data)
# Creating the plot
[Link](figsize=(14, 8))
# Plotting the box plot for Temperature
[Link](1, 2, 1)
[Link](x='Season', y='Temperature', data=weather_df, palette='coolwarm')
[Link]('Temperature Distribution by Season', fontsize=14, fontweight='bold')
[Link]('Season', fontsize=12)
[Link]('Temperature (°C)', fontsize=12)
# Plotting the box plot for Humidity
[Link](1, 2, 2)
[Link](x='Season', y='Humidity', data=weather_df, palette='Blues')
[Link]('Humidity Distribution by Season', fontsize=14, fontweight='bold')
[Link]('Season', fontsize=12)
[Link]('Humidity (%)', fontsize=12)
# Adjusting layout and displaying the plot
plt.tight_layout()
[Link]()