Skip to content

2.0 Examples fixes. See #6762 #6786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/axisartist/demo_curvelinear_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def inv_tr(x, y):
fig.add_subplot(ax1)

xx, yy = tr([3, 6], [5.0, 10.])
ax1.plot(xx, yy)
ax1.plot(xx, yy, linewidth=2.0)

ax1.set_aspect(1.)
ax1.set_xlim(0, 10.)
ax1.set_ylim(0, 10.)

ax1.axis["t"] = ax1.new_floating_axis(0, 3.)
ax1.axis["t2"] = ax1.new_floating_axis(1, 7.)
ax1.grid(True)
ax1.grid(True, zorder=0)


import mpl_toolkits.axisartist.angle_helper as angle_helper
Expand Down Expand Up @@ -107,13 +107,14 @@ def curvelinear_test2(fig):
ax1.parasites.append(ax2)
intp = cbook.simple_linear_interpolation
ax2.plot(intp(np.array([0, 30]), 50),
intp(np.array([10., 10.]), 50))
intp(np.array([10., 10.]), 50),
linewidth=2.0)

ax1.set_aspect(1.)
ax1.set_xlim(-5, 12)
ax1.set_ylim(-5, 10)

ax1.grid(True)
ax1.grid(True, zorder=0)

if 1:
fig = plt.figure(1, figsize=(7, 4))
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/keypress_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def press(event):

ax.plot(np.random.rand(12), np.random.rand(12), 'go')
xl = ax.set_xlabel('easy come, easy go')

ax.set_title('Press a key')
plt.show()
3 changes: 2 additions & 1 deletion examples/event_handling/lasso_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def onpress(self, event):
if __name__ == '__main__':

data = [Datum(*xy) for xy in rand(100, 2)]

ax = plt.axes(xlim=(0, 1), ylim=(0, 1), autoscale_on=False)
ax.set_title('Lasso points using left mouse button')

lman = LassoManager(ax, data)

plt.show()
1 change: 1 addition & 0 deletions examples/event_handling/looking_glass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

ax.plot(x, y, alpha=0.2)
line, = ax.plot(x, y, alpha=1.0, clip_path=circ)
ax.set_title("Left click and drag to move looking glass")


class EventHandler(object):
Expand Down
20 changes: 8 additions & 12 deletions examples/event_handling/resample.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import numpy as np
import matplotlib.pyplot as plt
from scikits.audiolab import wavread


# A class that will downsample the data and recompute when zoomed.
class DataDisplayDownsampler(object):
def __init__(self, xdata, ydata):
self.origYData = ydata
self.origXData = xdata
self.numpts = 3000
self.ratio = 5
self.delta = xdata[-1] - xdata[0]

def resample(self, xstart, xend):
def downsample(self, xstart, xend):
# Very simple downsampling that takes the points within the range
# and picks every Nth point
mask = (self.origXData > xstart) & (self.origXData < xend)
xdata = self.origXData[mask]
ratio = int(xdata.size / self.numpts) + 1
xdata = xdata[::ratio]
xdata = xdata[::self.ratio]

ydata = self.origYData[mask]
ydata = ydata[::ratio]
ydata = ydata[::self.ratio]

return xdata, ydata

Expand All @@ -33,18 +31,16 @@ def update(self, ax):
self.line.set_data(*self.downsample(xstart, xend))
ax.figure.canvas.draw_idle()

# Read data
data = wavread('/usr/share/sounds/purple/receive.wav')[0]
ydata = np.tile(data[:, 0], 100)
xdata = np.arange(ydata.size)
# Create a signal
xdata = np.linspace(16, 365, 365-16)
ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127)

d = DataDisplayDownsampler(xdata, ydata)

fig, ax = plt.subplots()

# Hook up the line
xdata, ydata = d.downsample(xdata[0], xdata[-1])
d.line, = ax.plot(xdata, ydata)
d.line, = ax.plot(xdata, ydata, 'o-')
ax.set_autoscale_on(False) # Otherwise, infinite loop

# Connect for changing the view limits
Expand Down
2 changes: 1 addition & 1 deletion examples/event_handling/trifinder_event_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def update_polygon(tri):
points = triangulation.triangles[tri]
xs = triangulation.x[points]
ys = triangulation.y[points]
polygon.set_xy(zip(xs, ys))
polygon.set_xy(list(zip(xs, ys)))


def motion_notify(event):
Expand Down
3 changes: 2 additions & 1 deletion examples/event_handling/viewlims.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def ax_update(self, ax):
ax1.imshow(Z, origin='lower', extent=(md.x.min(), md.x.max(), md.y.min(), md.y.max()))
ax2.imshow(Z, origin='lower', extent=(md.x.min(), md.x.max(), md.y.min(), md.y.max()))

rect = UpdatingRect([0, 0], 0, 0, facecolor='None', edgecolor='black')
rect = UpdatingRect([0, 0], 0, 0, facecolor='None', edgecolor='black', linewidth=1.0)
rect.set_bounds(*ax2.viewLim.bounds)
ax1.add_patch(rect)

Expand All @@ -74,5 +74,6 @@ def ax_update(self, ax):

ax2.callbacks.connect('xlim_changed', md.ax_update)
ax2.callbacks.connect('ylim_changed', md.ax_update)
ax2.set_title("Zoom here")

plt.show()