Draw Lyapunov Fractal with Python, matplotlib

Introduction

Since August 22, 2016, I have been on a business trip to Malaysia for two months. Since I live in a hotel and have free time on holidays, I decided to make a hobby program for the first time in a while.

Regarding fractals, I have drawn Mandelbrot, Buddhabrot, Julia set, etc., but all of them calculated the color of the coordinates in Fortran and output it in GMT, but this time I decided to try it all in Python did.

As a drawing function, the heat map drawing function (pcolor) of Python-matplotlib is used. It is necessary to prepare the x-coordinate, y-coordinate, and z-value (values that indicate colors on the drawing) in a two-dimensional array, but the coding for drawing can be very simple and convenient for such drawing.

Program example

The following program is a Python version of the BASIC program described in the reference site (1). I changed it a little for my hobby.

The variables to change are as follows

ab Create the basic character string (one-dimensional array in the program) you want to draw as a = 0, b = 1
nm Number of iterations of one-dimensional array * ab *
a0, a1 x-axis range
b0, b1 y-axis range
irx, iry x-axis range and y-axis range divisions

py_lyapunov0.py


import numpy as np
import matplotlib.pyplot as plt

ab=np.array([0,1])
nab=len(ab)
nm=10
a0=2
a1=4
b0=2
b1=4
irx=800
iry=600

x = np.linspace(a0,a1,irx+1)
y = np.linspace(b0,b1,iry+1)
X, Y = np.meshgrid(x, y)

z=np.empty((iry+1,irx+1))
for i in range(0,irx+1):
    a=a0+(a1-a0)/(irx)*i
    for j in range(0,iry+1):
        b=b0+(b1-b0)/(iry)*j
        s=0
        xx=0.5
        for n in range(0,nm):
            for m in range(0,nab):
                if ab[m]==0:
                    rr=a
                else:
                    rr=b
                xx=rr*xx*(1-xx)
                v=np.abs(rr*(1-2*xx))
                if 0<v: s=s+np.log(v)
        s=s/(nm*nab)
        if 2<s:
            z[j,i]=2
        elif s<-5:
            z[j,i]=-5
        else:
            z[j,i]=s

print(np.max(z))
print(np.min(z))

z=-1.0*z
plt.xlim(a0,a1)
plt.ylim(b0,b1)
plt.pcolor(X, Y, z, cmap=plt.cm.spectral)
plt.colorbar()
plt.show()

Drawing example

An example of drawing with the variables described in the above program is shown below.

figure_1.png

Reference site

(1) Lyapunov Fractal drawing program example http://www.rowan.edu/colleges/csm/departments/math/facultystaff/osler/15.%20A%20quick%20look%20at%20Lyapunov%20space.pdf

(2) Heat map example http://yoshihikomuto.hatenablog.jp/entry/2015/04/10/105615

(3) Heat map basics http://d.hatena.ne.jp/y_n_c/20091122/1258904025

(4) Lyapunov Fractal (Wikipedia) [https://ja.wikipedia.org/wiki/%E3%83%AA%E3%82%A2%E3%83%97%E3%83%8E%E3%83%95%E3%83%BB%E3%83%95%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%AB] (https://ja.wikipedia.org/wiki/%E3%83%AA%E3%82%A2%E3%83%97%E3%83%8E%E3%83%95%E3%83%BB%E3%83%95%E3%83%A9%E3%82%AF%E3%82%BF%E3%83%AB)

that's all

Recommended Posts

Draw Lyapunov Fractal with Python, matplotlib
[Python] How to draw multiple graphs with Matplotlib
Draw netCDF file with python
[Python] How to draw a line graph with Matplotlib
Forcibly draw something like a flowchart with Python, matplotlib
[Python] How to draw a scatter plot with Matplotlib
Study math with Python: Draw a sympy (scipy) graph with matplotlib
Create plot animation with Python + Matplotlib
A python graphing manual with Matplotlib.
[Python] font family and font with matplotlib
Draw Japanese with matplotlib on Ubuntu
Draw a loose graph with matplotlib
Draw Koch curve with Python Turtle
Heatmap with Dendrogram in Python + matplotlib
Draw an illustration with Python + OpenCV
Easy to draw graphs with matplotlib
When matplotlib doesn't work with python2.7
Lognormal probability plot with Python, matplotlib
Draw arrows (vectors) with opencv / python
[Python] Set the graph range with matplotlib
Draw Nozomi Sasaki in Excel with python
Fractal to make and play with Python
Draw hierarchical axis labels with matplotlib + pandas
[Python] Let's make matplotlib compatible with Japanese
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
#Python basics (#matplotlib)
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
Animation with matplotlib
with syntax (Python)
My matplotlib (python)
Japanese with matplotlib
Zundokokiyoshi with python
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
Excel with Python
Microcomputer with Python
Cast with python
Draw a flat surface with a matplotlib 3d graph
[Python] limit axis of 3D graph with Matplotlib
[Python] Draw a directed graph with Dash Cytoscape
Try to draw a life curve with python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Draw a graph with matplotlib from a csv file
Create 3D scatter plot with SciPy + matplotlib (Python)
Visualize grib2 on a map with python (matplotlib)
Create fractal shapes with python part1 (Sierpinski Gasket)
[Python] Customize Colormap when drawing graphs with matplotlib
Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6