Skip to content

Commit 30cdd23

Browse files
authored
Merge pull request #8860 from tacaswell/doc_yinleon_rebase
Doc yinleon rebase
2 parents 8e517d8 + 20b6309 commit 30cdd23

File tree

13 files changed

+103
-59
lines changed

13 files changed

+103
-59
lines changed

examples/axisartist/demo_axisline_style.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
2-
===================
3-
Demo Axisline Style
4-
===================
2+
================
3+
Axis line styles
4+
================
55
6+
This example shows some configurations for axis style.
67
"""
78

89
from mpl_toolkits.axisartist.axislines import SubplotZero
@@ -15,10 +16,14 @@
1516
fig.add_subplot(ax)
1617

1718
for direction in ["xzero", "yzero"]:
19+
# adds arrows at the ends of each axis
1820
ax.axis[direction].set_axisline_style("-|>")
21+
22+
# adds X and Y-axis from the origin
1923
ax.axis[direction].set_visible(True)
2024

2125
for direction in ["left", "right", "bottom", "top"]:
26+
# hides borders
2227
ax.axis[direction].set_visible(False)
2328

2429
x = np.linspace(-0.5, 1., 100)

examples/event_handling/poly_editor.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
===========
55
66
This is an example to show how to build cross-GUI applications using
7-
matplotlib event handling to interact with objects on the canvas
8-
7+
Matplotlib event handling to interact with objects on the canvas.
98
"""
109
import numpy as np
1110
from matplotlib.lines import Line2D
@@ -34,17 +33,19 @@ class PolygonInteractor(object):
3433

3534
def __init__(self, ax, poly):
3635
if poly.figure is None:
37-
raise RuntimeError('You must first add the polygon to a figure or canvas before defining the interactor')
36+
raise RuntimeError('You must first add the polygon to a figure '
37+
'or canvas before defining the interactor')
3838
self.ax = ax
3939
canvas = poly.figure.canvas
4040
self.poly = poly
4141

4242
x, y = zip(*self.poly.xy)
43-
self.line = Line2D(x, y, marker='o', markerfacecolor='r', animated=True)
43+
self.line = Line2D(x, y,
44+
marker='o', markerfacecolor='r',
45+
animated=True)
4446
self.ax.add_line(self.line)
45-
#self._update_line(poly)
4647

47-
cid = self.poly.add_callback(self.poly_changed)
48+
self.cid = self.poly.add_callback(self.poly_changed)
4849
self._ind = None # the active vert
4950

5051
canvas.mpl_connect('draw_event', self.draw_callback)
@@ -113,7 +114,9 @@ def key_press_callback(self, event):
113114
elif event.key == 'd':
114115
ind = self.get_ind_under_point(event)
115116
if ind is not None:
116-
self.poly.xy = [tup for i, tup in enumerate(self.poly.xy) if i != ind]
117+
self.poly.xy = [tup
118+
for i, tup in enumerate(self.poly.xy)
119+
if i != ind]
117120
self.line.set_data(zip(*self.poly.xy))
118121
elif event.key == 'i':
119122
xys = self.poly.get_transform().transform(self.poly.xy)
@@ -173,7 +176,6 @@ def motion_notify_callback(self, event):
173176
ax.add_patch(poly)
174177
p = PolygonInteractor(ax, poly)
175178

176-
#ax.add_line(p.line)
177179
ax.set_title('Click and drag a point to move it')
178180
ax.set_xlim((-2, 2))
179181
ax.set_ylim((-2, 2))

examples/event_handling/resample.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
"""
2-
========
3-
Resample
4-
========
2+
===============
3+
Resampling Data
4+
===============
55
6+
Downsampling lowers the sample rate or sample size of a signal. In
7+
this tutorial, the signal is downsampled when the plot is adjusted
8+
through dragging and zooming.
69
"""
10+
711
import numpy as np
812
import matplotlib.pyplot as plt
913

@@ -13,18 +17,28 @@ class DataDisplayDownsampler(object):
1317
def __init__(self, xdata, ydata):
1418
self.origYData = ydata
1519
self.origXData = xdata
16-
self.ratio = 5
20+
self.max_points = 50
1721
self.delta = xdata[-1] - xdata[0]
1822

