Skip to content

Commit a14ccb8

Browse files
committed
Created using Colab
1 parent 624a5e8 commit a14ccb8

File tree

1 file changed

+182
-12
lines changed

1 file changed

+182
-12
lines changed

Matplotlib_Visualization_with_Python.ipynb

Lines changed: 182 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"metadata": {
55
"colab": {
66
"provenance": [],
7-
"authorship_tag": "ABX9TyMW6CQCOdZU+K+pt1e9nEpf",
7+
"authorship_tag": "ABX9TyM+ZEl7UGZSEg7hzaffqCHC",
88
"include_colab_link": true
99
},
1010
"kernelspec": {
@@ -69,7 +69,7 @@
6969
"id": "3zA0huax09Hk",
7070
"outputId": "8b8d9b46-3de8-4346-9f84-16f180035d75"
7171
},
72-
"execution_count": 12,
72+
"execution_count": null,
7373
"outputs": [
7474
{
7575
"output_type": "stream",
@@ -101,7 +101,7 @@
101101
},
102102
{
103103
"cell_type": "code",
104-
"execution_count": 13,
104+
"execution_count": null,
105105
"metadata": {
106106
"id": "qGOn4lV20Y-F"
107107
},
@@ -142,7 +142,7 @@
142142
"id": "ZEZH8r871OPc",
143143
"outputId": "8eae4ed7-5dc2-4af4-fd63-8553803fbca1"
144144
},
145-
"execution_count": 14,
145+
"execution_count": null,
146146
"outputs": [
147147
{
148148
"output_type": "display_data",
@@ -196,7 +196,7 @@
196196
"id": "Vb80zbBq1gF9",
197197
"outputId": "21688184-cd9d-415e-dd32-a97c7c3bcb06"
198198
},
199-
"execution_count": 15,
199+
"execution_count": null,
200200
"outputs": [
201201
{
202202
"output_type": "display_data",
@@ -262,7 +262,7 @@
262262
"id": "fr7WiJQm1rBQ",
263263
"outputId": "3620c2bf-98dd-4583-c133-f43b48fde278"
264264
},
265-
"execution_count": 16,
265+
"execution_count": null,
266266
"outputs": [
267267
{
268268
"output_type": "display_data",
@@ -305,7 +305,7 @@
305305
"id": "5-X9XI0n1zaK",
306306
"outputId": "c376efcf-0d3b-4676-8c9f-8a00de4ebeca"
307307
},
308-
"execution_count": 17,
308+
"execution_count": null,
309309
"outputs": [
310310
{
311311
"output_type": "display_data",
@@ -346,7 +346,7 @@
346346
"id": "XRMLcfSl15bg",
347347
"outputId": "c0f5f6b6-d720-4c36-d8c6-2ebd4406e653"
348348
},
349-
"execution_count": 18,
349+
"execution_count": null,
350350
"outputs": [
351351
{
352352
"output_type": "display_data",
@@ -386,7 +386,7 @@
386386
"id": "qtTKz4SC18pt",
387387
"outputId": "1cb68a4d-cd4b-4351-f6dd-ca6635c4dfdf"
388388
},
389-
"execution_count": 19,
389+
"execution_count": null,
390390
"outputs": [
391391
{
392392
"output_type": "display_data",
@@ -427,7 +427,7 @@
427427
"id": "dIhC2nZP2AIC",
428428
"outputId": "b06ef5cd-0eeb-4e4c-de44-5c43021adcf5"
429429
},
430-
"execution_count": 20,
430+
"execution_count": null,
431431
"outputs": [
432432
{
433433
"output_type": "display_data",
@@ -474,7 +474,7 @@
474474
"id": "zDMd-hsd2GJa",
475475
"outputId": "2d5a8e37-1428-4703-d02b-bdf1b4d05bf7"
476476
},
477-
"execution_count": 21,
477+
"execution_count": null,
478478
"outputs": [
479479
{
480480
"output_type": "display_data",
@@ -514,7 +514,7 @@
514514
"id": "YAvbS5w52HEU",
515515
"outputId": "fb36e723-62a6-47a7-c18e-b1a2871dd0ec"
516516
},
517-
"execution_count": 22,
517+
"execution_count": null,
518518
"outputs": [
519519
{
520520
"output_type": "display_data",
@@ -528,6 +528,176 @@
528528
}
529529
]
530530
},
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+
},
531701
{
532702
"cell_type": "markdown",
533703
"source": [

0 commit comments

Comments
 (0)