本文整理汇总了Python中matplotlib.widgets.Slider.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Slider.reset方法的具体用法?Python Slider.reset怎么用?Python Slider.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.widgets.Slider
的用法示例。
在下文中一共展示了Slider.reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PhasePlaneInteractive
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import reset [as 别名]
class PhasePlaneInteractive(object):
"""
An interactive phase-plane plot generated from a TVB model object.
A TVB integrator object will be use for generating sample trajectories
-- not the phase-plane. This is mainly interesting for visualising
the effect of noise on a trajectory.
"""
def __init__(self, model, integrator):
self.log = get_logger(self.__class__.__module__)
self.model = model
self.integrator = integrator
#Make sure the model is fully configured...
self.model.configure()
self.model.update_derived_parameters()
def get_required_memory_size(self, **kwargs):
"""
Return the required memory to run this algorithm.
"""
# Don't know how much memory is needed.
return -1
def draw_phase_plane(self):
"""Generate the interactive phase-plane figure."""
self.log.debug("Plot started...")
model_name = self.model.__class__.__name__
msg = "Generating an interactive phase-plane plot for %s"
self.log.info(msg % model_name)
self.svx = self.model.state_variables[0] # x-axis: 1st state variable
self.svy = self.model.state_variables[1] # y-axis: 2nd state variable
self.mode = 0
self._set_state_vector()
#TODO: see how we can get the figure size from the UI to better 'fit' the encompassing div
self.ipp_fig = pylab.figure(figsize=(10, 8))
pylab.clf()
self.pp_ax = self.ipp_fig.add_axes([0.265, 0.2, 0.7, 0.75])
self.pp_splt = self.ipp_fig.add_subplot(212)
self.ipp_fig.subplots_adjust(left=0.265, bottom=0.02, right=0.75, top=0.3, wspace=0.1, hspace=None)
self.pp_splt.set_color_cycle(get_color(self.model.nvar))
self.pp_splt.plot(numpy.arange(TRAJ_STEPS + 1) * self.integrator.dt,
numpy.zeros((TRAJ_STEPS + 1, self.model.nvar)))
if hasattr(self.pp_splt, 'autoscale'):
self.pp_splt.autoscale(enable=True, axis='y', tight=True)
self.pp_splt.legend(self.model.state_variables)
#Selectors
self._add_state_variable_selector()
self._add_mode_selector()
#Sliders
self._add_axes_range_sliders()
self._add_state_variable_sliders()
if isinstance(self.integrator, integrators_module.IntegratorStochastic):
if self.integrator.noise.ntau > 0.0:
self.integrator.noise.configure_coloured(self.integrator.dt,
(1, self.model.nvar, 1, self.model.number_of_modes))
else:
self.integrator.noise.configure_white(self.integrator.dt,
(1, self.model.nvar, 1, self.model.number_of_modes))
self._add_noise_slider()
self._add_reset_noise_button()
self._add_reset_seed_button()
#Reset buttons
#self._add_reset_param_button()
self._add_reset_sv_button()
self._add_reset_axes_button()
#Calculate the phase plane
self._set_mesh_grid()
self._calc_phase_plane()
#Plot phase plane
self._plot_phase_plane()
# add mouse handler for trajectory clicking
self.ipp_fig.canvas.mpl_connect('button_press_event', self._click_trajectory)
self.ipp_fig.canvas.draw()
return dict(serverIp=config.SERVER_IP, serverPort=config.MPLH5_SERVER_PORT,
figureNumber=self.ipp_fig.number, showFullToolbar=False)
def _add_state_variable_selector(self):
"""
Generate radio selector buttons to set which state variable is
displayed on the x and y axis of the phase-plane plot.
"""
svx_ind = self.model.state_variables.index(self.svx)
#.........这里部分代码省略.........
示例2: AppForm
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import reset [as 别名]
#.........这里部分代码省略.........
# Initial image
# FIXME add null image
self.current_pixscale = .05
im = misc.imread('galaxy_images/im1.jpg')
self.obj = ImageObject(im, self.current_pixscale)
self.image_object = self.obj.current_image
# Initialize slider bars
self.imshow = self.image_axes.imshow(self.image_object, interpolation='nearest')
self.sample_axis = self.fig.add_axes([0.25, 0.1, 0.65, 0.03])
self.fov_axis = self.fig.add_axes([0.25, 0.15, 0.65, 0.03])
# self.sample_axis = self.fig.add_subplot(gs[1])
# self.fov_axis = self.fig.add_subplot(gs[2])
self.sample_slider = Slider(self.sample_axis, 'Sampling (arcsecs/pix)', self.current_pixscale, self.current_pixscale * 100., valinit = self.current_pixscale)
self.fov_slider = Slider(self.fov_axis, 'Field of View (arsecs)', .05, 3., valinit = .05)
def update(val):
self.obj.update_sampling(self.sample_slider.val)
self.imshow.set_data(self.obj.current_image)
self.canvas.draw()
self.sample_slider.on_changed(update)
self.canvas.draw()
def image_selection(self, image_name):
'''
Hacked together image selection.
Takes selection from the image_selection_menu widget
'''
if image_name == 'Galaxy Image 1':
im = misc.imread('galaxy_images/im1.jpg')
pixscale = .05
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Galaxy Image 2':
im = misc.imread('galaxy_images/im2.jpg')
pixscale = .05
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Galaxy Simulation 1':
im = misc.imread('galaxy_simulations/im1.jpg')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Jupiter Narrow Field Simulation':
im = misc.imread('jupiter_simulation/jupiter_zoomin.png')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Jupiter Wide Field Simulation':
im = misc.imread('jupiter_simulation/jupiter_zoomout.png')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Star Formation Simulation 1':
im = misc.imread('star_formation_simulation/im1.gif')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Star Formation Simulation 2':
im = misc.imread('star_formation_simulation/im2.gif')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Star Formation Simulation 3':
im = misc.imread('star_formation_simulation/im3.gif')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Star Formation Image 1':
im = misc.imread('star_formation_images/im1.jpg')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
if image_name == 'Star Formation Image 2':
im = misc.imread('star_formation_images/im2.gif')
pixscale = .1
self.obj = ImageObject(im, pixscale)
self.image_update()
def image_update(self):
'''
Helper function to image selection, resets image and sliders
'''
self.imshow.set_data(self.obj.current_image)
self.canvas.draw()
if self.obj.master_sampling != self.current_pixscale:
self.current_pixscale = self.obj.master_sampling
self.sample_axis.cla()
self.sample_slider = Slider(self.sample_axis, 'Sampling (arcsecs/pix)', self.current_pixscale, self.current_pixscale * 20., valinit = self.current_pixscale)
def update(val):
self.obj.update_sampling(self.sample_slider.val)
self.imshow.set_data(self.obj.current_image)
self.canvas.draw()
self.sample_slider.on_changed(update)
else:
self.sample_slider.reset()
示例3: Vorwaertsproblem
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import reset [as 别名]
class Vorwaertsproblem():
def __init__(self, l_e=10, l_r=3, h_m=30, h_b=90, phi_0=135, delta_phi=45, psi=90, show_legend=True):
self.l_e = l_e
self.l_r = l_r
self.h_m = h_m
self.h_b = h_b
self.phi = phi_0
self.delta_phi = delta_phi
self.psi = psi
self.show_legend = show_legend
def initUI(self):
self.fig, self.ax = plt.subplots()
self.fig.canvas.set_window_title('Numerik DGL 2 - Schattenprojektion')
self.fig.suptitle('Vorwaertsproblem')
plt.subplots_adjust(bottom=0.3)
plt.axis([0, 200, -100, 100])
plt.axis('equal')
axColor = 'lightgoldenrodyellow'
# Slider - Phi
axPhi = plt.axes([0.18, 0.2, 0.65, 0.03], axisbg=axColor)
self.sliderPhi = Slider(axPhi, 'Phi', 0, 360, valinit=self.phi, valfmt='%1d')
self.sliderPhi.on_changed(self.onUpdate)
# Slider - Delta Phi
axDeltaPhi = plt.axes([0.18, 0.15, 0.65, 0.03], axisbg=axColor)
self.sliderDeltaPhi = Slider(axDeltaPhi, 'Delta Phi', 5, 360, valinit=self.delta_phi, valfmt='%1d')
self.sliderDeltaPhi.on_changed(self.onUpdate)
# Slider - Psi
axPsi = plt.axes([0.18, 0.1, 0.65, 0.03], axisbg=axColor)
self.sliderPsi = Slider(axPsi, 'Psi', 0, 180, valinit=self.psi, valfmt='%1d')
self.sliderPsi.on_changed(self.onUpdate)
# Button - Previous
axPrev = plt.axes([0.18, 0.03, 0.1, 0.05])
self.buttonPrev = Button(axPrev, 'Previous')
self.buttonPrev.on_clicked(self.onPrevious)
# Button - Next
axNext = plt.axes([0.29, 0.03, 0.1, 0.05])
self.buttonNext = Button(axNext, 'Next')
self.buttonNext.on_clicked(self.onNext)
# Button - Reset
axReset = plt.axes([0.73, 0.03, 0.1, 0.05])
self.buttonReset = Button(axReset, 'Reset')
self.buttonReset.on_clicked(self.onReset)
self.onDraw()
def onPrevious(self, event):
self.phi -= self.delta_phi
self.phi = self.phi % 360
self.onDraw()
def onNext(self, event):
self.phi += self.delta_phi
self.phi = self.phi % 360
self.onDraw()
def onReset(self, event):
self.sliderPhi.reset()
self.sliderDeltaPhi.reset()
self.sliderPsi.reset()
self.onDraw()
def onUpdate(self, val):
self.phi = int(self.sliderPhi.val)
self.delta_phi = int(self.sliderDeltaPhi.val)
self.psi = int(self.sliderPsi.val)
self.onDraw()
self.fig.canvas.draw_idle()
def onDraw(self):
self.ax.cla() # clear the axes
self.ax.margins(x=.1, y=.1) # add margins
self.ax.autoscale(enable=False)
psi = np.radians(self.psi)
phi = np.radians(self.phi)
# Werte berechnen
h_r = vw.get_h_r(self.l_e, self.h_m, phi)
alpha = vw.get_alpha(self.l_e, phi, h_r)
beta = vw.get_beta(alpha, psi)
h = vw.get_h(psi, self.h_b, beta)
gamma = vw.get_gamma(self.l_r, h_r)
b_bottom = vw.get_b_bottom(h, beta, gamma)
b_top = vw.get_b_top(h, beta, gamma)
b = vw.get_b(h, beta, gamma)
# Abstand bis Drehteller vom Ursprung
point_phi_x, point_phi_y = self.plot_line(0, 0, np.radians(0), self.h_m, name="hm", color='k-')
self.ax.plot(self.h_m, 0, 'kx')
self.ax.text(self.h_m, -0.3, 'h_m')
# Untere Bodenlinie
point_psi_x, point_psi_y = self.plot_line(0, 0, np.radians(0), self.h_b, name="hb", color='k-')
self.ax.plot(self.h_b, 0, 'kx')
self.ax.text(self.h_b, -0.3, 'h_b')
# Drehteller
circlele = plt.Circle((point_phi_x, point_phi_y), self.l_e, color='k', linestyle='dashed', fill=False)
self.ax.add_artist(circlele)
# Winkelhalbierende
point_b_x, point_b_y = self.plot_line(0,0, alpha, h, name="h", color='g-')
# Winkelhalbierende bis Kreismittelpunkt
#.........这里部分代码省略.........
示例4: PlotFrame
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import reset [as 别名]
#.........这里部分代码省略.........
self.axes is the instance of MPL Axes, and is where it all happens
"""
self.panel = wx.Panel(self)
# Create the mpl Figure and FigCanvas objects.
# 3.5 x 5 inches, 100 dots-per-inch
#
self.dpi = 100
self.fig = Figure((3.5, 5.0), dpi=self.dpi)
self.canvas = FigCanvas(self.panel, wx.ID_ANY, self.fig)
# Since we have only one plot, we could use add_axes
# instead of add_subplot, but then the subplot
# configuration tool in the navigation toolbar wouldn't work.
self.axes = self.fig.add_subplot(111)
# (111) == (1,1,1) --> row 1, col 1, Figure 1)
# self.axes.set_title("View from: "+self.filename)
# Now create some sliders below the plot after making room
self.fig.subplots_adjust(left=0.1, bottom=0.20)
self.axtmin = self.fig.add_axes([0.2, 0.10, 0.5, 0.03])
self.axtmax = self.fig.add_axes([0.2, 0.05, 0.5, 0.03])
self.stmin = Slider(self.axtmin, 't_min:', 0.0, 1.0, valinit = 0.0)
self.stmax = Slider(self.axtmax, 't_max:', 0.0, 1.0, valinit = 1.0)
self.stmin.on_changed(self.update_trange)
self.stmax.on_changed(self.update_trange)
self.axbutton = self.fig.add_axes([0.8, 0.07, 0.1, 0.07])
self.reset_button = Button(self.axbutton, 'Reset')
self.reset_button.color = 'skyblue'
self.reset_button.hovercolor = 'lightblue'
self.reset_button.on_clicked(self.reset_trange)
# Create the navigation toolbar, tied to the canvas
self.toolbar = NavigationToolbar(self.canvas)
def update_trange(self, event):
self.t_min = self.stmin.val
self.t_max = self.stmax.val
# print(self.t_min, self.t_max)
def reset_trange(self, event):
self.stmin.reset()
self.stmax.reset()
def create_button_bar(self):
"""
create_button_bar makes a control panel bar with buttons and
toggles for
New Data - Play - STOP - Single Step - Forward/Back - Normal/Fast
It does not create a Panel container, but simply creates Button
objects with bindings, and adds them to a horizontal BoxSizer
self.button_bar_sizer. This is added to the PlotFrame vertical
BoxSizer, after the MPL canvas, during initialization of the frame.
"""
rewind_button = wx.Button(self.panel, -1, "New Data")
self.Bind(wx.EVT_BUTTON, self.OnRewind, rewind_button)