Skip to content

Commit aa60876

Browse files
committed
added 2.2.5 docs
1 parent 0eb098a commit aa60876

File tree

7,344 files changed

+1162483
-0
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,344 files changed

+1162483
-0
lines changed

2.2.5/Matplotlib.pdf

20.2 MB
Binary file not shown.
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# Axis Direction Demo Step01\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 mpl_toolkits.axisartist as axisartist\n\n\ndef setup_axes(fig, rect):\n ax = axisartist.Subplot(fig, rect)\n fig.add_axes(ax)\n\n ax.set_ylim(-0.1, 1.5)\n ax.set_yticks([0, 1])\n\n ax.axis[:].set_visible(False)\n\n ax.axis[\"x\"] = ax.new_floating_axis(1, 0.5)\n ax.axis[\"x\"].set_axisline_style(\"->\", size=1.5)\n\n return ax\n\n\nfig = plt.figure(figsize=(3, 2.5))\nfig.subplots_adjust(top=0.8)\nax1 = setup_axes(fig, \"111\")\n\nax1.axis[\"x\"].set_axis_direction(\"left\")\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.8.1"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
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# Simple Axesgrid2\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\nfrom mpl_toolkits.axes_grid1 import ImageGrid\n\n\ndef get_demo_image():\n import numpy as np\n from matplotlib.cbook import get_sample_data\n f = get_sample_data(\"axes_grid/bivariate_normal.npy\", asfileobj=False)\n z = np.load(f)\n # z is a numpy array of 15x15\n return z, (-3, 4, -4, 3)\n\nF = plt.figure(1, (5.5, 3.5))\ngrid = ImageGrid(F, 111, # similar to subplot(111)\n nrows_ncols=(1, 3),\n axes_pad=0.1,\n add_all=True,\n label_mode=\"L\",\n )\n\nZ, extent = get_demo_image() # demo image\n\nim1 = Z\nim2 = Z[:, :10]\nim3 = Z[:, 10:]\nvmin, vmax = Z.min(), Z.max()\nfor i, im in enumerate([im1, im2, im3]):\n ax = grid[i]\n ax.imshow(im, origin=\"lower\", vmin=vmin,\n vmax=vmax, interpolation=\"nearest\")\n\nplt.draw()\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.8.1"
50+
}
51+
},
52+
"nbformat": 4,
53+
"nbformat_minor": 0
54+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
=======================================
3+
Custom hillshading in a 3D surface plot
4+
=======================================
5+
6+
Demonstrates using custom hillshading in a 3D surface plot.
7+
"""
8+
9+
from mpl_toolkits.mplot3d import Axes3D
10+
from matplotlib import cbook
11+
from matplotlib import cm
12+
from matplotlib.colors import LightSource
13+
import matplotlib.pyplot as plt
14+
import numpy as np
15+
16+
# Load and format data
17+
filename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
18+
with np.load(filename) as dem:
19+
z = dem['elevation']
20+
nrows, ncols = z.shape
21+
x = np.linspace(dem['xmin'], dem['xmax'], ncols)
22+
y = np.linspace(dem['ymin'], dem['ymax'], nrows)
23+
x, y = np.meshgrid(x, y)
24+
25+
region = np.s_[5:50, 5:50]
26+
x, y, z = x[region], y[region], z[region]
27+
28+
# Set up plot
29+
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
30+
31+
ls = LightSource(270, 45)
32+
# To use a custom hillshading mode, override the built-in shading and pass
33+
# in the rgb colors of the shaded surface calculated from "shade".
34+
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
35+
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
36+
linewidth=0, antialiased=False, shade=False)
37+
38+
plt.show()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
=============
3+
QuadMesh Demo
4+
=============
5+
6+
`~.axes.Axes.pcolormesh` uses a `~matplotlib.collections.QuadMesh`,
7+
a faster generalization of `~.axes.Axes.pcolor`, but with some restrictions.
8+
9+
This demo illustrates a bug in quadmesh with masked data.
10+
"""
11+
12+
import copy
13+
14+
from matplotlib import cm, colors, pyplot as plt
15+
import numpy as np
16+
17+
n = 12
18+
x = np.linspace(-1.5, 1.5, n)
19+
y = np.linspace(-1.5, 1.5, n * 2)
20+
X, Y = np.meshgrid(x, y)
21+
Qx = np.cos(Y) - np.cos(X)
22+
Qz = np.sin(Y) + np.sin(X)
23+
Z = np.sqrt(X**2 + Y**2) / 5
24+
Z = (Z - Z.min()) / (Z.max() - Z.min())
25+
26+
# The color array can include masked values.
27+
Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
28+
29+
fig, axs = plt.subplots(nrows=1, ncols=3)
30+
axs[0].pcolormesh(Qx, Qz, Z, shading='gouraud')
31+
axs[0].set_title('Without masked values')
32+
33+
# You can control the color of the masked region. We copy the default colormap
34+
# before modifying it.
35+
cmap = copy.copy(cm.get_cmap(plt.rcParams['image.cmap']))
36+
cmap.set_bad('y', 1.0)
37+
axs[1].pcolormesh(Qx, Qz, Zm, shading='gouraud', cmap=cmap)
38+
axs[1].set_title('With masked values')
39+
40+
# Or use the default, which is transparent.
41+
axs[2].pcolormesh(Qx, Qz, Zm, shading='gouraud')
42+
axs[2].set_title('With masked values')
43+
44+
fig.tight_layout()
45+
plt.show()
46+
47+
#############################################################################
48+
#
49+
# ------------
50+
#
51+
# References
52+
# """"""""""
53+
#
54+
# The use of the following functions and methods is shown in this example:
55+
56+
import matplotlib
57+
matplotlib.axes.Axes.pcolormesh
58+
matplotlib.pyplot.pcolormesh
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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# Filling the area between lines\n\n\nThis example shows how to use ``fill_between`` to color between lines based on\nuser-defined logic.\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\n\nx = np.arange(0.0, 2, 0.01)\ny1 = np.sin(2 * np.pi * x)\ny2 = 1.2 * np.sin(4 * np.pi * x)"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": false
37+
},
38+
"outputs": [],
39+
"source": [
40+
"fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)\n\nax1.fill_between(x, 0, y1)\nax1.set_ylabel('between y1 and 0')\n\nax2.fill_between(x, y1, 1)\nax2.set_ylabel('between y1 and 1')\n\nax3.fill_between(x, y1, y2)\nax3.set_ylabel('between y1 and y2')\nax3.set_xlabel('x')"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"metadata": {},
46+
"source": [
47+
"Now fill between y1 and y2 where a logical condition is met. Note\nthis is different than calling\n``fill_between(x[where], y1[where], y2[where] ...)``\nbecause of edge effects over multiple contiguous regions.\n\n"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {
54+
"collapsed": false
55+
},
56+
"outputs": [],
57+
"source": [
58+
"fig, (ax, ax1) = plt.subplots(2, 1, sharex=True)\nax.plot(x, y1, x, y2, color='black')\nax.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True)\nax.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red', interpolate=True)\nax.set_title('fill between where')\n\n# Test support for masked arrays.\ny2 = np.ma.masked_greater(y2, 1.0)\nax1.plot(x, y1, x, y2, color='black')\nax1.fill_between(x, y1, y2, where=y2 >= y1,\n facecolor='green', interpolate=True)\nax1.fill_between(x, y1, y2, where=y2 <= y1,\n facecolor='red', interpolate=True)\nax1.set_title('Now regions with y2>1 are masked')"
59+
]
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {},
64+
"source": [
65+
"This example illustrates a problem; because of the data\ngridding, there are undesired unfilled triangles at the crossover\npoints. A brute-force solution would be to interpolate all\narrays to a very fine grid before plotting.\n\n"
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"Use transforms to create axes spans where a certain condition is satisfied:\n\n"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {
79+
"collapsed": false
80+
},
81+
"outputs": [],
82+
"source": [
83+
"fig, ax = plt.subplots()\ny = np.sin(4 * np.pi * x)\nax.plot(x, y, color='black')\n\n# use data coordinates for the x-axis and the axes coordinates for the y-axis\nimport matplotlib.transforms as mtransforms\ntrans = mtransforms.blended_transform_factory(ax.transData, ax.transAxes)\ntheta = 0.9\nax.axhline(theta, color='green', lw=2, alpha=0.5)\nax.axhline(-theta, color='red', lw=2, alpha=0.5)\nax.fill_between(x, 0, 1, where=y > theta,\n facecolor='green', alpha=0.5, transform=trans)\nax.fill_between(x, 0, 1, where=y < -theta,\n facecolor='red', alpha=0.5, transform=trans)\n\n\nplt.show()"
84+
]
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.8.1"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 0
108+
}

0 commit comments

Comments
 (0)