1923
def downsample(self, xstart, xend):
20-
# Very simple downsampling that takes the points within the range
21-
# and picks every Nth point
24+
# get the points in the view range
2225
mask = (self.origXData > xstart) & (self.origXData < xend)
23-
xdata = self.origXData[mask]
24-
xdata = xdata[::self.ratio]
26+
# dilate the mask by one to catch the points just outside
27+
# of the view range to not truncate the line
28+
mask = np.convolve([1, 1], mask, mode='same').astype(bool)
29+
# sort out how many points to drop
30+
ratio = max(np.sum(mask) // self.max_points, 1)
2531

32+
# mask data
33+
xdata = self.origXData[mask]
2634
ydata = self.origYData[mask]
27-
ydata = ydata[::self.ratio]
35+
36+
# downsample data
37+
xdata = xdata[::ratio]
38+
ydata = ydata[::ratio]
39+
40+
print("using {} of {} visible points".format(
41+
len(ydata), np.sum(mask)))
2842

2943
return xdata, ydata
3044

@@ -37,8 +51,9 @@ def update(self, ax):
3751
self.line.set_data(*self.downsample(xstart, xend))
3852
ax.figure.canvas.draw_idle()
3953

54+
4055
# Create a signal
41-
xdata = np.linspace(16, 365, 365-16)
56+
xdata = np.linspace(16, 365, (365-16)*4)
4257
ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127)
4358

4459
d = DataDisplayDownsampler(xdata, ydata)
@@ -51,5 +66,5 @@ def update(self, ax):
5166

5267
# Connect for changing the view limits
5368
ax.callbacks.connect('xlim_changed', d.update)
54-
69+
ax.set_xlim(16, 365)
5570
plt.show()

examples/mplot3d/lines3d.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'''
2-
===================
3-
3D parametric curve
4-
===================
2+
================
3+
Parametric Curve
4+
================
55
6-
Demonstrating plotting a parametric curve in 3D.
6+
This example demonstrates plotting a parametric curve in 3D.
77
'''
88

99
import matplotlib as mpl

examples/mplot3d/lorenz_attractor.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'''
2-
====================
3-
The Lorenz Attractor
4-
====================
2+
================
3+
Lorenz Attractor
4+
================
55
6-
Plot of the Lorenz Attractor based on Edward Lorenz's 1963 "Deterministic
7-
Nonperiodic Flow" publication.
8-
http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2
6+
This is an example of plotting Edward Lorenz's 1963 `"Deterministic
7+
Nonperiodic Flow"
8+
<http://journals.ametsoc.org/doi/abs/10.1175/1520-0469%281963%29020%3C0130%3ADNF%3E2.0.CO%3B2>`_
9+
in a 3-dimensional space using mplot3d.
910
1011
Note: Because this is a simple non-linear ODE, it would be more easily
1112
done using SciPy's ode solver, but this approach depends only

examples/mplot3d/mixed_subplots.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
"""
2-
==================
3-
2D and 3D subplots
4-
==================
2+
=================================
3+
2D and 3D *Axes* in same *Figure*
4+
=================================
55
6-
Demonstrate the mixing of 2d and 3d subplots.
6+
This example shows a how to plot a 2D and 3D plot on the same figure.
77
"""
8-
98
from mpl_toolkits.mplot3d import Axes3D
109
import matplotlib.pyplot as plt
1110
import numpy as np

examples/mplot3d/offset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''
2-
===================
3-
Offset text display
4-
===================
2+
=========================
3+
Automatic Text Offsetting
4+
=========================
55
66
This example demonstrates mplot3d's offset text display.
77
As one rotates the 3D figure, the offsets should remain oriented the

examples/pylab_examples/bar_stacked.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
"""
2-
===========
3-
Bar Stacked
4-
===========
2+
=================
3+
Stacked Bar Graph
4+
=================
5+
6+
This is an example of creating a stacked bar plot with error bars
7+
using `~matplotlib.pyplot.bar`. Note the parameters *yerr* used for
8+
error bars, and *bottom* to stack the women's bars on top of the men's
9+
bars.
510
6-
A stacked bar plot with errorbars.
711
"""
12+
813
import numpy as np
914
import matplotlib.pyplot as plt
1015

examples/pylab_examples/dolphin.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
"""
2-
=======
3-
Dolphin
4-
=======
2+
========
3+
Dolphins
4+
========
5+
6+
This example shows how to draw, and manipulate shapes given vertices
7+
and nodes using the `Patches`, `Path` and `Transforms` classes.
58
69
"""
10+
711
import matplotlib.cm as cm
812
import matplotlib.pyplot as plt
913
from matplotlib.patches import Circle, PathPatch

examples/pylab_examples/fill_between_demo.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
2-
=================
3-
Fill Between Demo
4-
=================
2+
==============================
3+
Filling the area between lines
4+
==============================
55
6+
This example shows how to use `fill_between` to color between lines based on
7+
user-defined logic.
68
"""
9+
710
import matplotlib.pyplot as plt
811
import numpy as np
912

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy