Skip to content

Commit 6d87b5f

Browse files
committed
ENH: expose the gallery in the statistics and matplotlib chapters
1 parent ca2b03e commit 6d87b5f

28 files changed

+214
-791
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
Examples for the Matplotlib chapter
2-
===================================
1+
2+
3+
Code samples for Matplotlib
4+
----------------------------
5+
6+
37

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,31 @@
11
"""
2-
Bar plot advanced
3-
==================
2+
Bar plots
3+
==========
44
5-
An more elaborate bar plot example
5+
An example of bar plots with matplotlib.
66
"""
77

88
import numpy as np
99
import matplotlib.pyplot as plt
1010

11-
n = 16
11+
n = 12
1212
X = np.arange(n)
1313
Y1 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)
1414
Y2 = (1 - X / float(n)) * np.random.uniform(0.5, 1.0, n)
15-
plt.bar(X, Y1, facecolor='#9999ff', edgecolor='white')
15+
16+
plt.axes([0.025, 0.025, 0.95, 0.95])
17+
plt.bar(X, +Y1, facecolor='#9999ff', edgecolor='white')
1618
plt.bar(X, -Y2, facecolor='#ff9999', edgecolor='white')
19+
20+
for x, y in zip(X, Y1):
21+
plt.text(x + 0.4, y + 0.05, '%.2f' % y, ha='center', va= 'bottom')
22+
23+
for x, y in zip(X, Y2):
24+
plt.text(x + 0.4, -y - 0.05, '%.2f' % y, ha='center', va= 'top')
25+
1726
plt.xlim(-.5, n)
1827
plt.xticks(())
19-
plt.ylim(-1, 1)
28+
plt.ylim(-1.25, 1.25)
2029
plt.yticks(())
2130

22-
23-
# Add a title and a box around it
24-
from matplotlib.patches import FancyBboxPatch
25-
ax = plt.gca()
26-
ax.add_patch(FancyBboxPatch((-0.05, .87),
27-
width=.66, height=.165, clip_on=False,
28-
boxstyle="square,pad=0", zorder=3,
29-
facecolor='white', alpha=1.0,
30-
transform=plt.gca().transAxes))
31-
32-
plt.text(-0.05, 1.02, " Bar Plot: plt.bar(...)\n",
33-
horizontalalignment='left',
34-
verticalalignment='top',
35-
size='xx-large',
36-
transform=plt.gca().transAxes)
37-
38-
plt.text(-0.05, 1.01, "\n\n Make a bar plot with rectangles ",
39-
horizontalalignment='left',
40-
verticalalignment='top',
41-
size='large',
42-
transform=plt.gca().transAxes)
43-
4431
plt.show()

intro/matplotlib/examples/plot_bar_ex.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

intro/matplotlib/examples/plot_boxplot.py

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,28 @@
11
"""
2-
Display the contours of a function
3-
===================================
4-
5-
An example demoing how to plot the contours of a function, with
6-
additional layout tweeks.
2+
Displaying the contours of a function
3+
======================================
74
5+
An example showing how to display the contours of a function with
6+
matplotlib.
87
"""
98

109
import numpy as np
1110
import matplotlib.pyplot as plt
1211

1312
def f(x,y):
14-
return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)
13+
return (1 - x / 2 + x**5 + y**3) * np.exp(-x**2 -y**2)
1514

1615
n = 256
1716
x = np.linspace(-3, 3, n)
1817
y = np.linspace(-3, 3, n)
19-
X, Y = np.meshgrid(x, y)
18+
X,Y = np.meshgrid(x, y)
19+
20+
plt.axes([0.025, 0.025, 0.95, 0.95])
2021

2122
plt.contourf(X, Y, f(X, Y), 8, alpha=.75, cmap=plt.cm.hot)
22-
C = plt.contour(X, Y, f(X,Y), 8, colors='black', linewidth=.5)
23+
C = plt.contour(X, Y, f(X, Y), 8, colors='black', linewidth=.5)
2324
plt.clabel(C, inline=1, fontsize=10)
25+
2426
plt.xticks(())
2527
plt.yticks(())
26-
27-
28-
# Add a title and a box around it
29-
from matplotlib.patches import FancyBboxPatch
30-
ax = plt.gca()
31-
ax.add_patch(FancyBboxPatch((-0.05, .87),
32-
width=.66, height=.165, clip_on=False,
33-
boxstyle="square,pad=0", zorder=3,
34-
facecolor='white', alpha=1.0,
35-
transform=plt.gca().transAxes))
36-
37-
plt.text(-0.05, 1.02, " Contour Plot: plt.contour(..)\n",
38-
horizontalalignment='left',
39-
verticalalignment='top',
40-
size='xx-large',
41-
transform=plt.gca().transAxes)
42-
43-
plt.text(-0.05, 1.01, "\n\n Draw contour lines and filled contours ",
44-
horizontalalignment='left',
45-
verticalalignment='top',
46-
size='large',
47-
transform=plt.gca().transAxes)
48-
4928
plt.show()

intro/matplotlib/examples/plot_contour_ex.py

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,25 @@
11
"""
2-
Grid elaborate
3-
===============
2+
Grid
3+
====
44
5-
An example displaying a grid on the axes and tweaking the layout.
5+
Displaying a grid on the axes in matploblib.
66
"""
77

88
import matplotlib.pyplot as plt
9-
from matplotlib.ticker import MultipleLocator
10-
11-
fig = plt.figure(figsize=(8, 6), dpi=72, facecolor="white")
12-
axes = plt.subplot(111)
13-
axes.set_xlim(0, 4)
14-
axes.set_ylim(0, 3)
15-
16-
axes.xaxis.set_major_locator(MultipleLocator(1.0))
17-
axes.xaxis.set_minor_locator(MultipleLocator(0.1))
18-
axes.yaxis.set_major_locator(MultipleLocator(1.0))
19-
axes.yaxis.set_minor_locator(MultipleLocator(0.1))
20-
axes.grid(which='major', axis='x', linewidth=0.75, linestyle='-', color='0.75')
21-
axes.grid(which='minor', axis='x', linewidth=0.25, linestyle='-', color='0.75')
22-
axes.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.75')
23-
axes.grid(which='minor', axis='y', linewidth=0.25, linestyle='-', color='0.75')
24-
axes.set_xticklabels([])
25-
axes.set_yticklabels([])
26-
27-
28-
# Add a title and a box around it
29-
from matplotlib.patches import FancyBboxPatch
30-
ax = plt.gca()
31-
ax.add_patch(FancyBboxPatch((-0.05, .87),
32-
width=.66, height=.165, clip_on=False,
33-
boxstyle="square,pad=0", zorder=3,
34-
facecolor='white', alpha=1.0,
35-
transform=plt.gca().transAxes))
36-
37-
plt.text(-0.05, 1.02, " Grid: plt.grid(...)\n",
38-
horizontalalignment='left',
39-
verticalalignment='top',
40-
size='xx-large',
41-
transform=axes.transAxes)
42-
43-
plt.text(-0.05, 1.01, "\n\n Draw ticks and grid ",
44-
horizontalalignment='left',
45-
verticalalignment='top',
46-
size='large',
47-
transform=axes.transAxes)
489

10+
ax = plt.axes([0.025, 0.025, 0.95, 0.95])
11+
12+
ax.set_xlim(0,4)
13+
ax.set_ylim(0,3)
14+
ax.xaxis.set_major_locator(plt.MultipleLocator(1.0))
15+
ax.xaxis.set_minor_locator(plt.MultipleLocator(0.1))
16+
ax.yaxis.set_major_locator(plt.MultipleLocator(1.0))
17+
ax.yaxis.set_minor_locator(plt.MultipleLocator(0.1))
18+
ax.grid(which='major', axis='x', linewidth=0.75, linestyle='-', color='0.75')
19+
ax.grid(which='minor', axis='x', linewidth=0.25, linestyle='-', color='0.75')
20+
ax.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.75')
21+
ax.grid(which='minor', axis='y', linewidth=0.25, linestyle='-', color='0.75')
22+
ax.set_xticklabels([])
23+
ax.set_yticklabels([])
24+
25+
plt.show()

intro/matplotlib/examples/plot_grid_ex.py

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,26 @@
11
"""
2-
Imshow demo
3-
============
2+
Imshow elaborate
3+
=================
44
5-
Demoing imshow
5+
An example demoing imshow and styling the figure.
66
"""
77

88
import numpy as np
99
import matplotlib.pyplot as plt
1010

1111
def f(x, y):
12-
return (1 - x / 2 + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)
12+
return (1 - x / 2 + x ** 5 + y ** 3 ) * np.exp(-x ** 2 - y ** 2)
1313

1414
n = 10
15-
x = np.linspace(-3, 3, 8 * n)
16-
y = np.linspace(-3, 3, 6 * n)
15+
x = np.linspace(-3, 3, 3.5 * n)
16+
y = np.linspace(-3, 3, 3.0 * n)
1717
X, Y = np.meshgrid(x, y)
1818
Z = f(X, Y)
19+
20+
plt.axes([0.025, 0.025, 0.95, 0.95])
1921
plt.imshow(Z, interpolation='nearest', cmap='bone', origin='lower')
22+
plt.colorbar(shrink=.92)
23+
2024
plt.xticks(())
2125
plt.yticks(())
22-
23-
24-
# Add a title and a box around it
25-
from matplotlib.patches import FancyBboxPatch
26-
ax = plt.gca()
27-
ax.add_patch(FancyBboxPatch((-0.05, .87),
28-
width=.66, height=.165, clip_on=False,
29-
boxstyle="square,pad=0", zorder=3,
30-
facecolor='white', alpha=1.0,
31-
transform=plt.gca().transAxes))
32-
33-
plt.text(-0.05, 1.02, " Imshow: plt.imshow(...)\n",
34-
horizontalalignment='left',
35-
verticalalignment='top',
36-
size='xx-large',
37-
transform=plt.gca().transAxes)
38-
39-
plt.text(-0.05, 1.01, "\n\n Display an image to current axes ",
40-
horizontalalignment='left',
41-
verticalalignment='top',
42-
family='Lint McCree Intl BB',
43-
size='large',
44-
transform=plt.gca().transAxes)
45-
4626
plt.show()

0 commit comments

Comments
 (0)