diff --git a/activities/1.1-basic-jupyter-notebook.ipynb b/activities/1.1-basic-jupyter-notebook.ipynb index dba7f486..54b516fa 100644 --- a/activities/1.1-basic-jupyter-notebook.ipynb +++ b/activities/1.1-basic-jupyter-notebook.ipynb @@ -31,7 +31,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "f2b4273a", "metadata": {}, "outputs": [ @@ -45,7 +45,7 @@ ], "source": [ "# This is a Python code cell\n", - "print('Hello, JupyterLab!')" + "print('Hello Chandrashekhar')" ] }, { diff --git a/src/1-line-plot.ipynb b/src/1-line-plot.ipynb index eab74494..20e9fd4d 100644 --- a/src/1-line-plot.ipynb +++ b/src/1-line-plot.ipynb @@ -14,7 +14,27 @@ "outputs": [], "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." + "# Customize the plot by adding a title, labels for both axes, and a grid.\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# Generate x values from 0 to 10\n", + "x = np.linspace(0, 10, 100)\n", + "\n", + "# Calculate y values as the square of x\n", + "y = x**2\n", + "\n", + "# Create the line plot\n", + "plt.plot(x, y)\n", + "\n", + "# Customize the plot\n", + "plt.title(\"Quadratic Function: y = x^2\")\n", + "plt.xlabel(\"x-axis\")\n", + "plt.ylabel(\"y-axis\")\n", + "plt.grid(True)\n", + "\n", + "# Display the plot\n", + "plt.show()" ] } ], diff --git a/src/2-bar-plot.ipynb b/src/2-bar-plot.ipynb index 9d3fb712..c15e7f88 100644 --- a/src/2-bar-plot.ipynb +++ b/src/2-bar-plot.ipynb @@ -14,7 +14,26 @@ "outputs": [], "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." + "# Use different colors for each bar and add a title to the plot.\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Define data\n", + "categories = ['A', 'B', 'C', 'D']\n", + "values = [5, 7, 3, 9]\n", + "\n", + "# Define colors for each bar\n", + "colors = ['blue', 'green', 'red', 'purple']\n", + "\n", + "# Create the bar plot\n", + "plt.bar(categories, values, color=colors)\n", + "\n", + "# Add title and labels\n", + "plt.title('Bar Plot with Different Colors')\n", + "plt.xlabel('Categories')\n", + "plt.ylabel('Values')\n", + "\n", + "# Show the plot\n", + "plt.show()" ] } ], diff --git a/src/3-scatter-plot.ipynb b/src/3-scatter-plot.ipynb index 9bed601f..5bab9695 100644 --- a/src/3-scatter-plot.ipynb +++ b/src/3-scatter-plot.ipynb @@ -14,7 +14,30 @@ "outputs": [], "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'." + "# Annotate each point with its (x, y) value, and set the title as 'Scatter Plot with Annotations'.\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for the scatter plot\n", + "x = [1, 2, 3, 4, 5]\n", + "y = [2, 4, 6, 8, 10]\n", + "\n", + "# Create the scatter plot\n", + "plt.figure(figsize=(8, 6))\n", + "plt.scatter(x, y, color='blue')\n", + "\n", + "# Annotate each point with its (x, y) value\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='left')\n", + "\n", + "# Set the title and labels\n", + "plt.title('Scatter Plot with Annotations')\n", + "plt.xlabel('X-axis')\n", + "plt.ylabel('Y-axis')\n", + "plt.grid(True)\n", + "plt.tight_layout()\n", + "\n", + "# Show the plot\n", + "plt.show()\n" ] } ], diff --git a/src/4-pie-chart.ipynb b/src/4-pie-chart.ipynb index eedc5b94..71d37ea0 100644 --- a/src/4-pie-chart.ipynb +++ b/src/4-pie-chart.ipynb @@ -14,7 +14,26 @@ "outputs": [], "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." + "# Display the percentages on the chart using autopct.\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for the pie chart\n", + "labels = ['Python', 'Java', 'C++', 'JavaScript']\n", + "sizes = [40, 25, 20, 15]\n", + "\n", + "# Create the pie chart\n", + "plt.figure(figsize=(8, 8))\n", + "plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)\n", + "\n", + "# Set the title\n", + "plt.title('Programming Language Popularity')\n", + "\n", + "# Equal aspect ratio ensures that pie is drawn as a circle\n", + "plt.axis('equal')\n", + "plt.tight_layout()\n", + "\n", + "# Show the plot\n", + "plt.show()\n" ] } ], diff --git a/src/5-subplot.ipynb b/src/5-subplot.ipynb index 98e4fa95..f4956fe8 100644 --- a/src/5-subplot.ipynb +++ b/src/5-subplot.ipynb @@ -14,7 +14,40 @@ "outputs": [], "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." + "# 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.\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Create a 2x2 subplot layout\n", + "fig, axs = plt.subplots(2, 2, figsize=(12, 10))\n", + "\n", + "# Line chart data\n", + "x = [1, 2, 3, 4, 5]\n", + "y = [2, 3, 5, 7, 11]\n", + "axs[0, 0].plot(x, y, marker='o')\n", + "axs[0, 0].set_title('Line Chart')\n", + "\n", + "# Bar chart data\n", + "categories = ['A', 'B', 'C', 'D']\n", + "values = [10, 20, 15, 25]\n", + "axs[0, 1].bar(categories, values, color='skyblue')\n", + "axs[0, 1].set_title('Bar Chart')\n", + "\n", + "# Scatter plot data\n", + "x_scatter = [1, 2, 3, 4, 5]\n", + "y_scatter = [5, 4, 3, 2, 1]\n", + "axs[1, 0].scatter(x_scatter, y_scatter, color='green')\n", + "axs[1, 0].set_title('Scatter Plot')\n", + "\n", + "# Pie chart data\n", + "labels = ['Python', 'Java', 'C++', 'JavaScript']\n", + "sizes = [40, 25, 20, 15]\n", + "axs[1, 1].pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)\n", + "axs[1, 1].set_title('Pie Chart')\n", + "axs[1, 1].axis('equal') # Equal aspect ratio\n", + "\n", + "# Adjust layout\n", + "plt.tight_layout()\n", + "plt.show()\n" ] } ], diff --git a/src/6-histogram.ipynb b/src/6-histogram.ipynb index 5e6e6b60..22fd57df 100644 --- a/src/6-histogram.ipynb +++ b/src/6-histogram.ipynb @@ -14,7 +14,24 @@ "outputs": [], "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." + "# Customize the histogram with a title, labels for the x-axis, and a specific color for the bars.\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for the histogram\n", + "data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5]\n", + "\n", + "# Create the histogram\n", + "plt.figure(figsize=(8, 6))\n", + "plt.hist(data, bins=5, color='orange', edgecolor='black')\n", + "\n", + "# Customize with title and axis labels\n", + "plt.title('Histogram of Data')\n", + "plt.xlabel('Value')\n", + "plt.ylabel('Frequency')\n", + "\n", + "plt.grid(True)\n", + "plt.tight_layout()\n", + "plt.show()\n" ] } ],