本文整理汇总了Python中guiqwt.plot.PlotManager.add_tool方法的典型用法代码示例。如果您正苦于以下问题:Python PlotManager.add_tool方法的具体用法?Python PlotManager.add_tool怎么用?Python PlotManager.add_tool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类guiqwt.plot.PlotManager
的用法示例。
在下文中一共展示了PlotManager.add_tool方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_plot
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
def configure_plot(self):
self.marker = add_marker(self.plot)
self.line = MeasurementLine()
self.line.setVisible(0)
self.label = make_label(self.marker, self.line)
setupCommonStyle(self.line, self.marker)
manager = PlotManager(self.widget)
manager.add_plot(self.plot)
tool = manager.add_tool(MzSelectionTool)
tool.activate()
manager.set_default_tool(tool)
self.plot.add_item(self.marker)
self.plot.add_item(self.label)
self.plot.add_item(self.line)
self.plot.startMeasuring.connect(self.line.start_measuring)
self.plot.moveMeasuring.connect(self.line.move_measuring)
self.plot.stopMeasuring.connect(self.line.stop_measuring)
self.plot.moveMarker.connect(self.marker.move_local_point_to)
self.line.updated.connect(self.plot.replot)
示例2: TestDialog
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class TestDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
vlayout = QVBoxLayout()
self.setLayout(vlayout)
self.widget = CurveWidget()
self.curve_item = make.curve([], [], color='r')
self.widget.plot.add_item(self.curve_item)
self.pm = PlotManager(self.widget)
self.pm.add_plot(self.widget.plot)
t = self.pm.add_tool(MyTool)
t.curve_item = self.curve_item
self.pm.set_default_tool(t)
t.activate()
self.layout().addWidget(self.widget)
self.update_curve()
def update_curve(self):
x = np.arange(0,10,.1)
y = np.sin(np.sin(x))
self.curve_item.set_data(x, y)
self.curve_item.plot().replot()
示例3: MzPlottingWidget
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class MzPlottingWidget(CurveWidget):
def __init__(self, parent=None):
super(MzPlottingWidget, self).__init__(parent, xlabel="mz", ylabel="I")
patch_inner_plot_object(self, MzPlot)
self.plot.centralMz = None
def label(self, x):
# label with full precision:
return QwtText(str(x))
a = QwtScaleDraw()
a.label = new.instancemethod(label, self.plot, QwtScaleDraw)
self.plot.setAxisScaleDraw(self.plot.xBottom, a)
self.pm = PlotManager(self)
self.pm.add_plot(self.plot)
self.curve = make_unselectable_curve([], [], color="b", curvestyle="Sticks")
self.plot.add_item(self.curve)
t = self.pm.add_tool(MzSelectionTool)
self.pm.set_default_tool(t)
t.activate()
marker = Marker(label_cb=self.plot.label_info, constraint_cb=self.plot.on_plot)
marker.attach(self.plot)
line = make_measurement_line()
line.setVisible(0)
setupCommonStyle(line, marker)
line.shapeparam.line.color = "#555555"
line.shapeparam.update_shape(line)
label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
label.labelparam.label = ""
label.labelparam.font.size = 12
label.labelparam.update_label(label)
self.marker = marker
self.label = label
self.line = line
def plot_spectra(self, all_peaks, labels):
self.plot.del_all_items()
self.plot.add_item(self.marker)
self.plot.add_item(make.legend("TL"))
self.plot.add_item(self.label)
for i, (peaks, label) in enumerate(zip(all_peaks, labels)):
config = dict(color=getColor(i))
curve = make_unselectable_curve([], [], title=label, curvestyle="Sticks", **config)
curve.set_data(peaks[:, 0], peaks[:, 1])
self.plot.add_item(curve)
self.plot.resample_config = []
self.plot.add_item(self.line)
if len(all_peaks):
self.plot.all_peaks = np.vstack(all_peaks)
else:
self.plot.all_peaks = np.zeros((0, 2))
def _setup_configs_and_titles(self, configs, titles, n):
configs = configs if configs is not None else [None] * n
titles = titles if titles is not None else [""] * n
def default(i):
return dict(color=getColor(i))
configs = [ci if ci is not None else default(i) for (i, ci) in enumerate(configs)]
return configs, titles
def set_overall_range(self, mzmin, mzmax):
self.plot.overall_x_min = mzmin
self.plot.overall_x_max = mzmax
def plot_peakmaps(self, peakmap_ranges, configs=None, titles=None):
has_titles = titles is not None
configs, titles = self._setup_configs_and_titles(configs, titles, len(peakmap_ranges))
self.plot.del_all_items()
self.plot.add_item(self.marker)
if has_titles:
self.plot.add_item(make.legend("TL"))
self.plot.add_item(self.label)
self.plot.plot_peakmap_ranges(peakmap_ranges, configs, titles)
self.plot.add_item(self.line)
def set_cursor_pos(self, mz):
self.plot.set_mz(mz)
def resetAxes(self):
self.plot.reset_x_limits()
def reset_mz_limits(self, xmin=None, xmax=None, fac=1.1):
self.plot.reset_x_limits(xmin, xmax, fac)
#.........这里部分代码省略.........
示例4: RtPlotter
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class RtPlotter(PlotterBase):
def __init__(self, parent=None, rangeSelectionCallback=None):
PlotterBase.__init__(self, "RT", "I")
self.rangeSelectionCallback = rangeSelectionCallback
widget = self.widget
widget.plot.__class__ = RtPlot
self.pm = PlotManager(widget)
self.pm.add_plot(widget.plot)
t = self.pm.add_tool(RtSelectionTool)
t.activate()
self.pm.set_default_tool(t)
marker = Marker(label_cb=self.widget.plot.label_info,
constraint_cb=self.widget.plot.on_plot)
marker.rts = [0]
setupStyleRtMarker(marker)
marker.attach(self.widget.plot)
self.marker = marker
self.cursor_info = RtCursorInfo(marker)
label = make.info_label("T", [self.cursor_info], title=None)
label.labelparam.label = ""
label.labelparam.font.size = 12
label.labelparam.border.color = "#ffffff"
label.labelparam.update_label(label)
self.label = label
self.minRTRangeSelected = None
self.maxRTRangeSelected = None
def _set_rt_x_axis_labels(self):
# todo: refactor as helper
a = QwtScaleDraw()
# render tic labels in modfied format:
label = lambda self, v: QwtText(formatSeconds(v))
a.label = new.instancemethod(label, self.widget.plot, QwtScaleDraw)
self.widget.plot.setAxisScaleDraw(self.widget.plot.xBottom, a)
def _set_ts_x_axis_labels(self, data):
# todo: refactor as helper
all_ts = [tsi for ts in data for tsi in ts.x]
pos = find_datetime_split_pos(all_ts)
a = QwtScaleDraw()
# render tic labels in modfied format:
label = lambda self, v, pos=pos: QwtText(format_datetime_value(pos, v)) # QwtText(str(v))
a.label = new.instancemethod(label, self.widget.plot, QwtScaleDraw)
self.widget.plot.setAxisScaleDraw(self.widget.plot.xBottom, a)
def reset(self):
"""empties plot"""
self.plot([])
self.marker.rts = [0]
self.replot()
def plot(self, data, is_time_series=False, titles=None, configs=None,
withmarker=False):
""" do not forget to call replot() after calling this function ! """
allrts = []
self.widget.plot.del_all_items()
if is_time_series:
self._set_ts_x_axis_labels(data)
self.widget.plot.set_axis_title("bottom", "time")
else:
self._set_rt_x_axis_labels()
self.widget.plot.set_axis_title("bottom", "RT")
labels = set()
legend_items = []
if is_time_series:
seen = set()
for i, ts in enumerate(data):
# we do not plot duplicates, which might happen if multiple lines in the
# table explorer are sellected !
if id(ts) in seen:
continue
seen.add(id(ts))
config = None
if configs is not None:
config = configs[i]
if config is None:
config = dict(color=getColor(i))
title = ts.label
labels.add(title)
for j, (x, y) in enumerate(ts.for_plotting()):
x = [xi.toordinal() if isinstance(xi, datetime) else xi for xi in x]
allrts.extend(x)
curve = make.curve(x, y, title="<pre>%s</pre>" % title, **config)
curve.__class__ = ModifiedCurveItem
self.widget.plot.add_item(curve)
self.cursor_info.is_time_series = True
if j == 0:
legend_items.append(curve)
#.........这里部分代码省略.........
示例5: GuiQwtPlot
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
#.........这里部分代码省略.........
w = QtGui.QWidget()
w.setLayout( hbox )
self.setCentralWidget( w )
def __setup_layout( self ):
self.connect( self.button, QtCore.SIGNAL( 'clicked()' ), self.button_Click )
self.connect( self.button2, QtCore.SIGNAL( 'clicked()' ), self.button_Click2 )
self.connect( self.button3, QtCore.SIGNAL( 'clicked()' ), self.button_Click3 )
self.connect( self.button4, QtCore.SIGNAL( 'clicked()' ), self.button_Click4 )
self.connect( self.button5, QtCore.SIGNAL( 'clicked()' ), self.button_Click5 )
self.connect( self.button6, QtCore.SIGNAL( 'clicked()' ), self.button_Click6 )
# Vertical cursor
self.cursorposition = 0.8
self.cursorposition2 = 1.2
self.vcursor1 = make.vcursor(self.cursorposition, label='x = %.2f')
self.plot.add_item( self.vcursor1 )
self.vcursor2 = make.vcursor(self.cursorposition2, label='x = %.2f')
self.plot.add_item( self.vcursor2 )
# Define the y label, x might change depending on user definition
CurvePlot.set_axis_title(self.plot,CurvePlot.Y_LEFT,"Intensity (counts)")
# Crate the PlotManager
self.manager = PlotManager( self )
self.manager.add_plot( self.plot )
self.manager.add_plot( self.plot2 )
# Create Toolbar
toolbar = self.addToolBar( 'tools' )
self.manager.add_toolbar( toolbar, id( toolbar ) )
# Register the ToolBar's type
self.manager.register_all_curve_tools( )
# self.manager.register_other_tools()
# Register a custom tool
self.manager.add_tool( SelectPointTool, title = 'Position', on_active_item = True, mode = 'create' )
def fill_series_list(self, names):
self.series_list_model.clear()
counterlist = 0
for name in reversed(names):
item = QtGui.QStandardItem(name)
# if counterlist == 0: # Check only the first one
# item.setCheckState(Qt.Checked)
# else:
item.setCheckState(Qt.Unchecked)
item.setCheckable(True)
self.series_list_model.appendRow(item)
counterlist = counterlist + 1
# Load data to the list
def button_Click( self ):
# Find the newest files in the directory and subdirectories
# and populate the list of files
self.y = {}
self.x = {}
self.timestamp = {}
self.names = []
self.fullfilename = {}
示例6: EicPlottingWidget
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class EicPlottingWidget(CurveWidget):
SELECTED_RANGE_CHANGED = pyqtSignal(float, float)
def __init__(self, parent=None, with_range=True):
super(EicPlottingWidget, self).__init__(parent, ylabel="I")
patch_inner_plot_object(self, EicPlot)
self._with_range = with_range
self._setup_plot()
def enable_range(self, flag):
self._with_range = flag
self._setup_range_selector()
def _setup_plot(self):
self.pm = PlotManager(self)
self.pm.add_plot(self.plot)
t = self.pm.add_tool(RtSelectionTool)
t.activate()
self.pm.set_default_tool(t)
self._setup_cursor()
self._setup_range_selector()
self._setup_label()
self._setup_axes()
def _setup_cursor(self):
marker = Marker(label_cb=self.plot.label_info, constraint_cb=self.plot.on_plot)
marker.rts = [0]
setup_marker_param(marker, {"symbol.size": 0,
"symbol.alpha": 0.0,
"sel_symbol.size": 0,
"sel_symbol.alpha": 0.0,
"line.color": "#909090",
"line.width": 1.0,
"line.style": "SolidLine",
"sel_line.color": "#909090",
"sel_line.width": 1.0,
"sel_line.style": "SolidLine",
"markerstyle": "VLine"})
marker.attach(self.plot)
self.marker = marker
self._setup_cursor_info(marker)
def _setup_cursor_info(self, marker):
self.cursor_info = RtCursorInfo(marker)
def _setup_range_selector(self):
if not self._with_range:
self.range_ = None
return
self.range_ = SnappingRangeSelection(0, 0)
# you have to register item to plot before you can register the
# rtSelectionHandler:
self.plot.add_item(self.range_)
self.range_.SELECTED_RANGE_CHANGED.connect(self._range_selection_handler)
cc = make.info_label("TR", [RangeSelectionInfo(self.range_)], title=None)
setup_label_param(cc, {"label": "", "font.size": 12})
self.plot.add_item(cc)
def _setup_label(self):
label = make.info_label("T", [self.cursor_info], title=None)
setup_label_param(label, {"label": "", "font.size": 12, "border.color": "#ffffff"})
self.label = label
def _setup_axes(self):
# render tic labels in modfied format:
set_rt_formatting_on_x_axis(self.plot)
self.plot.set_axis_title("bottom", "RT")
def plot_(self, eics):
self.add_eics(eics)
def set_cursor_pos(self, rt):
self.plot.set_rt(rt)
def set_overall_range(self, rtmin, rtmax):
self.plot.overall_x_min = rtmin
self.plot.overall_x_max = rtmax
def add_eics(self, data, labels=None, configs=None):
""" do not forget to call replot() after calling this function ! """
allrts = list()
if configs is None:
configs = [{"color": getColor(i)} for i in range(len(data))]
if labels is None:
labels = [""] * len(data)
unique_labels = set()
# items_with_label = []
seen = set()
for i, (rts, chromatogram) in enumerate(data):
# we do not plot duplicates, which might happen if multiple lines in the
#.........这里部分代码省略.........
示例7: RtPlotter
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class RtPlotter(PlotterBase):
def __init__(self, rangeSelectionCallback=None):
super(RtPlotter, self).__init__("RT", "I")
self.rangeSelectionCallback = rangeSelectionCallback
widget = self.widget
widget.plot.__class__ = RtPlot
# todo: refactor as helper
a = QwtScaleDraw()
# render tic labels in modfied format:
label = lambda self, v: QwtText(formatSeconds(v))
a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)
self.pm = PlotManager(widget)
self.pm.add_plot(widget.plot)
t = self.pm.add_tool(RtSelectionTool)
self.addTool(RtSelectionTool)
self.pm.set_default_tool(t)
marker = Marker(label_cb=self.widget.plot.label_info,
constraint_cb=self.widget.plot.on_plot)
marker.rts = [0]
setupStyleRtMarker(marker)
marker.attach(self.widget.plot)
self.marker = marker
label = make.info_label("T", [RtCursorInfo(marker)], title=None)
label.labelparam.label = ""
self.label = label
self.minRTRangeSelected = None
self.maxRTRangeSelected = None
def addTool(self, tool):
t = self.pm.add_tool(tool)
t.activate()
def reset(self):
self.plot([])
self.marker.rts = [0]
self.replot()
def plot(self, chromatograms, titles=None, configs=None,
withmarker=False):
""" do not forget to call replot() after calling this function ! """
allrts = set()
self.widget.plot.del_all_items()
# self.widget.plot.set_antialiasing(True)
for i in range(len(chromatograms)):
rts, chromatogram = chromatograms[i]
config = None
if configs is not None:
config = configs[i]
if config is None:
config = dict(color=getColor(i))
if titles:
title = titles[i]
else:
title = ""
curve = make.curve(rts, chromatogram, title=title, **config)
curve.__class__ = ModifiedCurveItem
allrts.update(rts)
self.widget.plot.add_item(curve)
if withmarker:
self.widget.plot.add_item(self.label)
allrts = sorted(allrts)
self.marker.rts = allrts
self.marker.attach(self.widget.plot)
self.widget.plot.add_item(self.marker)
if titles is not None:
self.widget.plot.add_item(make.legend("TL"))
self.addRangeSelector(allrts)
def setEnabled(self, enabled):
self.widget.plot.setVisible(enabled)
def addRangeSelector(self, rtvalues):
self.rtvalues = rtvalues
self.minRTRangeSelected = 0
self.maxRTRangeSelected = 0
range_ = SnappingRangeSelection(self.minRTRangeSelected,
self.maxRTRangeSelected, self.rtvalues)
setupStyleRangeMarker(range_)
self.range_ = range_
# you have to register item to plot before you can register the
# rtSelectionHandler:
self.widget.plot.add_item(range_)
self.widget.disconnect(range_.plot(), SIG_RANGE_CHANGED,
self.rangeSelectionHandler)
self.widget.connect(range_.plot(), SIG_RANGE_CHANGED,
#.........这里部分代码省略.........
示例8: MzPlotter
# 需要导入模块: from guiqwt.plot import PlotManager [as 别名]
# 或者: from guiqwt.plot.PlotManager import add_tool [as 别名]
class MzPlotter(PlotterBase):
def __init__(self, c_callback=None, image_plot=None):
super(MzPlotter, self).__init__("m/z", "I")
self.c_callback = c_callback
widget = self.widget
# inject mofified behaviour of wigets plot attribute:
widget.plot.__class__ = MzPlot
widget.plot.register_c_callback(self.handle_c_pressed)
widget.plot.image_plot = image_plot
self.setHalfWindowWidth(0.05)
self.centralMz = None
# todo: refactor as helper
a = QwtScaleDraw()
label = lambda self, x: QwtText("%s" % x)
a.label = new.instancemethod(label, widget.plot, QwtScaleDraw)
widget.plot.setAxisScaleDraw(widget.plot.xBottom, a)
self.pm = PlotManager(widget)
self.pm.add_plot(widget.plot)
self.curve = make.curve([], [], color='b', curvestyle="Sticks")
# inject modified behaviour:
self.curve.__class__ = ModifiedCurveItem
self.widget.plot.add_item(self.curve)
t = self.pm.add_tool(MzSelectionTool)
self.pm.set_default_tool(t)
t.activate()
marker = Marker(label_cb=widget.plot.label_info,
constraint_cb=widget.plot.on_plot)
marker.attach(self.widget.plot)
line = make.segment(0, 0, 0, 0)
line.__class__ = ModifiedSegment
line.setVisible(0)
setupCommonStyle(line, marker)
label = make.info_label("TR", [MzCursorInfo(marker, line)], title=None)
label.labelparam.label = ""
self.marker = marker
self.label = label
self.line = line
def setHalfWindowWidth(self, w2):
self.widget.plot.set_half_window_width(w2)
def setCentralMz(self, mz):
self.widget.plot.set_central_mz(mz)
def handle_c_pressed(self, p):
if self.c_callback:
self.c_callback(p)
def plot(self, data, configs=None, titles=None):
""" do not forget to call replot() after calling this function ! """
self.widget.plot.del_all_items()
self.widget.plot.add_item(self.marker)
if titles is not None:
self.widget.plot.add_item(make.legend("TL"))
self.widget.plot.add_item(self.label)
all_peaks = []
self.widget.plot.data = []
self.widget.plot.curves = []
for i, (pm, rtmin, rtmax, mzmin, mzmax, npeaks) in enumerate(data):
if rtmin is None and rtmax is None:
rtmin, rtmax = pm.rtRange()
elif rtmin is None:
rtmin, __ = pm.rtRange()
elif rtmax is None:
__, rtmax = pm.rtRange()
if mzmin is None and mzmax is None:
mzmin, mzmax = pm.mzRange()
elif mzmin is None:
mzmin, __ = pm.mzRange()
elif mzmax is None:
__, mzmax = pm.mzRange()
if npeaks is None:
npeaks = 3000
peaks = sample_peaks(pm, rtmin, rtmax, mzmin, mzmax, npeaks)
all_peaks.append(peaks)
config = configs[i] if configs is not None else None
if config is None:
config = dict(color=getColor(i))
if titles is not None:
title = titles[i]
else:
title = u""
curve = make.curve([], [], title=title, curvestyle="Sticks", **config)
curve.set_data(peaks[:, 0], peaks[:, 1])
#.........这里部分代码省略.........