March 2014
Beginner to intermediate
222 pages
4h 7m
English
Let's start with the most basic scenario. We have a 2D array, and we want to visualize its content. As an example, we will visualize the Mandelbrot set. The Mandelbrot set, a famous fractal shape, associates a number of iterations to each point on the plane.
We will first fill a 2D square array with values and then call pyplot.imshow() to visualize it, as shown in the following code:
import numpy as np import matplotlib.cm as cm from matplotlib import pyplot as plt def iter_count(C, max_iter): X = C for n in range(max_iter): if abs(X) > 2.: return n X = X ** 2 + C return max_iter N = 512 max_iter = 64 xmin, xmax, ymin, ymax = -2.2, .8, -1.5, 1.5 X = np.linspace(xmin, xmax, N) Y = np.linspace(ymin, ...
Read now
Unlock full access