本文整理汇总了Python中matplotlib.widgets.Slider.slidermax方法的典型用法代码示例。如果您正苦于以下问题:Python Slider.slidermax方法的具体用法?Python Slider.slidermax怎么用?Python Slider.slidermax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.widgets.Slider
的用法示例。
在下文中一共展示了Slider.slidermax方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createImagesc
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import slidermax [as 别名]
def createImagesc(img):
def press(event):
sys.stdout.flush()
if event.key == 'escape':
sys.exit(0)
elif event.key == ' ':
img_crop, currMin, currMax = update(event)
img8bit = cv2.convertScaleAbs(img_crop, alpha = 255.0 / (currMax - currMin), beta = - currMin * 255.0 / (currMax - currMin))
plt.imsave(os.path.join(currPath, 'converted.png'), img8bit, cmap = 'gray')
print 'saved'
img = np.sqrt(img)
img /= max(img.flatten())
minVal, maxVal, _, _ = cv2.minMaxLoc(img)
print 'Min [%f] - Max [%f]\n' % (minVal, maxVal)
fig_hist, ax_hist = plt.subplots()
fig_hist.canvas.mpl_connect('key_press_event', press)
plt.subplots_adjust(0.1, 0.05, 1.0, 0.98)
im_hist = plt.hist(img.flatten(), 50, histtype = 'stepfilled', normed = True)
fig, ax = plt.subplots()
fig.canvas.mpl_connect('key_press_event', press)
plt.subplots_adjust(0.15, 0.1, 0.9, 0.98)
plt.xticks([]), plt.yticks([])
im = plt.imshow(img)
im.set_clim(minVal, maxVal)
axcolor = 'lightgoldenrodyellow'
BAR_HEIGHT = 0.03
axmin = plt.axes([0.2, 0.2 * BAR_HEIGHT, 0.7, BAR_HEIGHT], axisbg = axcolor)
axmax = plt.axes([0.2, BAR_HEIGHT + 0.4 * BAR_HEIGHT, 0.7, BAR_HEIGHT], axisbg = axcolor)
smin = Slider(axmin, 'Min', minVal, maxVal, valinit = minVal)
smax = Slider(axmax, 'Max', minVal, maxVal, valinit = maxVal)
smin.slidermax = smax
smax.slidermin = smin
def update(event):
currMin = smin.val
currMax = smax.val
img_crop = img.copy()
img_crop[img_crop > currMax] = 1.0
img_crop[img_crop < currMin] = 0.0
print 'Min [%f] - Max [%f]' % (currMin, currMax)
im.set_data(img_crop)
im.set_clim(min(currMin, currMax), max(currMin, currMax))
plt.figure(fig.number)
fig.canvas.draw()
plt.figure(fig_hist.number)
ax_hist.cla()
ax_hist.hist(img_crop.flatten(), 50, histtype = 'stepfilled', normed = True)
fig_hist.canvas.draw()
return img_crop, currMin, currMax
smin.on_changed(update)
smax.on_changed(update)
invertax = plt.axes([0.02, 0.2 * BAR_HEIGHT, 0.1, (2.2) * BAR_HEIGHT])
button = Button(invertax, 'Invert', color=axcolor, hovercolor='0.975')
def invert(event):
invertColorMap(im)
fig.canvas.draw()
button.on_clicked(invert)
rax = plt.axes([0.02, (2.4) * BAR_HEIGHT, 0.1, 0.1], axisbg=axcolor)
radio = RadioButtons(rax, ('jet', 'gray'), active=0)
def colorfunc(label):
im.set_cmap(label)
fig.canvas.draw()
radio.on_clicked(colorfunc)
plt.show()
示例2: trim_path
# 需要导入模块: from matplotlib.widgets import Slider [as 别名]
# 或者: from matplotlib.widgets.Slider import slidermax [as 别名]
def trim_path(path):
"""Trim Path
Provides simple interface in order to trim the given path to
a desired, trainable path.
Arguments:
path: The full path input/output numpy array.
Returns:
A trimmed path input/output numpy array.
"""
global __g_start_trim_index
global __g_end_trim_index
global __g_trim_ok
__g_start_trim_index = 0
__g_end_trim_index = len(path) - 1
fig = plt.figure(facecolor='white')
axis = fig.gca(projection='3d')
plt.subplots_adjust(bottom=0.2)
slider_start_axis = plt.axes([0.15, 0.06, 0.6, 0.03], axisbg='w')
slider_start = Slider(slider_start_axis, 'Start', valmin=0,
valmax=len(path), valfmt='%d', valinit=0, closedmax=False,
color='r')
def start_changed(val):
global __g_start_trim_index
global __g_end_trim_index
__g_start_trim_index = int(round(val))
display_path(
axis,
path[__g_start_trim_index:__g_end_trim_index],
dotted_paths=[path[:__g_start_trim_index], path[__g_end_trim_index:]],
title='Trim Path'
)
plt.draw()
return
slider_start.on_changed(start_changed)
slider_end_axis = plt.axes([0.15, 0.025, 0.6, 0.03], axisbg='w')
slider_end = Slider(slider_end_axis, 'End', valmin=0, valmax=len(path)-2,
valfmt='%d', valinit=len(path)-1, slidermin=slider_start,
closedmin=False, color='r')
slider_start.slidermax = slider_end
def end_changed(val):
global __g_start_trim_index
global __g_end_trim_index
__g_end_trim_index = int(round(val))
display_path(
axis,
path[__g_start_trim_index:__g_end_trim_index],
dotted_paths=[path[:__g_start_trim_index], path[__g_end_trim_index:]],
title='Trim Path'
)
plt.draw()
return
slider_end.on_changed(end_changed)
button_ok_axis = plt.axes([0.82, 0.02, 0.13, 0.08])
button_ok = Button(button_ok_axis, label='Trim', color='lightgrey')
def button_clicked(event):
global __g_trim_ok
__g_trim_ok = True
plt.close()
return
button_ok.on_clicked(button_clicked)
# Show the path initially
display_path(axis, path, title='Trim Path')
plt.show()
if __g_trim_ok:
path = path[__g_start_trim_index:__g_end_trim_index]
return path