n = 4+8 "I would like %i shrubberies" % n "'n' declared above has a value of %i" % n import numpy %timeit numpy.sqrt(numpy.ones((400, 400))) values = numpy.arange(30)**2 plot(values) import numpy t1 = numpy.linspace(0,1,5).reshape((1, 5)) t2 = numpy.linspace(1,3,3).reshape((3, 1)) print(t1) print(t2) t1 + t2*1j m = 600 # Height of plot n = 600 # Width of plot values_real = numpy.linspace(-2.3, 1, n).reshape((1,n)) values_imag = numpy.linspace(-1.4, 1.4, m).reshape((m,1)) initial_values = values_real + values_imag*1j initial_values values = initial_values max_iterations = 30 iterations = numpy.ones(initial_values.shape) * max_iterations for i in range(max_iterations) : values = values**2 + initial_values divergent = values * conj(values) > 4 divergent = divergent & (iterations == max_iterations) # Test that we haven't already found this number iterations[divergent] = i imshow(iterations) rcParams['figure.figsize'] = 10, 10 imshow(iterations) def mandelbrot(width, height, x_lim = (-2.3, 1), y_lim = (-1.4, 1.4), max_iterations = 30) : m = height # Height of plot n = width # Width of plot values_real = numpy.linspace(x_lim[0], x_lim[1], n).reshape((1,n)) values_imag = numpy.linspace(y_lim[0], y_lim[1], m).reshape((m,1)) initial_values = values_real + values_imag*1j initial_values values = initial_values iterations = numpy.ones(initial_values.shape) * max_iterations for i in range(max_iterations) : values = values**2 + initial_values divergent = values * conj(values) > 4 divergent = divergent & (iterations == max_iterations) # Test that we haven't already found this number iterations[divergent] = i return iterations mandelbrot_data = mandelbrot(600, 600, (-0.56, -0.55), (-0.56,-0.55), 90) imshow(mandelbrot_data) import pandas, ggplot # Let's pick out a few lines from the image mandelbrot_df = pandas.DataFrame({ i : f for i,f in enumerate(mandelbrot_data) }) mandelbrot_df select_rows_df = pandas.melt(mandelbrot_df[[100,200,300,400]], var_name="line", value_name="iteration") # picking out row 100, 200, 300 and 400 for inspection select_rows_df from ggplot import * ggplot(select_rows_df, aes(x="iteration")) + geom_histogram(binwidth = 5) ggplot(select_rows_df, aes(x="iteration", color="line", fill="line")) + geom_density(alpha=0.3) accumulated_rows_df = mandelbrot_df.mean().reset_index() accumulated_rows_df ggplot(accumulated_rows_df, aes(x="index", y=0)) + geom_line(position="jitter")