Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d66d14

Browse files
committed
copy correct docs to top level
1 parent 65f2da2 commit 5d66d14

File tree

7,806 files changed

+147962
-174597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,806 files changed

+147962
-174597
lines changed

Matplotlib.pdf

-23.8 MB
Binary file not shown.

_downloads/affine_image.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import numpy as np\nimport matplotlib.mlab as mlab\nimport matplotlib.pyplot as plt\nimport matplotlib.transforms as mtransforms\n\n\ndef get_image():\n delta = 0.25\n x = y = np.arange(-3.0, 3.0, delta)\n X, Y = np.meshgrid(x, y)\n Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)\n Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)\n Z = Z2 - Z1 # difference of Gaussians\n return Z\n\n\ndef do_plot(ax, Z, transform):\n im = ax.imshow(Z, interpolation='none',\n origin='lower',\n extent=[-2, 4, -3, 2], clip_on=True)\n\n trans_data = transform + ax.transData\n im.set_transform(trans_data)\n\n # display intended extent of the image\n x1, x2, y1, y2 = im.get_extent()\n ax.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], \"y--\",\n transform=trans_data)\n ax.set_xlim(-5, 5)\n ax.set_ylim(-4, 4)\n\n\n# prepare image and figure\nfig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)\nZ = get_image()\n\n# image rotation\ndo_plot(ax1, Z, mtransforms.Affine2D().rotate_deg(30))\n\n# image skew\ndo_plot(ax2, Z, mtransforms.Affine2D().skew_deg(30, 15))\n\n# scale and reflection\ndo_plot(ax3, Z, mtransforms.Affine2D().scale(-1, .5))\n\n# everything and a translation\ndo_plot(ax4, Z, mtransforms.Affine2D().\n rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1))\n\nplt.show()"
29+
"import numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.transforms as mtransforms\n\n\ndef get_image():\n delta = 0.25\n x = y = np.arange(-3.0, 3.0, delta)\n X, Y = np.meshgrid(x, y)\n Z1 = np.exp(-X**2 - Y**2)\n Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)\n Z = (Z1 - Z2)\n return Z\n\n\ndef do_plot(ax, Z, transform):\n im = ax.imshow(Z, interpolation='none',\n origin='lower',\n extent=[-2, 4, -3, 2], clip_on=True)\n\n trans_data = transform + ax.transData\n im.set_transform(trans_data)\n\n # display intended extent of the image\n x1, x2, y1, y2 = im.get_extent()\n ax.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], \"y--\",\n transform=trans_data)\n ax.set_xlim(-5, 5)\n ax.set_ylim(-4, 4)\n\n\n# prepare image and figure\nfig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)\nZ = get_image()\n\n# image rotation\ndo_plot(ax1, Z, mtransforms.Affine2D().rotate_deg(30))\n\n# image skew\ndo_plot(ax2, Z, mtransforms.Affine2D().skew_deg(30, 15))\n\n# scale and reflection\ndo_plot(ax3, Z, mtransforms.Affine2D().scale(-1, .5))\n\n# everything and a translation\ndo_plot(ax4, Z, mtransforms.Affine2D().\n rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1))\n\nplt.show()"
3030
]
3131
}
3232
],

_downloads/affine_image.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010

1111
import numpy as np
12-
import matplotlib.mlab as mlab
1312
import matplotlib.pyplot as plt
1413
import matplotlib.transforms as mtransforms
1514

@@ -18,9 +17,9 @@ def get_image():
1817
delta = 0.25
1918
x = y = np.arange(-3.0, 3.0, delta)
2019
X, Y = np.meshgrid(x, y)
21-
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
22-
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
23-
Z = Z2 - Z1 # difference of Gaussians
20+
Z1 = np.exp(-X**2 - Y**2)
21+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
22+
Z = (Z1 - Z2)
2423
return Z
2524

2625

