PK /Q]1F animation/unchained.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n========================\nMATPLOTLIB **UNCHAINED**\n========================\n\nComparative path demonstration of frequency from a fake signal of a pulsar\n(mostly known because of the cover for Joy Division's Unknown Pleasures).\n\nAuthor: Nicolas P. Rougier\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\n# Create new Figure with black background\nfig = plt.figure(figsize=(8, 8), facecolor='black')\n\n# Add a subplot with no frame\nax = plt.subplot(111, frameon=False)\n\n# Generate random data\ndata = np.random.uniform(0, 1, (64, 75))\nX = np.linspace(-1, 1, data.shape[-1])\nG = 1.5 * np.exp(-4 * X ** 2)\n\n# Generate line plots\nlines = []\nfor i in range(len(data)):\n # Small reduction of the X extents to get a cheap perspective effect\n xscale = 1 - i / 200.\n # Same for linewidth (thicker strokes on bottom)\n lw = 1.5 - i / 100.0\n line, = ax.plot(xscale * X, i + G * data[i], color=\"w\", lw=lw)\n lines.append(line)\n\n# Set y limit (or first line is cropped because of thickness)\nax.set_ylim(-1, 70)\n\n# No ticks\nax.set_xticks([])\nax.set_yticks([])\n\n# 2 part titles to get different font weights\nax.text(0.5, 1.0, \"MATPLOTLIB \", transform=ax.transAxes,\n ha=\"right\", va=\"bottom\", color=\"w\",\n family=\"sans-serif\", fontweight=\"light\", fontsize=16)\nax.text(0.5, 1.0, \"UNCHAINED\", transform=ax.transAxes,\n ha=\"left\", va=\"bottom\", color=\"w\",\n family=\"sans-serif\", fontweight=\"bold\", fontsize=16)\n\n\ndef update(*args):\n # Shift all data to the right\n data[:, 1:] = data[:, :-1]\n\n # Fill-in new values\n data[:, 0] = np.random.uniform(0, 1, len(data))\n\n # Update data\n for i in range(len(data)):\n lines[i].set_ydata(i + G * data[i])\n\n # Return modified artists\n return lines\n\n# Construct the animation, using the update function as the animation director.\nanim = animation.FuncAnimation(fig, update, interval=10)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Qr animation/animate_decay.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Decay\n\n\nThis example showcases:\n- using a generator to drive an animation,\n- changing axes limits during an animation.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import itertools\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n\ndef data_gen():\n for cnt in itertools.count():\n t = cnt / 10\n yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)\n\n\ndef init():\n ax.set_ylim(-1.1, 1.1)\n ax.set_xlim(0, 10)\n del xdata[:]\n del ydata[:]\n line.set_data(xdata, ydata)\n return line,\n\nfig, ax = plt.subplots()\nline, = ax.plot([], [], lw=2)\nax.grid()\nxdata, ydata = [], []\n\n\ndef run(data):\n # update the data\n t, y = data\n xdata.append(t)\n ydata.append(y)\n xmin, xmax = ax.get_xlim()\n\n if t >= xmax:\n ax.set_xlim(xmin, 2*xmax)\n ax.figure.canvas.draw()\n line.set_data(xdata, ydata)\n\n return line,\n\nani = animation.FuncAnimation(fig, run, data_gen, interval=10, init_func=init)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /QHHu % animation/frame_grabbing_sgskip.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Frame grabbing\n\n\nUse a MovieWriter directly to grab individual frames and write them to a\nfile. This avoids any event loop integration, and thus works even with the Agg\nbackend. This is not recommended for use in an interactive setting.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib\nmatplotlib.use(\"Agg\")\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FFMpegWriter\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\nmetadata = dict(title='Movie Test', artist='Matplotlib',\n comment='Movie support!')\nwriter = FFMpegWriter(fps=15, metadata=metadata)\n\nfig = plt.figure()\nl, = plt.plot([], [], 'k-o')\n\nplt.xlim(-5, 5)\nplt.ylim(-5, 5)\n\nx0, y0 = 0, 0\n\nwith writer.saving(fig, \"writer_test.mp4\", 100):\n for i in range(100):\n x0 += 0.1 * np.random.randn()\n y0 += 0.1 * np.random.randn()\n l.set_data(x0, y0)\n writer.grab_frame()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Q*
animation/bayes_update.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# The Bayes update\n\n\nThis animation displays the posterior estimate updates as it is refitted when\nnew data arrives.\nThe vertical line represents the theoretical value to which the plotted\ndistribution should converge.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import math\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\n\n\ndef beta_pdf(x, a, b):\n return (x**(a-1) * (1-x)**(b-1) * math.gamma(a + b)\n / (math.gamma(a) * math.gamma(b)))\n\n\nclass UpdateDist:\n def __init__(self, ax, prob=0.5):\n self.success = 0\n self.prob = prob\n self.line, = ax.plot([], [], 'k-')\n self.x = np.linspace(0, 1, 200)\n self.ax = ax\n\n # Set up plot parameters\n self.ax.set_xlim(0, 1)\n self.ax.set_ylim(0, 10)\n self.ax.grid(True)\n\n # This vertical line represents the theoretical value, to\n # which the plotted distribution should converge.\n self.ax.axvline(prob, linestyle='--', color='black')\n\n def __call__(self, i):\n # This way the plot can continuously run and we just keep\n # watching new realizations of the process\n if i == 0:\n self.success = 0\n self.line.set_data([], [])\n return self.line,\n\n # Choose success based on exceed a threshold with a uniform pick\n if np.random.rand(1,) < self.prob:\n self.success += 1\n y = beta_pdf(self.x, self.success + 1, (i - self.success) + 1)\n self.line.set_data(self.x, y)\n return self.line,\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\nfig, ax = plt.subplots()\nud = UpdateDist(ax, prob=0.7)\nanim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Ql animation/animation_demo.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# pyplot animation\n\n\nGenerating an animation by calling `~.pyplot.pause` between plotting commands.\n\nThe method shown here is only suitable for simple, low-performance use. For\nmore demanding applications, look at the :mod:`.animation` module and the\nexamples that use it.\n\nNote that calling `time.sleep` instead of `~.pyplot.pause` would *not* work.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport numpy as np\n\nnp.random.seed(19680801)\ndata = np.random.random((50, 50, 50))\n\nfig, ax = plt.subplots()\n\nfor i in range(len(data)):\n ax.cla()\n ax.imshow(data[i])\n ax.set_title(\"frame {}\".format(i))\n # Note that using time.sleep does *not* work here!\n plt.pause(0.1)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Q가V"
"
animation/strip_chart.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Oscilloscope\n\n\nEmulates an oscilloscope.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nfrom matplotlib.lines import Line2D\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n\nclass Scope:\n def __init__(self, ax, maxt=2, dt=0.02):\n self.ax = ax\n self.dt = dt\n self.maxt = maxt\n self.tdata = [0]\n self.ydata = [0]\n self.line = Line2D(self.tdata, self.ydata)\n self.ax.add_line(self.line)\n self.ax.set_ylim(-.1, 1.1)\n self.ax.set_xlim(0, self.maxt)\n\n def update(self, y):\n lastt = self.tdata[-1]\n if lastt > self.tdata[0] + self.maxt: # reset the arrays\n self.tdata = [self.tdata[-1]]\n self.ydata = [self.ydata[-1]]\n self.ax.set_xlim(self.tdata[0], self.tdata[0] + self.maxt)\n self.ax.figure.canvas.draw()\n\n t = self.tdata[-1] + self.dt\n self.tdata.append(t)\n self.ydata.append(y)\n self.line.set_data(self.tdata, self.ydata)\n return self.line,\n\n\ndef emitter(p=0.1):\n \"\"\"Return a random value in [0, 1) with probability p, else 0.\"\"\"\n while True:\n v = np.random.rand(1)\n if v > p:\n yield 0.\n else:\n yield np.random.rand(1)\n\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801 // 10)\n\n\nfig, ax = plt.subplots()\nscope = Scope(ax)\n\n# pass a generator in \"emitter\" to produce data for the update func\nani = animation.FuncAnimation(fig, scope.update, emitter, interval=50,\n blit=True)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Qw'e]c
c
animation/rain.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Rain simulation\n\n\nSimulates rain drops on a surface by animating the scale and opacity\nof 50 scatter points.\n\nAuthor: Nicolas P. Rougier\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.animation import FuncAnimation\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\n# Create new Figure and an Axes which fills it.\nfig = plt.figure(figsize=(7, 7))\nax = fig.add_axes([0, 0, 1, 1], frameon=False)\nax.set_xlim(0, 1), ax.set_xticks([])\nax.set_ylim(0, 1), ax.set_yticks([])\n\n# Create rain data\nn_drops = 50\nrain_drops = np.zeros(n_drops, dtype=[('position', float, 2),\n ('size', float, 1),\n ('growth', float, 1),\n ('color', float, 4)])\n\n# Initialize the raindrops in random positions and with\n# random growth rates.\nrain_drops['position'] = np.random.uniform(0, 1, (n_drops, 2))\nrain_drops['growth'] = np.random.uniform(50, 200, n_drops)\n\n# Construct the scatter which we will update during animation\n# as the raindrops develop.\nscat = ax.scatter(rain_drops['position'][:, 0], rain_drops['position'][:, 1],\n s=rain_drops['size'], lw=0.5, edgecolors=rain_drops['color'],\n facecolors='none')\n\n\ndef update(frame_number):\n # Get an index which we can use to re-spawn the oldest raindrop.\n current_index = frame_number % n_drops\n\n # Make all colors more transparent as time progresses.\n rain_drops['color'][:, 3] -= 1.0/len(rain_drops)\n rain_drops['color'][:, 3] = np.clip(rain_drops['color'][:, 3], 0, 1)\n\n # Make all circles bigger.\n rain_drops['size'] += rain_drops['growth']\n\n # Pick a new position for oldest rain drop, resetting its size,\n # color and growth factor.\n rain_drops['position'][current_index] = np.random.uniform(0, 1, 2)\n rain_drops['size'][current_index] = 5\n rain_drops['color'][current_index] = (0, 0, 0, 1)\n rain_drops['growth'][current_index] = np.random.uniform(50, 200)\n\n # Update the scatter collection, with the new colors, sizes and positions.\n scat.set_edgecolors(rain_drops['color'])\n scat.set_sizes(rain_drops['size'])\n scat.set_offsets(rain_drops['position'])\n\n\n# Construct the animation, using the update function as the animation director.\nanimation = FuncAnimation(fig, update, interval=10)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Qpƌ " animation/animated_histogram.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Animated histogram\n\n\nUse a path patch to draw a bunch of rectangles for an animated histogram.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as patches\nimport matplotlib.path as path\nimport matplotlib.animation as animation\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n# histogram our data with numpy\ndata = np.random.randn(1000)\nn, bins = np.histogram(data, 100)\n\n# get the corners of the rectangles for the histogram\nleft = bins[:-1]\nright = bins[1:]\nbottom = np.zeros(len(left))\ntop = bottom + n\nnrects = len(left)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here comes the tricky part -- we have to set up the vertex and path codes\narrays using `.Path.MOVETO`, `.Path.LINETO` and `.Path.CLOSEPOLY` for each\nrect.\n\n* We need 1 ``MOVETO`` per rectangle, which sets the initial point.\n* We need 3 ``LINETO``'s, which tell Matplotlib to draw lines from\n vertex 1 to vertex 2, v2 to v3, and v3 to v4.\n* We then need one ``CLOSEPOLY`` which tells Matplotlib to draw a line from\n the v4 to our initial vertex (the ``MOVETO`` vertex), in order to close the\n polygon.\n\n
Note
The vertex for ``CLOSEPOLY`` is ignored, but we still need a placeholder\n in the ``verts`` array to keep the codes aligned with the vertices.
\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nverts = nrects * (1 + 3 + 1)\nverts = np.zeros((nverts, 2))\ncodes = np.full(nverts, path.Path.LINETO)\ncodes[0::5] = path.Path.MOVETO\ncodes[4::5] = path.Path.CLOSEPOLY\nverts[0::5, 0] = left\nverts[0::5, 1] = bottom\nverts[1::5, 0] = left\nverts[1::5, 1] = top\nverts[2::5, 0] = right\nverts[2::5, 1] = top\nverts[3::5, 0] = right\nverts[3::5, 1] = bottom"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To animate the histogram, we need an ``animate`` function, which generates\na random set of numbers and updates the locations of the vertices for the\nhistogram (in this case, only the heights of each rectangle). ``patch`` will\neventually be a `.Patch` object.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"patch = None\n\n\ndef animate(i):\n # simulate new data coming in\n data = np.random.randn(1000)\n n, bins = np.histogram(data, 100)\n top = bottom + n\n verts[1::5, 1] = top\n verts[2::5, 1] = top\n return [patch, ]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And now we build the `.Path` and `.Patch` instances for the histogram using\nour vertices and codes. We add the patch to the `~.axes.Axes` instance, and\nsetup the `.FuncAnimation` with our ``animate`` function.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig, ax = plt.subplots()\nbarpath = path.Path(verts, codes)\npatch = patches.PathPatch(\n barpath, facecolor='green', edgecolor='yellow', alpha=0.5)\nax.add_patch(patch)\n\nax.set_xlim(left[0], right[-1])\nax.set_ylim(bottom.min(), top.max())\n\nani = animation.FuncAnimation(fig, animate, 50, repeat=False, blit=True)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Q@2 animation/dynamic_image.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Animated image using a precomputed list of images\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\nfig, ax = plt.subplots()\n\n\ndef f(x, y):\n return np.sin(x) + np.cos(y)\n\nx = np.linspace(0, 2 * np.pi, 120)\ny = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)\n\n# ims is a list of lists, each row is a list of artists to draw in the\n# current frame; here we are just animating one artist, the image, in\n# each frame\nims = []\nfor i in range(60):\n x += np.pi / 15.\n y += np.pi / 20.\n im = ax.imshow(f(x, y), animated=True)\n if i == 0:\n ax.imshow(f(x, y)) # show an initial one first\n ims.append([im])\n\nani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,\n repeat_delay=1000)\n\n# To save the animation, use e.g.\n#\n# ani.save(\"movie.mp4\")\n#\n# or\n#\n# writer = animation.FFMpegWriter(\n# fps=15, metadata=dict(artist='Me'), bitrate=1800)\n# ani.save(\"movie.mp4\", writer=writer)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Q
animation/double_pendulum.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# The double pendulum problem\n\n\nThis animation illustrates the double pendulum problem.\n\nDouble pendulum formula translated from the C code at\nhttp://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from numpy import sin, cos\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport scipy.integrate as integrate\nimport matplotlib.animation as animation\n\nG = 9.8 # acceleration due to gravity, in m/s^2\nL1 = 1.0 # length of pendulum 1 in m\nL2 = 1.0 # length of pendulum 2 in m\nM1 = 1.0 # mass of pendulum 1 in kg\nM2 = 1.0 # mass of pendulum 2 in kg\nt_stop = 5 # how many seconds to simulate\n\n\ndef derivs(state, t):\n\n dydx = np.zeros_like(state)\n dydx[0] = state[1]\n\n delta = state[2] - state[0]\n den1 = (M1+M2) * L1 - M2 * L1 * cos(delta) * cos(delta)\n dydx[1] = ((M2 * L1 * state[1] * state[1] * sin(delta) * cos(delta)\n + M2 * G * sin(state[2]) * cos(delta)\n + M2 * L2 * state[3] * state[3] * sin(delta)\n - (M1+M2) * G * sin(state[0]))\n / den1)\n\n dydx[2] = state[3]\n\n den2 = (L2/L1) * den1\n dydx[3] = ((- M2 * L2 * state[3] * state[3] * sin(delta) * cos(delta)\n + (M1+M2) * G * sin(state[0]) * cos(delta)\n - (M1+M2) * L1 * state[1] * state[1] * sin(delta)\n - (M1+M2) * G * sin(state[2]))\n / den2)\n\n return dydx\n\n# create a time array from 0..100 sampled at 0.05 second steps\ndt = 0.05\nt = np.arange(0, t_stop, dt)\n\n# th1 and th2 are the initial angles (degrees)\n# w10 and w20 are the initial angular velocities (degrees per second)\nth1 = 120.0\nw1 = 0.0\nth2 = -10.0\nw2 = 0.0\n\n# initial state\nstate = np.radians([th1, w1, th2, w2])\n\n# integrate your ODE using scipy.integrate.\ny = integrate.odeint(derivs, state, t)\n\nx1 = L1*sin(y[:, 0])\ny1 = -L1*cos(y[:, 0])\n\nx2 = L2*sin(y[:, 2]) + x1\ny2 = -L2*cos(y[:, 2]) + y1\n\nfig = plt.figure(figsize=(5, 4))\nax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 1))\nax.set_aspect('equal')\nax.grid()\n\nline, = ax.plot([], [], 'o-', lw=2)\ntime_template = 'time = %.1fs'\ntime_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)\n\n\ndef animate(i):\n thisx = [0, x1[i], x2[i]]\n thisy = [0, y1[i], y2[i]]\n\n line.set_data(thisx, thisy)\n time_text.set_text(time_template % (i*dt))\n return line, time_text\n\n\nani = animation.FuncAnimation(\n fig, animate, len(y), interval=dt*1000, blit=True)\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /Qf"O O animation/random_walk.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Animated 3D random walk\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n\ndef gen_rand_line(length, dims=2):\n \"\"\"\n Create a line using a random walk algorithm.\n\n Parameters\n ----------\n length : int\n The number of points of the line.\n dims : int\n The number of dimensions of the line.\n \"\"\"\n line_data = np.empty((dims, length))\n line_data[:, 0] = np.random.rand(dims)\n for index in range(1, length):\n # scaling the random numbers by 0.1 so\n # movement is small compared to position.\n # subtraction by 0.5 is to change the range to [-0.5, 0.5]\n # to allow a line to move backwards.\n step = (np.random.rand(dims) - 0.5) * 0.1\n line_data[:, index] = line_data[:, index - 1] + step\n return line_data\n\n\ndef update_lines(num, data_lines, lines):\n for line, data in zip(lines, data_lines):\n # NOTE: there is no .set_data() for 3 dim data...\n line.set_data(data[0:2, :num])\n line.set_3d_properties(data[2, :num])\n return lines\n\n\n# Attaching 3D axis to the figure\nfig = plt.figure()\nax = fig.add_subplot(projection=\"3d\")\n\n# Fifty lines of random 3-D lines\ndata = [gen_rand_line(25, 3) for index in range(50)]\n\n# Creating fifty line objects.\n# NOTE: Can't pass empty arrays into 3d version of plot()\nlines = [ax.plot(dat[0, 0:1], dat[1, 0:1], dat[2, 0:1])[0] for dat in data]\n\n# Setting the axes properties\nax.set_xlim3d([0.0, 1.0])\nax.set_xlabel('X')\n\nax.set_ylim3d([0.0, 1.0])\nax.set_ylabel('Y')\n\nax.set_zlim3d([0.0, 1.0])\nax.set_zlabel('Z')\n\nax.set_title('3D Test')\n\n# Creating the Animation object\nline_ani = animation.FuncAnimation(\n fig, update_lines, 50, fargs=(data, lines), interval=50)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK /QuT T animation/simple_anim.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Animated line plot\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\n\nfig, ax = plt.subplots()\n\nx = np.arange(0, 2*np.pi, 0.01)\nline, = ax.plot(x, np.sin(x))\n\n\ndef animate(i):\n line.set_ydata(np.sin(x + i / 50)) # update the data.\n return line,\n\n\nani = animation.FuncAnimation(\n fig, animate, interval=20, blit=True, save_count=50)\n\n# To save the animation, use e.g.\n#\n# ani.save(\"movie.mp4\")\n#\n# or\n#\n# writer = animation.FFMpegWriter(\n# fps=15, metadata=dict(artist='Me'), bitrate=1800)\n# ani.save(\"movie.mp4\", writer=writer)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK խ/Q t % axes_grid1/demo_fixed_size_axes.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo Fixed Size Axes\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nfrom mpl_toolkits.axes_grid1 import Divider, Size"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(6, 6))\n\n# The first items are for padding and the second items are for the axes.\n# sizes are in inch.\nh = [Size.Fixed(1.0), Size.Fixed(4.5)]\nv = [Size.Fixed(0.7), Size.Fixed(5.)]\n\ndivider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)\n# The width and height of the rectangle are ignored.\n\nax = fig.add_axes(divider.get_position(),\n axes_locator=divider.new_locator(nx=1, ny=1))\n\nax.plot([1, 2, 3])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(6, 6))\n\n# The first & third items are for padding and the second items are for the\n# axes. Sizes are in inches.\nh = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)]\nv = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)]\n\ndivider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)\n# The width and height of the rectangle are ignored.\n\nax = fig.add_axes(divider.get_position(),\n axes_locator=divider.new_locator(nx=1, ny=1))\n\nax.plot([1, 2, 3])\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ح/Q1U
, axes_grid1/scatter_hist_locatable_axes.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n==================================\nScatter Histogram (Locatable Axes)\n==================================\n\nShow the marginal distributions of a scatter as histograms at the sides of\nthe plot.\n\nFor a nice alignment of the main axes with the marginals, the axes positions\nare defined by a ``Divider``, produced via `.make_axes_locatable`.\n\nAn alternative method to produce a similar figure is shown in the\n:doc:`/gallery/lines_bars_and_markers/scatter_hist` example. The advantage of\nthe locatable axes method shown below is that the marginal axes follow the\nfixed aspect ratio of the main axes.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\n# the random data\nx = np.random.randn(1000)\ny = np.random.randn(1000)\n\n\nfig, ax = plt.subplots(figsize=(5.5, 5.5))\n\n# the scatter plot:\nax.scatter(x, y)\n\n# Set aspect of the main axes.\nax.set_aspect(1.)\n\n# create new axes on the right and on the top of the current axes\ndivider = make_axes_locatable(ax)\n# below height and pad are in inches\nax_histx = divider.append_axes(\"top\", 1.2, pad=0.1, sharex=ax)\nax_histy = divider.append_axes(\"right\", 1.2, pad=0.1, sharey=ax)\n\n# make some labels invisible\nax_histx.xaxis.set_tick_params(labelbottom=False)\nax_histy.yaxis.set_tick_params(labelleft=False)\n\n# now determine nice limits by hand:\nbinwidth = 0.25\nxymax = max(np.max(np.abs(x)), np.max(np.abs(y)))\nlim = (int(xymax/binwidth) + 1)*binwidth\n\nbins = np.arange(-lim, lim + binwidth, binwidth)\nax_histx.hist(x, bins=bins)\nax_histy.hist(y, bins=bins, orientation='horizontal')\n\n# the xaxis of ax_histx and yaxis of ax_histy are shared with ax,\n# thus there is no need to manually adjust the xlim and ylim of these\n# axis.\n\nax_histx.set_yticks([0, 50, 100])\nax_histy.set_xticks([0, 50, 100])\n\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"------------\n\nReferences\n\"\"\"\"\"\"\"\"\"\"\n\nThe use of the following functions, methods and classes is shown\nin this example:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib\nimport mpl_toolkits\nmpl_toolkits.axes_grid1.axes_divider.make_axes_locatable\nmatplotlib.axes.Axes.set_aspect\nmatplotlib.axes.Axes.scatter\nmatplotlib.axes.Axes.hist"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ҭ/Q " axes_grid1/demo_axes_divider.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo Axes Divider\n\n\nAxes divider to calculate location of axes and\ncreate a divider for them using existing axes instances.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from matplotlib import cbook\nimport matplotlib.pyplot as plt\n\n\ndef get_demo_image():\n z = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\", np_load=True)\n # z is a numpy array of 15x15\n return z, (-3, 4, -4, 3)\n\n\ndef demo_simple_image(ax):\n Z, extent = get_demo_image()\n\n im = ax.imshow(Z, extent=extent)\n cb = plt.colorbar(im)\n plt.setp(cb.ax.get_yticklabels(), visible=False)\n\n\ndef demo_locatable_axes_hard(fig):\n\n from mpl_toolkits.axes_grid1 import SubplotDivider, Size\n from mpl_toolkits.axes_grid1.mpl_axes import Axes\n\n divider = SubplotDivider(fig, 2, 2, 2, aspect=True)\n\n # axes for image\n ax = Axes(fig, divider.get_position())\n\n # axes for colorbar\n ax_cb = Axes(fig, divider.get_position())\n\n h = [Size.AxesX(ax), # main axes\n Size.Fixed(0.05), # padding, 0.1 inch\n Size.Fixed(0.2), # colorbar, 0.3 inch\n ]\n\n v = [Size.AxesY(ax)]\n\n divider.set_horizontal(h)\n divider.set_vertical(v)\n\n ax.set_axes_locator(divider.new_locator(nx=0, ny=0))\n ax_cb.set_axes_locator(divider.new_locator(nx=2, ny=0))\n\n fig.add_axes(ax)\n fig.add_axes(ax_cb)\n\n ax_cb.axis[\"left\"].toggle(all=False)\n ax_cb.axis[\"right\"].toggle(ticks=True)\n\n Z, extent = get_demo_image()\n\n im = ax.imshow(Z, extent=extent)\n plt.colorbar(im, cax=ax_cb)\n plt.setp(ax_cb.get_yticklabels(), visible=False)\n\n\ndef demo_locatable_axes_easy(ax):\n from mpl_toolkits.axes_grid1 import make_axes_locatable\n\n divider = make_axes_locatable(ax)\n\n ax_cb = divider.new_horizontal(size=\"5%\", pad=0.05)\n fig = ax.get_figure()\n fig.add_axes(ax_cb)\n\n Z, extent = get_demo_image()\n im = ax.imshow(Z, extent=extent)\n\n plt.colorbar(im, cax=ax_cb)\n ax_cb.yaxis.tick_right()\n ax_cb.yaxis.set_tick_params(labelright=False)\n\n\ndef demo_images_side_by_side(ax):\n from mpl_toolkits.axes_grid1 import make_axes_locatable\n\n divider = make_axes_locatable(ax)\n\n Z, extent = get_demo_image()\n ax2 = divider.new_horizontal(size=\"100%\", pad=0.05)\n fig1 = ax.get_figure()\n fig1.add_axes(ax2)\n\n ax.imshow(Z, extent=extent)\n ax2.imshow(Z, extent=extent)\n ax2.yaxis.set_tick_params(labelleft=False)\n\n\ndef demo():\n\n fig = plt.figure(figsize=(6, 6))\n\n # PLOT 1\n # simple image & colorbar\n ax = fig.add_subplot(2, 2, 1)\n demo_simple_image(ax)\n\n # PLOT 2\n # image and colorbar whose location is adjusted in the drawing time.\n # a hard way\n\n demo_locatable_axes_hard(fig)\n\n # PLOT 3\n # image and colorbar whose location is adjusted in the drawing time.\n # a easy way\n\n ax = fig.add_subplot(2, 2, 3)\n demo_locatable_axes_easy(ax)\n\n # PLOT 4\n # two images side by side with fixed padding.\n\n ax = fig.add_subplot(2, 2, 4)\n demo_images_side_by_side(ax)\n\n plt.show()\n\n\ndemo()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ٭/Q3 axes_grid1/simple_colorbar.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Simple Colorbar\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import make_axes_locatable\nimport numpy as np\n\nax = plt.subplot(111)\nim = ax.imshow(np.arange(100).reshape((10, 10)))\n\n# create an axes on the right side of ax. The width of cax will be 5%\n# of ax and the padding between cax and ax will be fixed at 0.05 inch.\ndivider = make_axes_locatable(ax)\ncax = divider.append_axes(\"right\", size=\"5%\", pad=0.05)\n\nplt.colorbar(im, cax=cax)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK խ/QVn n # axes_grid1/demo_edge_colorbar.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo Edge Colorbar\n\n\nThis example shows how to use one common colorbar for each row or column\nof an image grid.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from matplotlib import cbook\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import AxesGrid\n\n\nplt.rcParams[\"mpl_toolkits.legacy_colorbar\"] = False\n\n\ndef get_demo_image():\n z = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\", np_load=True)\n # z is a numpy array of 15x15\n return z, (-3, 4, -4, 3)\n\n\ndef demo_bottom_cbar(fig):\n \"\"\"\n A grid of 2x2 images with a colorbar for each column.\n \"\"\"\n grid = AxesGrid(fig, 121, # similar to subplot(121)\n nrows_ncols=(2, 2),\n axes_pad=0.10,\n share_all=True,\n label_mode=\"1\",\n cbar_location=\"bottom\",\n cbar_mode=\"edge\",\n cbar_pad=0.25,\n cbar_size=\"15%\",\n direction=\"column\"\n )\n\n Z, extent = get_demo_image()\n cmaps = [plt.get_cmap(\"autumn\"), plt.get_cmap(\"summer\")]\n for i in range(4):\n im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])\n if i % 2:\n grid.cbar_axes[i//2].colorbar(im)\n\n for cax in grid.cbar_axes:\n cax.toggle_label(True)\n cax.axis[cax.orientation].set_label(\"Bar\")\n\n # This affects all axes as share_all = True.\n grid.axes_llc.set_xticks([-2, 0, 2])\n grid.axes_llc.set_yticks([-2, 0, 2])\n\n\ndef demo_right_cbar(fig):\n \"\"\"\n A grid of 2x2 images. Each row has its own colorbar.\n \"\"\"\n grid = AxesGrid(fig, 122, # similar to subplot(122)\n nrows_ncols=(2, 2),\n axes_pad=0.10,\n label_mode=\"1\",\n share_all=True,\n cbar_location=\"right\",\n cbar_mode=\"edge\",\n cbar_size=\"7%\",\n cbar_pad=\"2%\",\n )\n Z, extent = get_demo_image()\n cmaps = [plt.get_cmap(\"spring\"), plt.get_cmap(\"winter\")]\n for i in range(4):\n im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])\n if i % 2:\n grid.cbar_axes[i//2].colorbar(im)\n\n for cax in grid.cbar_axes:\n cax.toggle_label(True)\n cax.axis[cax.orientation].set_label('Foo')\n\n # This affects all axes because we set share_all = True.\n grid.axes_llc.set_xticks([-2, 0, 2])\n grid.axes_llc.set_yticks([-2, 0, 2])\n\n\nfig = plt.figure(figsize=(5.5, 2.5))\nfig.subplots_adjust(left=0.05, right=0.93)\n\ndemo_bottom_cbar(fig)\ndemo_right_cbar(fig)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ح/QQL @z z axes_grid1/simple_axesgrid.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Simple ImageGrid\n\n\nAlign multiple images using `~mpl_toolkits.axes_grid1.axes_grid.ImageGrid`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1 import ImageGrid\nimport numpy as np\n\nim1 = np.arange(100).reshape((10, 10))\nim2 = im1.T\nim3 = np.flipud(im1)\nim4 = np.fliplr(im2)\n\nfig = plt.figure(figsize=(4., 4.))\ngrid = ImageGrid(fig, 111, # similar to subplot(111)\n nrows_ncols=(2, 2), # creates 2x2 grid of axes\n axes_pad=0.1, # pad between axes in inch.\n )\n\nfor ax, im in zip(grid, [im1, im2, im3, im4]):\n # Iterating over the grid returns the Axes.\n ax.imshow(im)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ԭ/Q@ ' axes_grid1/demo_axes_hbox_divider.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n===================\n`.HBoxDivider` demo\n===================\n\nUsing an `.HBoxDivider` to arrange subplots.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1.axes_divider import HBoxDivider\nimport mpl_toolkits.axes_grid1.axes_size as Size\n\n\ndef make_heights_equal(fig, rect, ax1, ax2, pad):\n # pad in inches\n divider = HBoxDivider(\n fig, rect,\n horizontal=[Size.AxesX(ax1), Size.Fixed(pad), Size.AxesX(ax2)],\n vertical=[Size.AxesY(ax1), Size.Scaled(1), Size.AxesY(ax2)])\n ax1.set_axes_locator(divider.new_locator(0))\n ax2.set_axes_locator(divider.new_locator(2))\n\n\nif __name__ == \"__main__\":\n\n arr1 = np.arange(20).reshape((4, 5))\n arr2 = np.arange(20).reshape((5, 4))\n\n fig, (ax1, ax2) = plt.subplots(1, 2)\n ax1.imshow(arr1)\n ax2.imshow(arr2)\n\n make_heights_equal(fig, 111, ax1, ax2, pad=0.5)\n\n fig.text(.5, .5,\n \"Both axes' location are adjusted\\n\"\n \"so that they have equal heights\\n\"\n \"while maintaining their aspect ratios\",\n va=\"center\", ha=\"center\",\n bbox=dict(boxstyle=\"round, pad=1\", facecolor=\"w\"))\n\n plt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ҭ/Q6 / axes_grid1/demo_anchored_direction_arrows.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo Anchored Direction Arrow\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport numpy as np\nfrom mpl_toolkits.axes_grid1.anchored_artists import AnchoredDirectionArrows\nimport matplotlib.font_manager as fm\n\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nfig, ax = plt.subplots()\nax.imshow(np.random.random((10, 10)))\n\n# Simple example\nsimple_arrow = AnchoredDirectionArrows(ax.transAxes, 'X', 'Y')\nax.add_artist(simple_arrow)\n\n# High contrast arrow\nhigh_contrast_part_1 = AnchoredDirectionArrows(\n ax.transAxes,\n '111', r'11$\\overline{2}$',\n loc='upper right',\n arrow_props={'ec': 'w', 'fc': 'none', 'alpha': 1,\n 'lw': 2}\n )\nax.add_artist(high_contrast_part_1)\n\nhigh_contrast_part_2 = AnchoredDirectionArrows(\n ax.transAxes,\n '111', r'11$\\overline{2}$',\n loc='upper right',\n arrow_props={'ec': 'none', 'fc': 'k'},\n text_props={'ec': 'w', 'fc': 'k', 'lw': 0.4}\n )\nax.add_artist(high_contrast_part_2)\n\n# Rotated arrow\nfontprops = fm.FontProperties(family='serif')\n\nroatated_arrow = AnchoredDirectionArrows(\n ax.transAxes,\n '30', '120',\n loc='center',\n color='w',\n angle=30,\n fontproperties=fontprops\n )\nax.add_artist(roatated_arrow)\n\n# Altering arrow directions\na1 = AnchoredDirectionArrows(\n ax.transAxes, 'A', 'B', loc='lower center',\n length=-0.15,\n sep_x=0.03, sep_y=0.03,\n color='r'\n )\nax.add_artist(a1)\n\na2 = AnchoredDirectionArrows(\n ax.transAxes, 'A', ' B', loc='lower left',\n aspect_ratio=-1,\n sep_x=0.01, sep_y=-0.02,\n color='orange'\n )\nax.add_artist(a2)\n\n\na3 = AnchoredDirectionArrows(\n ax.transAxes, ' A', 'B', loc='lower right',\n length=-0.15,\n aspect_ratio=-1,\n sep_y=-0.1, sep_x=0.04,\n color='cyan'\n )\nax.add_artist(a3)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ح/QB
B
% axes_grid1/simple_axes_divider1.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Simple Axes Divider 1\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from mpl_toolkits.axes_grid1 import Size, Divider\nimport matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Fixed axes sizes; fixed paddings.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(6, 6))\n\n# Sizes are in inches.\nhoriz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]\nvert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]\n\nrect = (0.1, 0.1, 0.8, 0.8)\n# Divide the axes rectangle into a grid with sizes specified by horiz * vert.\ndivider = Divider(fig, rect, horiz, vert, aspect=False)\n\n# The rect parameter will actually be ignored and overridden by axes_locator.\nax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))\nax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))\nax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))\nax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))\n\nfor ax in fig.axes:\n ax.tick_params(labelbottom=False, labelleft=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Axes sizes that scale with the figure size; fixed paddings.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(6, 6))\n\nhoriz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]\nvert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]\n\nrect = (0.1, 0.1, 0.8, 0.8)\n# Divide the axes rectangle into a grid with sizes specified by horiz * vert.\ndivider = Divider(fig, rect, horiz, vert, aspect=False)\n\n# The rect parameter will actually be ignored and overridden by axes_locator.\nax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))\nax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))\nax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))\nax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))\n\nfor ax in fig.axes:\n ax.tick_params(labelbottom=False, labelleft=False)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ԭ/Q axes_grid1/demo_axes_rgb.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Demo Axes RGB\n\n\nRGBAxes to show RGB composite images.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nfrom matplotlib import cbook\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, RGBAxes\n\n\ndef get_rgb():\n Z = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\", np_load=True)\n Z[Z < 0] = 0.\n Z = Z / Z.max()\n\n R = Z[:13, :13]\n G = Z[2:, 2:]\n B = Z[:13, 2:]\n\n return R, G, B\n\n\ndef make_cube(r, g, b):\n ny, nx = r.shape\n R = np.zeros((ny, nx, 3))\n R[:, :, 0] = r\n G = np.zeros_like(R)\n G[:, :, 1] = g\n B = np.zeros_like(R)\n B[:, :, 2] = b\n\n RGB = R + G + B\n\n return R, G, B, RGB\n\n\ndef demo_rgb1():\n fig = plt.figure()\n ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)\n r, g, b = get_rgb()\n ax.imshow_rgb(r, g, b)\n\n\ndef demo_rgb2():\n fig, ax = plt.subplots()\n ax_r, ax_g, ax_b = make_rgb_axes(ax, pad=0.02)\n\n r, g, b = get_rgb()\n im_r, im_g, im_b, im_rgb = make_cube(r, g, b)\n ax.imshow(im_rgb)\n ax_r.imshow(im_r)\n ax_g.imshow(im_g)\n ax_b.imshow(im_b)\n\n for ax in fig.axes:\n ax.tick_params(axis='both', direction='in')\n for sp1 in ax.spines.values():\n sp1.set_color(\"w\")\n for tick in ax.xaxis.get_major_ticks() + ax.yaxis.get_major_ticks():\n tick.tick1line.set_markeredgecolor(\"w\")\n tick.tick2line.set_markeredgecolor(\"w\")\n\n\ndemo_rgb1()\ndemo_rgb2()\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ֭/Q꾠 # axes_grid1/inset_locator_demo.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Inset Locator Demo\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `.inset_locator`'s `~.inset_locator.inset_axes` allows\neasily placing insets in the corners of the axes by specifying a width and\nheight and optionally a location (loc) that accepts locations as codes,\nsimilar to `~matplotlib.axes.Axes.legend`.\nBy default, the inset is offset by some points from the axes,\ncontrolled via the *borderpad* parameter.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1.inset_locator import inset_axes\n\n\nfig, (ax, ax2) = plt.subplots(1, 2, figsize=[5.5, 2.8])\n\n# Create inset of width 1.3 inches and height 0.9 inches\n# at the default upper right location\naxins = inset_axes(ax, width=1.3, height=0.9)\n\n# Create inset of width 30% and height 40% of the parent axes' bounding box\n# at the lower left corner (loc=3)\naxins2 = inset_axes(ax, width=\"30%\", height=\"40%\", loc=3)\n\n# Create inset of mixed specifications in the second subplot;\n# width is 30% of parent axes' bounding box and\n# height is 1 inch at the upper left corner (loc=2)\naxins3 = inset_axes(ax2, width=\"30%\", height=1., loc=2)\n\n# Create an inset in the lower right corner (loc=4) with borderpad=1, i.e.\n# 10 points padding (as 10pt is the default fontsize) to the parent axes\naxins4 = inset_axes(ax2, width=\"20%\", height=\"20%\", loc=4, borderpad=1)\n\n# Turn ticklabels of insets off\nfor axi in [axins, axins2, axins3, axins4]:\n axi.tick_params(labelleft=False, labelbottom=False)\n\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The arguments *bbox_to_anchor* and *bbox_transfrom* can be used for a more\nfine grained control over the inset position and size or even to position\nthe inset at completely arbitrary positions.\nThe *bbox_to_anchor* sets the bounding box in coordinates according to the\n*bbox_transform*.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=[5.5, 2.8])\nax = fig.add_subplot(121)\n\n# We use the axes transform as bbox_transform. Therefore the bounding box\n# needs to be specified in axes coordinates ((0, 0) is the lower left corner\n# of the axes, (1, 1) is the upper right corner).\n# The bounding box (.2, .4, .6, .5) starts at (.2, .4) and ranges to (.8, .9)\n# in those coordinates.\n# Inside of this bounding box an inset of half the bounding box' width and\n# three quarters of the bounding box' height is created. The lower left corner\n# of the inset is aligned to the lower left corner of the bounding box (loc=3).\n# The inset is then offset by the default 0.5 in units of the font size.\n\naxins = inset_axes(ax, width=\"50%\", height=\"75%\",\n bbox_to_anchor=(.2, .4, .6, .5),\n bbox_transform=ax.transAxes, loc=3)\n\n# For visualization purposes we mark the bounding box by a rectangle\nax.add_patch(plt.Rectangle((.2, .4), .6, .5, ls=\"--\", ec=\"c\", fc=\"None\",\n transform=ax.transAxes))\n\n# We set the axis limits to something other than the default, in order to not\n# distract from the fact that axes coordinates are used here.\nax.set(xlim=(0, 10), ylim=(0, 10))\n\n\n# Note how the two following insets are created at the same positions, one by\n# use of the default parent axes' bbox and the other via a bbox in axes\n# coordinates and the respective transform.\nax2 = fig.add_subplot(222)\naxins2 = inset_axes(ax2, width=\"30%\", height=\"50%\")\n\nax3 = fig.add_subplot(224)\naxins3 = inset_axes(ax3, width=\"100%\", height=\"100%\",\n bbox_to_anchor=(.7, .5, .3, .5),\n bbox_transform=ax3.transAxes)\n\n# For visualization purposes we mark the bounding box by a rectangle\nax2.add_patch(plt.Rectangle((0, 0), 1, 1, ls=\"--\", lw=2, ec=\"c\", fc=\"None\"))\nax3.add_patch(plt.Rectangle((.7, .5), .3, .5, ls=\"--\", lw=2,\n ec=\"c\", fc=\"None\"))\n\n# Turn ticklabels off\nfor axi in [axins2, axins3, ax2, ax3]:\n axi.tick_params(labelleft=False, labelbottom=False)\n\nplt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the above the axes transform together with 4-tuple bounding boxes has been\nused as it mostly is useful to specify an inset relative to the axes it is\nan inset to. However other use cases are equally possible. The following\nexample examines some of those.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"fig = plt.figure(figsize=[5.5, 2.8])\nax = fig.add_subplot(131)\n\n# Create an inset outside the axes\naxins = inset_axes(ax, width=\"100%\", height=\"100%\",\n bbox_to_anchor=(1.05, .6, .5, .4),\n bbox_transform=ax.transAxes, loc=2, borderpad=0)\naxins.tick_params(left=False, right=True, labelleft=False, labelright=True)\n\n# Create an inset with a 2-tuple bounding box. Note that this creates a\n# bbox without extent. This hence only makes sense when specifying\n# width and height in absolute units (inches).\naxins2 = inset_axes(ax, width=0.5, height=0.4,\n bbox_to_anchor=(0.33, 0.25),\n bbox_transform=ax.transAxes, loc=3, borderpad=0)\n\n\nax2 = fig.add_subplot(133)\nax2.set_xscale(\"log\")\nax2.set(xlim=(1e-6, 1e6), ylim=(-2, 6))\n\n# Create inset in data coordinates using ax.transData as transform\naxins3 = inset_axes(ax2, width=\"100%\", height=\"100%\",\n bbox_to_anchor=(1e-2, 2, 1e3, 3),\n bbox_transform=ax2.transData, loc=2, borderpad=0)\n\n# Create an inset horizontally centered in figure coordinates and vertically\n# bound to line up with the axes.\nfrom matplotlib.transforms import blended_transform_factory\ntransform = blended_transform_factory(fig.transFigure, ax2.transAxes)\naxins4 = inset_axes(ax2, width=\"16%\", height=\"34%\",\n bbox_to_anchor=(0, 0, 1, 1),\n bbox_transform=transform, loc=8, borderpad=0)\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ֭/Qk2?
?
$ axes_grid1/inset_locator_demo2.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Inset Locator Demo2\n\n\nThis Demo shows how to create a zoomed inset via `~.zoomed_inset_axes`.\nIn the first subplot an `~.AnchoredSizeBar` shows the zoom effect.\nIn the second subplot a connection to the region of interest is\ncreated via `~.mark_inset`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from matplotlib import cbook\nimport matplotlib.pyplot as plt\nfrom mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset\nfrom mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar\n\nimport numpy as np\n\n\ndef get_demo_image():\n z = cbook.get_sample_data(\"axes_grid/bivariate_normal.npy\", np_load=True)\n # z is a numpy array of 15x15\n return z, (-3, 4, -4, 3)\n\nfig, (ax, ax2) = plt.subplots(ncols=2, figsize=[6, 3])\n\n\n# First subplot, showing an inset with a size bar.\nax.set_aspect(1)\n\naxins = zoomed_inset_axes(ax, zoom=0.5, loc='upper right')\n# fix the number of ticks on the inset axes\naxins.yaxis.get_major_locator().set_params(nbins=7)\naxins.xaxis.get_major_locator().set_params(nbins=7)\n\nplt.setp(axins.get_xticklabels(), visible=False)\nplt.setp(axins.get_yticklabels(), visible=False)\n\n\ndef add_sizebar(ax, size):\n asb = AnchoredSizeBar(ax.transData,\n size,\n str(size),\n loc=8,\n pad=0.1, borderpad=0.5, sep=5,\n frameon=False)\n ax.add_artist(asb)\n\nadd_sizebar(ax, 0.5)\nadd_sizebar(axins, 0.5)\n\n\n# Second subplot, showing an image with an inset zoom\n# and a marked inset\nZ, extent = get_demo_image()\nZ2 = np.zeros((150, 150))\nny, nx = Z.shape\nZ2[30:30+ny, 30:30+nx] = Z\n\nax2.imshow(Z2, extent=extent, origin=\"lower\")\n\naxins2 = zoomed_inset_axes(ax2, zoom=6, loc=1)\naxins2.imshow(Z2, extent=extent, origin=\"lower\")\n\n# sub region of the original image\nx1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9\naxins2.set_xlim(x1, x2)\naxins2.set_ylim(y1, y2)\n# fix the number of ticks on the inset axes\naxins2.yaxis.get_major_locator().set_params(nbins=7)\naxins2.xaxis.get_major_locator().set_params(nbins=7)\n\nplt.setp(axins2.get_xticklabels(), visible=False)\nplt.setp(axins2.get_yticklabels(), visible=False)\n\n# draw a bbox of the region of the inset axes in the parent axes and\n# connecting lines between the bbox and the inset axes area\nmark_inset(ax2, axins2, loc1=2, loc2=4, fc=\"none\", ec=\"0.5\")\n\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ֭/Q' &