diff --git a/src/1-line-plot.ipynb b/src/1-line-plot.ipynb index eab74494..44100a05 100644 --- a/src/1-line-plot.ipynb +++ b/src/1-line-plot.ipynb @@ -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()" ] } ], diff --git a/src/2-bar-plot.ipynb b/src/2-bar-plot.ipynb index 9d3fb712..f1eca1b8 100644 --- a/src/2-bar-plot.ipynb +++ b/src/2-bar-plot.ipynb @@ -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()" ] } ], diff --git a/src/3-scatter-plot.ipynb b/src/3-scatter-plot.ipynb index 9bed601f..f52dcbc5 100644 --- a/src/3-scatter-plot.ipynb +++ b/src/3-scatter-plot.ipynb @@ -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()" ] } ], diff --git a/src/4-pie-chart.ipynb b/src/4-pie-chart.ipynb index eedc5b94..17876410 100644 --- a/src/4-pie-chart.ipynb +++ b/src/4-pie-chart.ipynb @@ -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()" ] } ], diff --git a/src/5-subplot.ipynb b/src/5-subplot.ipynb index 98e4fa95..0fceb0a7 100644 --- a/src/5-subplot.ipynb +++ b/src/5-subplot.ipynb @@ -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()" ] } ], diff --git a/src/6-histogram.ipynb b/src/6-histogram.ipynb index 5e6e6b60..e0beadfe 100644 --- a/src/6-histogram.ipynb +++ b/src/6-histogram.ipynb @@ -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()", ] } ],