_downloads/align_labels_demo.ipynb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"%matplotlib inline"
12+
]
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"metadata": {},
17+
"source": [
18+
"\n# Aligning Labels\n\n\nAligning xlabel and ylabel using `Figure.align_xlabels` and\n`Figure.align_ylabels`\n\n`Figure.align_labels` wraps these two functions.\n\nNote that the xlabel \"XLabel1 1\" would normally be much closer to the\nx-axis, and \"YLabel1 0\" would be much closer to the y-axis of their\nrespective axes.\n\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [],
28+
"source": [
29+
"import matplotlib.pyplot as plt\nimport numpy as np\nimport matplotlib.gridspec as gridspec\n\nfig = plt.figure(tight_layout=True)\ngs = gridspec.GridSpec(2, 2)\n\nax = fig.add_subplot(gs[0, :])\nax.plot(np.arange(0, 1e6, 1000))\nax.set_ylabel('YLabel0')\nax.set_xlabel('XLabel0')\n\nfor i in range(2):\n ax = fig.add_subplot(gs[1, i])\n ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1))\n ax.set_ylabel('YLabel1 %d' % i)\n ax.set_xlabel('XLabel1 %d' % i)\n if i == 0:\n for tick in ax.get_xticklabels():\n tick.set_rotation(55)\nfig.align_labels() # same as fig.align_xlabels(); fig.align_ylabels()\n\nplt.show()"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"kernelspec": {
35+
"display_name": "Python 3",
36+
"language": "python",
37+
"name": "python3"
38+
},
39+
"language_info": {
40+
"codemirror_mode": {
41+
"name": "ipython",
42+
"version": 3
43+
},
44+
"file_extension": ".py",
45+
"mimetype": "text/x-python",
46+
"name": "python",
47+
"nbconvert_exporter": "python",
48+
"pygments_lexer": "ipython3",
49+
"version": "3.6.4"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}

_downloads/align_labels_demo.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
===============
3+
Aligning Labels
4+
===============
5+
6+
Aligning xlabel and ylabel using `Figure.align_xlabels` and
7+
`Figure.align_ylabels`
8+
9+
`Figure.align_labels` wraps these two functions.
10+
11+
Note that the xlabel "XLabel1 1" would normally be much closer to the
12+
x-axis, and "YLabel1 0" would be much closer to the y-axis of their
13+
respective axes.
14+
"""
15+
import matplotlib.pyplot as plt
16+
import numpy as np
17+
import matplotlib.gridspec as gridspec
18+
19+
fig = plt.figure(tight_layout=True)
20+
gs = gridspec.GridSpec(2, 2)
21+
22+
ax = fig.add_subplot(gs[0, :])
23+
ax.plot(np.arange(0, 1e6, 1000))
24+
ax.set_ylabel('YLabel0')
25+
ax.set_xlabel('XLabel0')
26+
27+
for i in range(2):
28+
ax = fig.add_subplot(gs[1, i])
29+
ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1))
30+
ax.set_ylabel('YLabel1 %d' % i)
31+
ax.set_xlabel('XLabel1 %d' % i)
32+
if i == 0:
33+
for tick in ax.get_xticklabels():
34+
tick.set_rotation(55)
35+
fig.align_labels() # same as fig.align_xlabels(); fig.align_ylabels()
36+
37+
plt.show()

_downloads/align_ylabels.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"import numpy as np\nimport matplotlib.pyplot as plt\n\nbox = dict(facecolor='yellow', pad=5, alpha=0.2)\n\nfig = plt.figure()\nfig.subplots_adjust(left=0.2, wspace=0.6)\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nax1 = fig.add_subplot(221)\nax1.plot(2000*np.random.rand(10))\nax1.set_title('ylabels not aligned')\nax1.set_ylabel('misaligned 1', bbox=box)\nax1.set_ylim(0, 2000)\nax3 = fig.add_subplot(223)\nax3.set_ylabel('misaligned 2',bbox=box)\nax3.plot(np.random.rand(10))\n\n\nlabelx = -0.3 # axes coords\n\nax2 = fig.add_subplot(222)\nax2.set_title('ylabels aligned')\nax2.plot(2000*np.random.rand(10))\nax2.set_ylabel('aligned 1', bbox=box)\nax2.yaxis.set_label_coords(labelx, 0.5)\nax2.set_ylim(0, 2000)\n\nax4 = fig.add_subplot(224)\nax4.plot(np.random.rand(10))\nax4.set_ylabel('aligned 2', bbox=box)\nax4.yaxis.set_label_coords(labelx, 0.5)\n\n\nplt.show()"
29+
"import numpy as np\nimport matplotlib.pyplot as plt\n\nbox = dict(facecolor='yellow', pad=5, alpha=0.2)\n\nfig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)\nfig.subplots_adjust(left=0.2, wspace=0.6)\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nax1.plot(2000*np.random.rand(10))\nax1.set_title('ylabels not aligned')\nax1.set_ylabel('misaligned 1', bbox=box)\nax1.set_ylim(0, 2000)\n\nax3.set_ylabel('misaligned 2',bbox=box)\nax3.plot(np.random.rand(10))\n\nlabelx = -0.3 # axes coords\n\nax2.set_title('ylabels aligned')\nax2.plot(2000*np.random.rand(10))\nax2.set_ylabel('aligned 1', bbox=box)\nax2.yaxis.set_label_coords(labelx, 0.5)\nax2.set_ylim(0, 2000)\n\nax4.plot(np.random.rand(10))\nax4.set_ylabel('aligned 2', bbox=box)\nax4.yaxis.set_label_coords(labelx, 0.5)\n\nplt.show()"
3030
]
3131
}
3232
],

_downloads/align_ylabels.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,30 @@
99

1010
box = dict(facecolor='yellow', pad=5, alpha=0.2)
1111

12-
fig = plt.figure()
12+
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
1313
fig.subplots_adjust(left=0.2, wspace=0.6)
1414

1515
# Fixing random state for reproducibility
1616
np.random.seed(19680801)
1717

18-
ax1 = fig.add_subplot(221)
1918
ax1.plot(2000*np.random.rand(10))
2019
ax1.set_title('ylabels not aligned')
2120
ax1.set_ylabel('misaligned 1', bbox=box)
2221
ax1.set_ylim(0, 2000)
23-
ax3 = fig.add_subplot(223)
22+
2423
ax3.set_ylabel('misaligned 2',bbox=box)
2524
ax3.plot(np.random.rand(10))
2625

27-
2826
labelx = -0.3 # axes coords
2927

30-
ax2 = fig.add_subplot(222)
3128
ax2.set_title('ylabels aligned')
3229
ax2.plot(2000*np.random.rand(10))
3330
ax2.set_ylabel('aligned 1', bbox=box)
3431
ax2.yaxis.set_label_coords(labelx, 0.5)
3532
ax2.set_ylim(0, 2000)
3633

37-
ax4 = fig.add_subplot(224)
3834
ax4.plot(np.random.rand(10))
3935
ax4.set_ylabel('aligned 2', bbox=box)
4036
ax4.yaxis.set_label_coords(labelx, 0.5)
4137

42-
4338
plt.show()

_downloads/anchored_artists.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from matplotlib.patches import Rectangle, Ellipse\n\nfrom matplotlib.offsetbox import AnchoredOffsetbox, AuxTransformBox, VPacker,\\\n TextArea, DrawingArea\n\n\nclass AnchoredText(AnchoredOffsetbox):\n def __init__(self, s, loc, pad=0.4, borderpad=0.5,\n prop=None, frameon=True):\n\n self.txt = TextArea(s,\n minimumdescent=False)\n\n super(AnchoredText, self).__init__(loc, pad=pad, borderpad=borderpad,\n child=self.txt,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredSizeBar(AnchoredOffsetbox):\n def __init__(self, transform, size, label, loc,\n pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):\n \"\"\"\n Draw a horizontal bar with the size in data coordinate of the given\n axes. A label will be drawn underneath (center-aligned).\n\n pad, borderpad in fraction of the legend font size (or prop)\n sep in points.\n \"\"\"\n self.size_bar = AuxTransformBox(transform)\n self.size_bar.add_artist(Rectangle((0, 0), size, 0, fc=\"none\", lw=1.0))\n\n self.txt_label = TextArea(label, minimumdescent=False)\n\n self._box = VPacker(children=[self.size_bar, self.txt_label],\n align=\"center\",\n pad=0, sep=sep)\n\n AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,\n child=self._box,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredEllipse(AnchoredOffsetbox):\n def __init__(self, transform, width, height, angle, loc,\n pad=0.1, borderpad=0.1, prop=None, frameon=True):\n \"\"\"\n Draw an ellipse the size in data coordinate of the give axes.\n\n pad, borderpad in fraction of the legend font size (or prop)\n \"\"\"\n self._box = AuxTransformBox(transform)\n self.ellipse = Ellipse((0, 0), width, height, angle)\n self._box.add_artist(self.ellipse)\n\n AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,\n child=self._box,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredDrawingArea(AnchoredOffsetbox):\n def __init__(self, width, height, xdescent, ydescent,\n loc, pad=0.4, borderpad=0.5, prop=None, frameon=True):\n\n self.da = DrawingArea(width, height, xdescent, ydescent)\n\n super(AnchoredDrawingArea, self).__init__(loc, pad=pad,\n borderpad=borderpad,\n child=self.da,\n prop=None,\n frameon=frameon)\n\n\nif __name__ == \"__main__\":\n\n import matplotlib.pyplot as plt\n\n ax = plt.gca()\n ax.set_aspect(1.)\n\n at = AnchoredText(\"Figure 1a\",\n loc=2, frameon=True)\n at.patch.set_boxstyle(\"round,pad=0.,rounding_size=0.2\")\n ax.add_artist(at)\n\n from matplotlib.patches import Circle\n ada = AnchoredDrawingArea(20, 20, 0, 0,\n loc=1, pad=0., frameon=False)\n p = Circle((10, 10), 10)\n ada.da.add_artist(p)\n ax.add_artist(ada)\n\n # draw an ellipse of width=0.1, height=0.15 in the data coordinate\n ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0.,\n loc=3, pad=0.5, borderpad=0.4, frameon=True)\n\n ax.add_artist(ae)\n\n # draw a horizontal bar with length of 0.1 in Data coordinate\n # (ax.transData) with a label underneath.\n asb = AnchoredSizeBar(ax.transData,\n 0.1,\n r\"1$^{\\prime}$\",\n loc=8,\n pad=0.1, borderpad=0.5, sep=5,\n frameon=False)\n ax.add_artist(asb)\n\n plt.draw()\n plt.show()"
29+
"from matplotlib.patches import Rectangle, Ellipse\n\nfrom matplotlib.offsetbox import AnchoredOffsetbox, AuxTransformBox, VPacker,\\\n TextArea, DrawingArea\n\n\nclass AnchoredText(AnchoredOffsetbox):\n def __init__(self, s, loc, pad=0.4, borderpad=0.5,\n prop=None, frameon=True):\n\n self.txt = TextArea(s,\n minimumdescent=False)\n\n super(AnchoredText, self).__init__(loc, pad=pad, borderpad=borderpad,\n child=self.txt,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredSizeBar(AnchoredOffsetbox):\n def __init__(self, transform, size, label, loc,\n pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True):\n \"\"\"\n Draw a horizontal bar with the size in data coordinate of the given\n axes. A label will be drawn underneath (center-aligned).\n\n pad, borderpad in fraction of the legend font size (or prop)\n sep in points.\n \"\"\"\n self.size_bar = AuxTransformBox(transform)\n self.size_bar.add_artist(Rectangle((0, 0), size, 0, ec=\"black\", lw=1.0))\n\n self.txt_label = TextArea(label, minimumdescent=False)\n\n self._box = VPacker(children=[self.size_bar, self.txt_label],\n align=\"center\",\n pad=0, sep=sep)\n\n AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,\n child=self._box,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredEllipse(AnchoredOffsetbox):\n def __init__(self, transform, width, height, angle, loc,\n pad=0.1, borderpad=0.1, prop=None, frameon=True):\n \"\"\"\n Draw an ellipse the size in data coordinate of the give axes.\n\n pad, borderpad in fraction of the legend font size (or prop)\n \"\"\"\n self._box = AuxTransformBox(transform)\n self.ellipse = Ellipse((0, 0), width, height, angle)\n self._box.add_artist(self.ellipse)\n\n AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad,\n child=self._box,\n prop=prop,\n frameon=frameon)\n\n\nclass AnchoredDrawingArea(AnchoredOffsetbox):\n def __init__(self, width, height, xdescent, ydescent,\n loc, pad=0.4, borderpad=0.5, prop=None, frameon=True):\n\n self.da = DrawingArea(width, height, xdescent, ydescent)\n\n super(AnchoredDrawingArea, self).__init__(loc, pad=pad,\n borderpad=borderpad,\n child=self.da,\n prop=None,\n frameon=frameon)\n\n\nif __name__ == \"__main__\":\n\n import matplotlib.pyplot as plt\n\n ax = plt.gca()\n ax.set_aspect(1.)\n\n at = AnchoredText(\"Figure 1a\",\n loc=2, frameon=True)\n at.patch.set_boxstyle(\"round,pad=0.,rounding_size=0.2\")\n ax.add_artist(at)\n\n from matplotlib.patches import Circle\n ada = AnchoredDrawingArea(20, 20, 0, 0,\n loc=1, pad=0., frameon=False)\n p = Circle((10, 10), 10)\n ada.da.add_artist(p)\n ax.add_artist(ada)\n\n # draw an ellipse of width=0.1, height=0.15 in the data coordinate\n ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0.,\n loc=3, pad=0.5, borderpad=0.4, frameon=True)\n\n ax.add_artist(ae)\n\n # draw a horizontal bar with length of 0.1 in Data coordinate\n # (ax.transData) with a label underneath.\n asb = AnchoredSizeBar(ax.transData,\n 0.1,\n r\"1$^{\\prime}$\",\n loc=8,\n pad=0.1, borderpad=0.5, sep=5,\n frameon=False)\n ax.add_artist(asb)\n\n plt.draw()\n plt.show()"
3030
]
3131
}
3232
],

_downloads/anchored_artists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, transform, size, label, loc,
3434
sep in points.
3535
"""
3636
self.size_bar = AuxTransformBox(transform)
37-
self.size_bar.add_artist(Rectangle((0, 0), size, 0, fc="none", lw=1.0))
37+
self.size_bar.add_artist(Rectangle((0, 0), size, 0, ec="black", lw=1.0))
3838

3939
self.txt_label = TextArea(label, minimumdescent=False)
4040

_downloads/animate_decay.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# Decay\n\n\nA sinusoidal decay animation.\n\n"
18+
"\n# Decay\n\n\nThis example showcases:\n- using a generator to drive an animation,\n- changing axes limits during an animation.\n\n"
1919
]
2020
},
2121
{

_downloads/animate_decay.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
Decay
44
=====
55
6-
A sinusoidal decay animation.
6+
This example showcases:
7+
- using a generator to drive an animation,
8+
- changing axes limits during an animation.
79
"""
810

9-
1011
import numpy as np
1112
import matplotlib.pyplot as plt
1213
import matplotlib.animation as animation

0 commit comments

Comments
 (0)