Skip to content

Instantly share code, notes, and snippets.

@gaebor
Last active April 26, 2016 18:16
Show Gist options
  • Save gaebor/41f73ce934fafb383934c389254a72ad to your computer and use it in GitHub Desktop.
Save gaebor/41f73ce934fafb383934c389254a72ad to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"n = 1024\n",
"x0 = -1.5; x1 = 0.5\n",
"y0 = -1; y1 = 1\n",
"iter_number = 100\n",
"image_size = 5\n",
"\n",
"x = numpy.linspace(x0,x1, n)\n",
"y = numpy.linspace(y0,y1, n)\n",
"reC = numpy.ones((n,1)).dot(x.reshape(1,n))\n",
"imC = y.reshape(n,1).dot(numpy.ones((1,n)))\n",
"C = reC + 1j * imC\n",
"\n",
"Z = numpy.zeros((n,n)).astype(\"complex\")\n",
"for i in xrange(iter_number):\n",
" Z = Z**2 + C\n",
"\n",
"# img = 1.0/(1.0+numpy.sqrt(numpy.real(Z * numpy.conj(Z))))\n",
"img = numpy.sqrt(numpy.real(Z * numpy.conj(Z))) < 1.0\n",
"\n",
"fig, ax = plt.subplots(figsize=(image_size, image_size))\n",
"ticks = numpy.linspace(0,n-1,11).astype(int)\n",
"ax.set_xticks(ticks)\n",
"ax.set_yticks(ticks)\n",
"ax.set_xticklabels(map(lambda q: \"%.2g\" % q,x[ticks]))\n",
"ax.set_yticklabels(map(lambda q: \"%.2gi\" % q,y[ticks[::-1]]))\n",
"plt.imshow(img, cmap=\"bone\", aspect=(y1-y0)/(x1-x0))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.3rc2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment