Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pep8ify examples/ part 3#3183

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
twmr wants to merge4 commits intomatplotlib:masterfromtwmr:pep8examplesapiv3
Closed
Show file tree
Hide file tree
Changes fromall 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
4 changes: 2 additions & 2 deletionsexamples/animation/double_pendulum_animated.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,8 +22,8 @@ def derivs(state, t):
del_ = state[2] - state[0]
den1 = (M1 + M2) * L1 - M2 * L1 * cos(del_) * cos(del_)
dydx[1] = (M2 * L1 * state[1] * state[1] * sin(del_) * cos(del_)
+ M2 * G * sin(state[2]) * cos(del_) + M2 *
L2 * state[3] * state[3] * sin(del_)
+ M2 * G * sin(state[2]) * cos(del_)
+ M2 *L2 * state[3] * state[3] * sin(del_)
- (M1 + M2) * G * sin(state[0])) / den1

dydx[2] = state[3]
Expand Down
1 change: 1 addition & 0 deletionsexamples/event_handling/close_event.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import matplotlib.pyplot as plt


def handle_close(evt):
print('Closed Figure!')

Expand Down
53 changes: 30 additions & 23 deletionsexamples/event_handling/data_browser.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,13 @@


class PointBrowser:

"""
Click on a point to select and highlight it -- the data that
generated the point will be shown in the lower axes. Use the 'n'
and 'p' keys to browse through the next and previous points
"""

def __init__(self):
self.lastind = 0

Expand All@@ -16,50 +18,56 @@ def __init__(self):
color='yellow', visible=False)

def onpress(self, event):
if self.lastind is None: return
if event.key not in ('n', 'p'): return
if event.key=='n': inc = 1
else: inc = -1

if self.lastind is None:
return
if event.key not in ('n', 'p'):
return
if event.key == 'n':
inc = 1
else:
inc = -1

self.lastind += inc
self.lastind = np.clip(self.lastind, 0, len(xs)-1)
self.lastind = np.clip(self.lastind, 0, len(xs) -1)
self.update()

def onpick(self, event):

if event.artist!=line: return True
if event.artist != line:
return True

N = len(event.ind)
if not N: return True
N = len(event.ind)
if not N:
return True

# the click locations
x = event.mouseevent.xdata
y = event.mouseevent.ydata
# the click locations
x = event.mouseevent.xdata
y = event.mouseevent.ydata

distances = np.hypot(x - xs[event.ind], y - ys[event.ind])
indmin = distances.argmin()
dataind = event.ind[indmin]

distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
indmin = distances.argmin()
dataind = event.ind[indmin]

self.lastind = dataind
self.update()
self.lastind = dataind
self.update()

def update(self):
if self.lastind is None: return
if self.lastind is None:
return

dataind = self.lastind

ax2.cla()
ax2.plot(X[dataind])

ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]),
transform=ax2.transAxes, va='top')
ax2.text(
0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
transform=ax2.transAxes, va='top')
ax2.set_ylim(-0.5, 1.5)
self.selected.set_visible(True)
self.selected.set_data(xs[dataind], ys[dataind])

self.text.set_text('selected: %d'%dataind)
self.text.set_text('selected: %d' %dataind)
fig.canvas.draw()


Expand All@@ -80,4 +88,3 @@ def update(self):
fig.canvas.mpl_connect('key_press_event', browser.onpress)

plt.show()

6 changes: 4 additions & 2 deletionsexamples/event_handling/figure_axes_enter_leave.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,21 +5,25 @@
from __future__ import print_function
import matplotlib.pyplot as plt


def enter_axes(event):
print('enter_axes', event.inaxes)
event.inaxes.patch.set_facecolor('yellow')
event.canvas.draw()


def leave_axes(event):
print('leave_axes', event.inaxes)
event.inaxes.patch.set_facecolor('white')
event.canvas.draw()


def enter_figure(event):
print('enter_figure', event.canvas.figure)
event.canvas.figure.patch.set_facecolor('red')
event.canvas.draw()


def leave_figure(event):
print('leave_figure', event.canvas.figure)
event.canvas.figure.patch.set_facecolor('grey')
Expand All@@ -42,5 +46,3 @@ def leave_figure(event):
fig2.canvas.mpl_connect('axes_leave_event', leave_axes)

plt.show()


14 changes: 7 additions & 7 deletionsexamples/event_handling/idle_and_timeout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,19 +10,21 @@
fig, ax = plt.subplots()

t = np.arange(0.0, 2.0, 0.01)
y1 = np.sin(2*np.pi*t)
y2 = np.cos(2*np.pi*t)
y1 = np.sin(2 *np.pi *t)
y2 = np.cos(2 *np.pi *t)
line1, = ax.plot(y1)
line2, = ax.plot(y2)

N = 100


def on_idle(event):
on_idle.count +=1
on_idle.count +=1
print('idle', on_idle.count)
line1.set_ydata(np.sin(2*np.pi*t*(N-on_idle.count)/float(N)))
line1.set_ydata(np.sin(2 *np.pi * t * (N -on_idle.count) /float(N)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Excessive whitespace.

event.canvas.draw()
# test boolean return removal
if on_idle.count==N:
if on_idle.count ==N:
return False
return True
on_idle.cid = None
Expand All@@ -31,5 +33,3 @@ def on_idle(event):
fig.canvas.mpl_connect('idle_event', on_idle)

plt.show()


2 changes: 1 addition & 1 deletionexamples/event_handling/keypress_demo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,7 @@
def press(event):
print('press', event.key)
sys.stdout.flush()
if event.key=='x':
if event.key =='x':
visible = xl.get_visible()
xl.set_visible(not visible)
fig.canvas.draw()
Expand Down
20 changes: 14 additions & 6 deletionsexamples/event_handling/lasso_demo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,17 +15,22 @@
from numpy import nonzero
from numpy.random import rand


class Datum(object):
colorin = colorConverter.to_rgba('red')
colorout = colorConverter.to_rgba('blue')

def __init__(self, x, y, include=False):
self.x = x
self.y = y
if include: self.color = self.colorin
else: self.color = self.colorout
if include:
self.color = self.colorin
else:
self.color = self.colorout


class LassoManager(object):

def __init__(self, ax, data):
self.axes = ax
self.canvas = ax.figure.canvas
Expand DownExpand Up@@ -61,17 +66,20 @@ def callback(self, verts):
del self.lasso

def onpress(self, event):
if self.canvas.widgetlock.locked(): return
if event.inaxes is None: return
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
if self.canvas.widgetlock.locked():
return
if event.inaxes is None:
return
self.lasso = Lasso(
event.inaxes, (event.xdata, event.ydata), self.callback)
# acquire a lock on the widget drawing
self.canvas.widgetlock(self.lasso)

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 = plt.axes(xlim=(0,1), ylim=(0,1), autoscale_on=False)
lman = LassoManager(ax, data)

plt.show()
4 changes: 2 additions & 2 deletionsexamples/event_handling/legend_picking.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,8 +5,8 @@
import matplotlib.pyplot as plt

t = np.arange(0.0, 0.2, 0.1)
y1 = 2*np.sin(2*np.pi*t)
y2 = 4*np.sin(2*np.pi*2*t)
y1 = 2 *np.sin(2 *np.pi *t)
y2 = 4 *np.sin(2 *np.pi * 2 *t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Excessive whitespace.


fig, ax = plt.subplots()
ax.set_title('Click on legend line to toggle line on/off')
Expand Down
62 changes: 32 additions & 30 deletionsexamples/event_handling/looking_glass.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,43 +4,45 @@
x, y = np.random.rand(2, 200)

fig, ax = plt.subplots()
circ = patches.Circle((0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
circ = patches.Circle((0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
ax.add_patch(circ)


ax.plot(x, y, alpha=0.2)
line, = ax.plot(x, y, alpha=1.0, clip_path=circ)


class EventHandler:
def __init__(self):
fig.canvas.mpl_connect('button_press_event', self.onpress)
fig.canvas.mpl_connect('button_release_event', self.onrelease)
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
self.x0, self.y0 = circ.center
self.pressevent = None

def onpress(self, event):
if event.inaxes!=ax:
return

if not circ.contains(event)[0]:
return

self.pressevent = event

def onrelease(self, event):
self.pressevent = None
self.x0, self.y0 = circ.center

def onmove(self, event):
if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
return

dx = event.xdata - self.pressevent.xdata
dy = event.ydata - self.pressevent.ydata
circ.center = self.x0 + dx, self.y0 + dy
line.set_clip_path(circ)
fig.canvas.draw()

def __init__(self):
fig.canvas.mpl_connect('button_press_event', self.onpress)
fig.canvas.mpl_connect('button_release_event', self.onrelease)
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
self.x0, self.y0 = circ.center
self.pressevent = None

def onpress(self, event):
if event.inaxes != ax:
return

if not circ.contains(event)[0]:
return

self.pressevent = event

def onrelease(self, event):
self.pressevent = None
self.x0, self.y0 = circ.center

def onmove(self, event):
if self.pressevent is None or event.inaxes != self.pressevent.inaxes:
return

dx = event.xdata - self.pressevent.xdata
dy = event.ydata - self.pressevent.ydata
circ.center = self.x0 + dx, self.y0 + dy
line.set_clip_path(circ)
fig.canvas.draw()

handler = EventHandler()
plt.show()
Loading

[8]ページ先頭

©2009-2025 Movatter.jp