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 1 commit
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
Next Next commit
2.0 Examples fixes. See #6762
These are fixes for all issues found in axes_grid, color, and
event_handling sections on the examples page.

axis_grid/demo_colorbar_with_inset_locator.py - changed interpolation from the
default(previously bilinear now none) to 'bilinear' to match 1.5.1 example

axes_grid1/simple_axesgrid.py - set interpolation to bilinear

axisartist/demo_curvelinear_grid.py - Set linewidth=2.0 and grid zorder=0 so
the plotted lines actually visible

event_handling/keypress_demo.py - added usage instruction as axes title

event_handling/lasso_demo.py - added usage instruction as axes title

event_handling/looking_glass.py - added usage instruction as axes title

event_handling/resample.py - removed gtk and hardcoded wave file dependencies
and just created a sample signal within the script

event_handling/trifinder_event_demo.py - zip(l1,l2) call changed to
list(zip(l1,l2)) to be python3 compatible

event_handling/viewlims.py - The focus box that is supposed to appear in the
left axes when user zooms in the right axes wasn't visible. Set linewidth=1.0
  • Loading branch information
mlub committed Jul 17, 2016
commit 0e07fd2ba8605de1961123dd16e1831a2b21177e
4 changes: 2 additions & 2 deletions examples/axes_grid1/demo_colorbar_with_inset_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
height="5%", # height : 50%
loc=1)

im1 = ax1.imshow([[1, 2], [2, 3]])
im1 = ax1.imshow([[1, 2], [2, 3]], interpolation='bilinear')
plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
axins1.xaxis.set_ticks_position("bottom")

Expand All @@ -26,7 +26,7 @@
# of the legend. you may want to play with the borderpad value and
# the bbox_to_anchor coordinate.

im = ax2.imshow([[1, 2], [2, 3]])
im = ax2.imshow([[1, 2], [2, 3]], interpolation='bilinear')
plt.colorbar(im, cax=axins, ticks=[1, 2, 3])

plt.draw()
Expand Down
2 changes: 1 addition & 1 deletion examples/axes_grid1/simple_axesgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
)

for i in range(4):
grid[i].imshow(im) # The AxesGrid object work as a list of axes.
grid[i].imshow(im, interpolation='bilinear') # The AxesGrid object work as a list of axes.

plt.show()
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()
2 changes: 1 addition & 1 deletion examples/event_handling/looking_glass.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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):
def __init__(self):
Expand Down
22 changes: 10 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,21 +31,21 @@ 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
ax.callbacks.connect('xlim_changed', d.update)

plt.show()


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()