|
4 | 4 | "metadata": { |
5 | 5 | "colab": { |
6 | 6 | "provenance": [], |
7 | | - "authorship_tag": "ABX9TyMW6CQCOdZU+K+pt1e9nEpf", |
| 7 | + "authorship_tag": "ABX9TyM+ZEl7UGZSEg7hzaffqCHC", |
8 | 8 | "include_colab_link": true |
9 | 9 | }, |
10 | 10 | "kernelspec": { |
|
69 | 69 | "id": "3zA0huax09Hk", |
70 | 70 | "outputId": "8b8d9b46-3de8-4346-9f84-16f180035d75" |
71 | 71 | }, |
72 | | - "execution_count": 12, |
| 72 | + "execution_count": null, |
73 | 73 | "outputs": [ |
74 | 74 | { |
75 | 75 | "output_type": "stream", |
|
101 | 101 | }, |
102 | 102 | { |
103 | 103 | "cell_type": "code", |
104 | | - "execution_count": 13, |
| 104 | + "execution_count": null, |
105 | 105 | "metadata": { |
106 | 106 | "id": "qGOn4lV20Y-F" |
107 | 107 | }, |
|
142 | 142 | "id": "ZEZH8r871OPc", |
143 | 143 | "outputId": "8eae4ed7-5dc2-4af4-fd63-8553803fbca1" |
144 | 144 | }, |
145 | | - "execution_count": 14, |
| 145 | + "execution_count": null, |
146 | 146 | "outputs": [ |
147 | 147 | { |
148 | 148 | "output_type": "display_data", |
|
196 | 196 | "id": "Vb80zbBq1gF9", |
197 | 197 | "outputId": "21688184-cd9d-415e-dd32-a97c7c3bcb06" |
198 | 198 | }, |
199 | | - "execution_count": 15, |
| 199 | + "execution_count": null, |
200 | 200 | "outputs": [ |
201 | 201 | { |
202 | 202 | "output_type": "display_data", |
|
262 | 262 | "id": "fr7WiJQm1rBQ", |
263 | 263 | "outputId": "3620c2bf-98dd-4583-c133-f43b48fde278" |
264 | 264 | }, |
265 | | - "execution_count": 16, |
| 265 | + "execution_count": null, |
266 | 266 | "outputs": [ |
267 | 267 | { |
268 | 268 | "output_type": "display_data", |
|
305 | 305 | "id": "5-X9XI0n1zaK", |
306 | 306 | "outputId": "c376efcf-0d3b-4676-8c9f-8a00de4ebeca" |
307 | 307 | }, |
308 | | - "execution_count": 17, |
| 308 | + "execution_count": null, |
309 | 309 | "outputs": [ |
310 | 310 | { |
311 | 311 | "output_type": "display_data", |
|
346 | 346 | "id": "XRMLcfSl15bg", |
347 | 347 | "outputId": "c0f5f6b6-d720-4c36-d8c6-2ebd4406e653" |
348 | 348 | }, |
349 | | - "execution_count": 18, |
| 349 | + "execution_count": null, |
350 | 350 | "outputs": [ |
351 | 351 | { |
352 | 352 | "output_type": "display_data", |
|
386 | 386 | "id": "qtTKz4SC18pt", |
387 | 387 | "outputId": "1cb68a4d-cd4b-4351-f6dd-ca6635c4dfdf" |
388 | 388 | }, |
389 | | - "execution_count": 19, |
| 389 | + "execution_count": null, |
390 | 390 | "outputs": [ |
391 | 391 | { |
392 | 392 | "output_type": "display_data", |
|
427 | 427 | "id": "dIhC2nZP2AIC", |
428 | 428 | "outputId": "b06ef5cd-0eeb-4e4c-de44-5c43021adcf5" |
429 | 429 | }, |
430 | | - "execution_count": 20, |
| 430 | + "execution_count": null, |
431 | 431 | "outputs": [ |
432 | 432 | { |
433 | 433 | "output_type": "display_data", |
|
474 | 474 | "id": "zDMd-hsd2GJa", |
475 | 475 | "outputId": "2d5a8e37-1428-4703-d02b-bdf1b4d05bf7" |
476 | 476 | }, |
477 | | - "execution_count": 21, |
| 477 | + "execution_count": null, |
478 | 478 | "outputs": [ |
479 | 479 | { |
480 | 480 | "output_type": "display_data", |
|
514 | 514 | "id": "YAvbS5w52HEU", |
515 | 515 | "outputId": "fb36e723-62a6-47a7-c18e-b1a2871dd0ec" |
516 | 516 | }, |
517 | | - "execution_count": 22, |
| 517 | + "execution_count": null, |
518 | 518 | "outputs": [ |
519 | 519 | { |
520 | 520 | "output_type": "display_data", |
|
528 | 528 | } |
529 | 529 | ] |
530 | 530 | }, |
| 531 | + { |
| 532 | + "cell_type": "markdown", |
| 533 | + "source": [ |
| 534 | + "1️⃣ Subplots\n", |
| 535 | + "Subplots help you show multiple plots in a single figure." |
| 536 | + ], |
| 537 | + "metadata": { |
| 538 | + "id": "8QerCujUbhen" |
| 539 | + } |
| 540 | + }, |
| 541 | + { |
| 542 | + "cell_type": "code", |
| 543 | + "source": [ |
| 544 | + "import matplotlib.pyplot as plt\n", |
| 545 | + "import numpy as np\n", |
| 546 | + "\n", |
| 547 | + "x = np.linspace(0, 10, 100)\n", |
| 548 | + "\n", |
| 549 | + "# Create subplots (2 rows, 2 columns)\n", |
| 550 | + "fig, axes = plt.subplots(2, 2, figsize=(10, 8))\n", |
| 551 | + "\n", |
| 552 | + "# Plot on each subplot\n", |
| 553 | + "axes[0, 0].plot(x, np.sin(x), 'r') # Red sine wave\n", |
| 554 | + "axes[0, 0].set_title('Sine Wave')\n", |
| 555 | + "\n", |
| 556 | + "axes[0, 1].plot(x, np.cos(x), 'g') # Green cosine wave\n", |
| 557 | + "axes[0, 1].set_title('Cosine Wave')\n", |
| 558 | + "\n", |
| 559 | + "axes[1, 0].scatter(x, np.random.rand(100), color='blue')\n", |
| 560 | + "axes[1, 0].set_title('Random Scatter')\n", |
| 561 | + "\n", |
| 562 | + "axes[1, 1].hist(np.random.randn(1000), bins=30, color='purple')\n", |
| 563 | + "axes[1, 1].set_title('Histogram')\n", |
| 564 | + "\n", |
| 565 | + "plt.tight_layout() # Adjust layout to avoid overlapping\n", |
| 566 | + "plt.show()\n" |
| 567 | + ], |
| 568 | + "metadata": { |
| 569 | + "id": "a8gvjqs3beJ4" |
| 570 | + }, |
| 571 | + "execution_count": null, |
| 572 | + "outputs": [] |
| 573 | + }, |
| 574 | + { |
| 575 | + "cell_type": "markdown", |
| 576 | + "source": [ |
| 577 | + "2️⃣ Customizing Plots (Colors, Markers, and Styles)\n", |
| 578 | + "You can customize your plots using different colors, markers, and line styles." |
| 579 | + ], |
| 580 | + "metadata": { |
| 581 | + "id": "uE0drRzsbu05" |
| 582 | + } |
| 583 | + }, |
| 584 | + { |
| 585 | + "cell_type": "code", |
| 586 | + "source": [ |
| 587 | + "x = np.linspace(0, 10, 100)\n", |
| 588 | + "y = np.sin(x)\n", |
| 589 | + "\n", |
| 590 | + "# Customize line style, color, and marker\n", |
| 591 | + "plt.plot(x, y, linestyle='--', color='orange', marker='o', markersize=5, label='Sine')\n", |
| 592 | + "plt.title('Customized Plot')\n", |
| 593 | + "plt.xlabel('X-axis')\n", |
| 594 | + "plt.ylabel('Y-axis')\n", |
| 595 | + "plt.legend()\n", |
| 596 | + "plt.grid(True) # Add grid lines\n", |
| 597 | + "plt.show()\n" |
| 598 | + ], |
| 599 | + "metadata": { |
| 600 | + "id": "wMZj1Wpmbvq_" |
| 601 | + }, |
| 602 | + "execution_count": null, |
| 603 | + "outputs": [] |
| 604 | + }, |
| 605 | + { |
| 606 | + "cell_type": "markdown", |
| 607 | + "source": [ |
| 608 | + "**Line Styles**: '-', '--', '-.', ':'\n", |
| 609 | + "\n", |
| 610 | + "**Colors**: 'r', 'g', 'b', 'orange', etc.\n", |
| 611 | + "\n", |
| 612 | + "**Markers**: 'o', 's' (square), 'x', '*', 'D' (diamond), etc." |
| 613 | + ], |
| 614 | + "metadata": { |
| 615 | + "id": "thWnwKGMb0x_" |
| 616 | + } |
| 617 | + }, |
| 618 | + { |
| 619 | + "cell_type": "markdown", |
| 620 | + "source": [ |
| 621 | + "3️⃣ Saving Plots as Images\n", |
| 622 | + "You can save plots as PNG, PDF, SVG, and more using savefig()." |
| 623 | + ], |
| 624 | + "metadata": { |
| 625 | + "id": "4YtyHAMScF13" |
| 626 | + } |
| 627 | + }, |
| 628 | + { |
| 629 | + "cell_type": "code", |
| 630 | + "source": [ |
| 631 | + "x = np.linspace(0, 10, 100)\n", |
| 632 | + "y = np.sin(x)\n", |
| 633 | + "\n", |
| 634 | + "plt.plot(x, y)\n", |
| 635 | + "plt.title('Plot to be Saved')\n", |
| 636 | + "plt.xlabel('X-axis')\n", |
| 637 | + "plt.ylabel('Y-axis')\n", |
| 638 | + "\n", |
| 639 | + "# Save the plot as a PNG image\n", |
| 640 | + "plt.savefig('saved_plot.png', dpi=300, bbox_inches='tight') # High resolution\n", |
| 641 | + "plt.show()\n" |
| 642 | + ], |
| 643 | + "metadata": { |
| 644 | + "id": "tcexyk37b1X4" |
| 645 | + }, |
| 646 | + "execution_count": null, |
| 647 | + "outputs": [] |
| 648 | + }, |
| 649 | + { |
| 650 | + "cell_type": "markdown", |
| 651 | + "source": [ |
| 652 | + "4️⃣ Animated Plots\n", |
| 653 | + "Matplotlib supports animations using FuncAnimation from matplotlib.animation. Here’s a simple animation example:" |
| 654 | + ], |
| 655 | + "metadata": { |
| 656 | + "id": "0X9C8SFUcJRI" |
| 657 | + } |
| 658 | + }, |
| 659 | + { |
| 660 | + "cell_type": "code", |
| 661 | + "source": [ |
| 662 | + "import matplotlib.pyplot as plt\n", |
| 663 | + "import numpy as np\n", |
| 664 | + "from matplotlib.animation import FuncAnimation\n", |
| 665 | + "\n", |
| 666 | + "x = np.linspace(0, 10, 100)\n", |
| 667 | + "fig, ax = plt.subplots()\n", |
| 668 | + "line, = ax.plot(x, np.sin(x))\n", |
| 669 | + "\n", |
| 670 | + "# Function to update the plot for each frame\n", |
| 671 | + "def update(frame):\n", |
| 672 | + " line.set_ydata(np.sin(x + frame / 10)) # Change sine wave phase\n", |
| 673 | + " return line,\n", |
| 674 | + "\n", |
| 675 | + "ani = FuncAnimation(fig, update, frames=100, interval=50) # 100 frames, 50 ms interval\n", |
| 676 | + "plt.show()\n" |
| 677 | + ], |
| 678 | + "metadata": { |
| 679 | + "id": "_S05SJcUcTJp" |
| 680 | + }, |
| 681 | + "execution_count": null, |
| 682 | + "outputs": [] |
| 683 | + }, |
| 684 | + { |
| 685 | + "cell_type": "markdown", |
| 686 | + "source": [ |
| 687 | + "FuncAnimation Parameters:\n", |
| 688 | + "\n", |
| 689 | + "frames: Total number of frames\n", |
| 690 | + "\n", |
| 691 | + "interval: Delay between frames (in milliseconds)\n", |
| 692 | + "\n", |
| 693 | + "update: Function to update the plot\n", |
| 694 | + "\n", |
| 695 | + "You can save the animation as a video using ani.save('animation.mp4')." |
| 696 | + ], |
| 697 | + "metadata": { |
| 698 | + "id": "nWMo6laCcXTY" |
| 699 | + } |
| 700 | + }, |
531 | 701 | { |
532 | 702 | "cell_type": "markdown", |
533 | 703 | "source": [ |
|
0 commit comments