Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/1-line-plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
"source": [
"# TASK: Create a line plot with x values ranging from 0 to 10 and y values as the square of x.\n",
"# Customize the plot by adding a title, labels for both axes, and a grid."
"mport matplotlib.pyplot as plt\n",
"\n",
"# Define x and y values\n"
"x = list(range(11))\n",
"y = [i**2 for i in x]",
"\n",
"# Create the plot\n",
"plt.plot(x, y)\n",
"\n",
"# Customize the plot\n",
"plt.title('Square Numbers Line Plot')",
"plt.xlabel('X values')\n",
"plt.ylabel('Y = X Squared')\n",
"plt.grid(True)\n",
"\n",
"# Show the plot\n",
"plt.show()"
]
}
],
Expand Down
17 changes: 17 additions & 0 deletions src/2-bar-plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
"source": [
"# TASK: Create a bar plot with the following data: categories = ['A', 'B', 'C', 'D'] and values = [5, 7, 3, 9].\n",
"# Use different colors for each bar and add a title to the plot."
"import matplotlib.pyplot as plt\n",
"\n",
"# Data\n",
"categories = ['A', 'B', 'C', 'D']\n",
"values = [5, 7, 3, 9]\n",
"colors = ['red', 'blue', 'green', 'orange']\n",
"\n",
"# Create bar plot\n",
"plt.bar(categories, values, color=colors)\n",
"\n",
"# Customize plot\n",
"plt.title('Bar Plot with Colors')\n",
"plt.xlabel('Categories')\n",
"plt.ylabel('Values')\n",
"\n",
"# Show plot\n",
"plt.show()"
]
}
],
Expand Down
18 changes: 18 additions & 0 deletions src/3-scatter-plot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
"source": [
"# TASK: Create a scatter plot with x = [1, 2, 3, 4, 5] and y = [2, 4, 6, 8, 10].\n",
"# Annotate each point with its (x, y) value, and set the title as 'Scatter Plot with Annotations'."
"import matplotlib.pyplot as plt\n",
"\n",
"# Data\n",
"x = [1, 2, 3, 4, 5]\n",
"y = [2, 4, 6, 8, 10]\n",
"\n",
"# Create scatter plot\n",
"plt.scatter(x, y)\n",
"\n",
"# Annotate each point\n",
"for i in range(len(x)): \n",
"plt.annotate(f'({x[i]}, {y[i]})', (x[i], y[i]), textcoords= 'offset points', xytext=(5,5), ha='center')\n",
"\n",
"# Set title\n",
"plt.title('Scatter Plot with Annotations')",
"\n",
"# Show plot\n",
"plt.show()"
]
}
],
Expand Down
15 changes: 15 additions & 0 deletions src/4-pie-chart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
"source": [
"# TASK: Create a pie chart with the following data: labels = ['Python', 'Java', 'C++', 'JavaScript'] and sizes = [40, 25, 20, 15].\n",
"# Display the percentages on the chart using autopct."
"import matplotlib.pyplot as plt\n",
"\n",
"# Data\n",
"labels = ['Python', 'Java', 'C++', 'JavaScript']\n",
"sizes = [40, 25, 20, 15]\n",
"\n",
"# Create pie char\n",
"plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)\n",
"\n",
"# Equal aspect ratio ensures pie is drawn as a circle\n",
"plt.axis('equal')\n",
"plt.title('Programming Language Usage')\n",
"\n",
"# Show plot\n",
"plt.show()"
]
}
],
Expand Down
33 changes: 33 additions & 0 deletions src/5-subplot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@
"source": [
"# TASK: Create a 2x2 subplot layout.\n",
"# Plot a line chart in the first subplot, a bar chart in the second, a scatter plot in the third, and a pie chart in the fourth."
"import matplotlib.pyplot as plt\n",
"\n",
"# Sample data\n",
"x = [1, 2, 3, 4, 5]\n",
"y = [10, 20, 25, 30, 40]\n",
"categories = ['A', 'B', 'C', 'D']\n",
"values = [5, 7, 3, 4]\n",
"labels = ['Python', 'Java', 'C++', 'JavaScript']\n",
"sizes = [40, 25, 20, 15]\n",
"\n",
"# Create 2x2 subplot layout\n",
"fig, axs = plt.subplots(2, 2, figsize=(10, 8))\n",
"\n",
"# Line chart\n",
"axs[0, 0].plot(x, y)\n",
"axs[0, 0].set_title('Line Chart')\n",
"\n",
"# Bar chart\n",
"axs[0, 1].bar(categories, values)\n",
"axs[0, 1].set_title('Bar Chart')\n",
"\n",
"# Scatter plot\n",
"axs[1, 0].scatter(x, y)\n",
"axs[1, 0].set_title('Scatter Plot')\n",
"\n",
"# Pie chart\n",
"axs[1, 1].pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)\n",
"axs[1, 1].set_title('Pie Chart')\n",
"axs[1, 1].axis('equal')\n",
"\n",
"# Adjust layout\n",
"plt.tight_layout()\n",
"plt.show()"
]
}
],
Expand Down
15 changes: 15 additions & 0 deletions src/6-histogram.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
"source": [
"# TASK: Create a histogram for the following data: data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5].\n",
"# Customize the histogram with a title, labels for the x-axis, and a specific color for the bars."
"import matplotlib.pyplot as plt\n",
"\n",
"# Data\n",
"data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5]\n",
"\n",
"# Create histogram\n",
"plt.hist(data, bins=5, color='skyblue', edgecolor='black')\n",
"\n",
"# Customization\n",
"plt.title('Histogram of Given Data')\n",
"plt.xlabel('Value')\n",
"plt.ylabel('Frequency')\n",
"\n",
"# Show plot\n",
"plt.show()",
]
}
],
Expand Down