diff --git a/src/1-line-plot.ipynb b/src/1-line-plot.ipynb index eab74494..5aab4ba7 100644 --- a/src/1-line-plot.ipynb +++ b/src/1-line-plot.ipynb @@ -13,8 +13,28 @@ "metadata": {}, "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." + "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 plot\n", + "plt.plot(x, y)\n", + "\n", + "# Add title and labels\n", + "plt.title('Line Plot of y = x^2')\n", + "plt.xlabel('x values')\n", + "plt.ylabel('y values (x^2)')\n", + "\n", + "# Add grid\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..a0e7b923 100644 --- a/src/2-bar-plot.ipynb +++ b/src/2-bar-plot.ipynb @@ -13,8 +13,14 @@ "metadata": {}, "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." + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for categories and values\n", + "categories = ['A', 'B', 'C', 'D']\n", + "values = [5, 7, 3, 9]\n", + "\n", + "# Create the bar plot with different colors\n", + "plt.bar(categories, values, color=['red', 'blue', 'green', 'purple'])" ] } ], diff --git a/src/3-scatter-plot.ipynb b/src/3-scatter-plot.ipynb index 9bed601f..68e83311 100644 --- a/src/3-scatter-plot.ipynb +++ b/src/3-scatter-plot.ipynb @@ -13,8 +13,24 @@ "metadata": {}, "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'." + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for x and y\n", + "x = [1, 2, 3, 4, 5]\n", + "y = [2, 4, 6, 8, 10]\n", + "\n", + "# Create the scatter plot\n", + "plt.scatter(x, y)\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=(0, 5), ha='center')\n", + "\n", + "# Set the title of the plot\n", + "plt.title('Scatter Plot with Annotations')\n", + "\n", + "# Show the plot\n", + "plt.show()" ] } ], diff --git a/src/4-pie-chart.ipynb b/src/4-pie-chart.ipynb index eedc5b94..fb0371b8 100644 --- a/src/4-pie-chart.ipynb +++ b/src/4-pie-chart.ipynb @@ -13,8 +13,20 @@ "metadata": {}, "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." + "import matplotlib.pyplot as plt\n", + "\n", + "# Data for labels and sizes\n", + "labels = ['Python', 'Java', 'C++', 'JavaScript']\n", + "sizes = [40, 25, 20, 15]\n", + "\n", + "# Create the pie chart\n", + "plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)\n", + "\n", + "# Set the title of the plot\n", + "plt.title('Programming Language Usage')\n", + "\n", + "# Display the pie chart\n", + "plt.show()" ] } ], diff --git a/src/5-subplot.ipynb b/src/5-subplot.ipynb index 98e4fa95..228f6fba 100644 --- a/src/5-subplot.ipynb +++ b/src/5-subplot.ipynb @@ -13,8 +13,43 @@ "metadata": {}, "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." + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# Create a 2x2 subplot layout\n", + "fig, axs = plt.subplots(2, 2, figsize=(10, 8))\n", + "\n", + "# 1st subplot: Line chart\n", + "x = np.linspace(0, 10, 100)\n", + "y = x ** 2\n", + "axs[0, 0].plot(x, y)\n", + "axs[0, 0].set_title('Line Chart: y = x^2')\n", + "\n", + "# 2nd subplot: Bar chart\n", + "categories = ['A', 'B', 'C', 'D']\n", + "values = [5, 7, 3, 9]\n", + "axs[0, 1].bar(categories, values, color=['red', 'blue', 'green', 'purple'])\n", + "axs[0, 1].set_title('Bar Chart')\n", + "\n", + "# 3rd subplot: Scatter plot\n", + "x_scatter = [1, 2, 3, 4, 5]\n", + "y_scatter = [2, 4, 6, 8, 10]\n", + "axs[1, 0].scatter(x_scatter, y_scatter)\n", + "for i in range(len(x_scatter)):\n", + " axs[1, 0].annotate(f'({x_scatter[i]}, {y_scatter[i]})', (x_scatter[i], y_scatter[i]), textcoords=\"offset points\", xytext=(0, 5), ha='center')\n", + "axs[1, 0].set_title('Scatter Plot with Annotations')\n", + "\n", + "# 4th subplot: Pie chart\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", + "\n", + "# Adjust layout to prevent overlap\n", + "plt.tight_layout()\n", + "\n", + "# Show the plot\n", + "plt.show()" ] } ], diff --git a/src/6-histogram.ipynb b/src/6-histogram.ipynb index 5e6e6b60..aa1512d7 100644 --- a/src/6-histogram.ipynb +++ b/src/6-histogram.ipynb @@ -13,8 +13,21 @@ "metadata": {}, "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." + "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.hist(data, bins=5, color='skyblue', edgecolor='black')\n", + "\n", + "# Add title and labels\n", + "plt.title('Histogram of Given Data')\n", + "plt.xlabel('Values')\n", + "plt.ylabel('Frequency')\n", + "\n", + "# Show the plot\n", + "plt.show()" ] } ],