Mandelbrot Set Visualization in Python
Skills:
AI Pair Programming70%
Key Takeaways
Visualizes the Mandelbrot set using Python
Full Transcript
what's going on guys welcome back in this video today we're going to visualize the mandle broad set in Python so let us get right into [Music] it all right so this is going to be a straightforward and practical video we're going to focus on the implementation and not too much on the mathematics and the theory behind the manal broad set and the fractal if you want to have an explanation or an exploration from me let me know in the comment section down below otherwise you can just look it up on Wikipedia or ask chat GPT about it we're going to focus here on the implementation and the visualization and for this we're going to need two external python packages so you can open up your terminal and you can use pip or pip 3 to install matte plot lip and numai those are the two packages we're going to need in this video today once you have them installed you can just import them as NP and mathod lip. pipel S PLT uh now the idea is that we're going to define a function the mandle broad function and then we're going to use it to determine whether a complex number is part of the set or not then we're going to construct a set and then we're going to visualize the set so we're going to start by defining a function mandle broad it's going to take a complex number and a maximum number of iterations uh it should not diverge if it's part of uh the mandal broad set and then we're going to say Z equals 0 this is just the formula the calculation uh we go for a maximum of Max iteration so 4N in um in range Max iteration and what we want to do now is we want to say okay if the absolute value of Z so exceeds two so basically if Z is below -2 or above two uh we return the number of iterations it took to diverge to go out of the bounce and otherwise what we do is we say Z equal z^2 plus the complex number so that's the iteration and we just assume that after a certain number of iteration iterations if it didn't um if it didn't uh diverge then we're going to say it's basically part of the set so we're going to return the max iterations all right then we're going to define a function mandle BR set and this function mandle BR set takes xmin x max y Min y Max width and height and also Max iterations and here basically we're going to cont construct a full set so we're going to say x equals NP length space so just creating the coordinates basically from xmin to x max with the following width and then we're going to copy that and do the same thing for y so y minimum y maximum and width and then what we're going to do is we're going to recursively call that function uh or actually no we're not going to rively call this function I just noticed right now that in my code I uh basically named the function the same way as my local variable so let's call this different let's call this m set for manual broad Set uh we're going to initialize this as a numpy array full of zeros with the following shape height and width and then we're going to say for I in range now we're going to construct complex numbers for I in range height 4 J in range width we're going to say that we want to have a complex number this is a python data type that is supported uh by default and it's going to be XJ y i and now what we want to do is want to say mset i j is equal to mandle BR and we want to pass the complex number and the max iterations that are pass to this function and then basically we want to return the mandal broth set all right so that is that the only thing we need to do now is we need to specify uh the parameters and then we can basically display the image so we can say x Min x max y Min y Max is equal to -2 uh 1 - 1.5 and 1.5 and then we're going to say that the width and the height are equal to 1,000 and 1,000 and we're going to allow for a maximum of 100 iterations until we say it's part of the set then we're going to construct the mandal BR image and of course this is going to only have a certain resolution so we cannot uh because if you know the fractal you can maybe look up some tool online that allows you to zoom into it interactively um oh by the way sorry this is we need to return M set not the function um when you look up the uh the fractal online you will see that you can endlessly zoom in of course we don't have that granularity because we're just going to picture it uh on High level so in a in a um just just as an overview we're not going to go deep and deeper and deeper into it um and because of that we have a limited uh scope here so we're going to call the function mandle BR set and we're going to pass to it X Min xmax y Min y Max withth height and the max iteration so basically these parameters here and now all we have to do is we have to display them so PLT imow we want to display the image the mandle BR image uh and the extent here is just X-Men xmax yman y Max and and we're going to use the hot color map um then we can say PLT color bar just so we see what the color stands for and then we're going to say PLT title just some basic stuff like mandle brought visualization and then uh we can label the axis of the complex number so xlabel is going to be uh real number or real part and the Y label is going to be the imaginary part and then we're going to just show this and when I run this now you will hopefully see if I didn't make any mistakes there you go the fractal visualized the manual broad set now of course you could go and try to calculate this deeper and deeper if you zoom into it so that it never ends but that is computationally very intensive um and expensive so yeah this is a simple way to just visualize the set of course you can also use a different color map basically everything you have in here uh is Max iterations which means it's part of the set and everything that you see that has color is not part of the set and terminates after uh or diverges after uh very few iterations around here and takes longer on a coastline here which is infinite of course even though uh the area is finite so yeah this is how you visualize the mandle broad set in Python so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye
Original Description
In this video we learn how to visualize the Mandelbrot set in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
💼 Services 💼
💻 Freelancing & Tutoring: https://www.neuralnine.com/services
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related Reads
🎓
Tutor Explanation
DeepCamp AI