Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_to_viewwidget(self, viewwidget=None):
if viewwidget is not None:
self.viewwidget = viewwidget
self.viewwidget.addItem(self)
# Removing the handle from this CricleROI
self.removeHandle(0)
# create a new free handle for the name tag, positioned at "east" on the circle.
self.my_handle = self.addRotateHandle([1, 0.5], [0.5, 0.5])
self.sigRegionChangeFinished.connect(self._redraw_label)
self.label = pg.TextItem(text=self.poi.get_name(),
anchor=(0, 1),
color= self.color
)
self.setAngle(30)
self.setPos(self.position + self.get_marker_offset())
# self.viewwidget.addItem(self.label)
g_init = self.model(**inputs)
fit_g = fitting.LevMarLSQFitter()
g = fit_g(g_init, x, y)
txt=''
for paramname in g.param_names:
self.param('Outputs').param(paramname).setValue(getattr(g,paramname).value)
txt+=paramname +': '+str(getattr(g,paramname).value)+'\n'
txt=txt[:-1] # remove trailing new line
# Plot fit in similar style
pen = pg.mkPen(item.opts['pen'])
pen.setStyle(Qt.DashLine)
curve = self.parentTree.plotwidget.plot(x,g(x),pen=pen)
curve.isFit=True
curve.display_text = pg.TextItem(text='Test', color=(255, 255, 255), anchor=(0, 1),
fill=pg.mkBrush(255, 127, 0, 100))
curve.display_text.hide()
self.parentTree.plotwidget.addItem(curve.display_text)
def hover(event):
curve.display_text.setPos(event.pos())
curve.display_text.setVisible(not event.exit)
curve.display_text.setText(txt)
curve.curve.hoverEvent=hover
color = pg.mkColor(0, 0, 255)
elif (event_name == "KEY"):
color = pg.mkColor(255, 0, 0)
elif (event_name == "LPT"):
color = pg.mkColor(0, 255, 0)
else:
color = pg.mkColor(255, 255, 255)
self.events_detected.append(self.data_plot.shape[0] - 1)
self.events_detected.append(event_id)
self.events_curves.append(self.main_plot_handler.plot(pen=color,
x=np.array([self.x_ticks[-1], self.x_ticks[-1]]), y=np.array(
[+1.5 * self.scale,
-1.5 * self.scale * self.config['eeg_channels']])))
# text = pg.TextItem(event_name + "(" + str(self.events_detected[-1]) + ")", anchor=(1.1,0), fill=(0,0,0), color=color)
text = pg.TextItem(str(self.events_detected[-1]), anchor=(1.1, 0),
fill=(0, 0, 0), color=color)
text.setPos(self.x_ticks[-1], self.scale)
self.events_text.append(text)
self.main_plot_handler.addItem(self.events_text[-1])
d3.addWidget(p3)
area.addDock(d1, 'top')
area.addDock(d2, 'top', d1)
area.addDock(d3, 'bottom', d1)
residuals_plot = p1.getPlotItem()
auto_corr_plot = p2.getPlotItem()
data_plot = p3.getPlotItem()
self.data_plot = data_plot
self.res_plot = residuals_plot
self.auto_corr_plot = auto_corr_plot
# Labels
self.text = pg.TextItem(text='', border='w', fill=(0, 0, 255, 100), anchor=(0, 0))
self.data_plot.addItem(self.text)
colors = mfm.settings.gui['plot']['colors']
# Fitting-region selector
if mfm.settings.gui['plot']['enable_region_selector']:
ca = list(mpl_colors.hex2color(colors["region_selector"]))
co = [ca[0] * 255, ca[1] * 255, ca[2] * 255, colors["region_selector_alpha"]]
region = pg.LinearRegionItem(brush=co)
data_plot.addItem(region)
self.region = region
def update_region(evt):
lb, ub = region.getRegion()
data_x = fit.data.x
if self.pltControl.data_is_log_x:
lb, ub = 10**lb, 10**ub
if names is None:
names = [None] * len(y)
self.sequences = y
self.x = x
self.selection_limit = selection_limit
self.data_increasing = [np.sum(d[1:] - d[:-1]) > 0 for d in y]
# plot sequence
for s, c, n, inc in zip(y, colors, names, self.data_increasing):
c = QColor(c)
self.plot(x, s, pen=mkPen(c, width=2), antialias=True)
if n is not None:
label = TextItem(
text=n, anchor=(0, 1), color=QColor(0, 0, 0, 128))
label.setPos(x[-1], s[-1])
self._set_anchor(label, len(x) - 1, inc)
self.addItem(label)
self._plot_cutpoint(cutpoint_x)
self.setRange(xRange=(x.min(), x.max()),
yRange=(0, max(yi.max() for yi in y)))
def _plot_horizontal_lines(self):
"""
Function plots the vertical dashed lines that points to the selected
sequence values at the y axis.
"""
for _ in range(len(self.sequences)):
self.plot_horline.append(PlotCurveItem(
pen=mkPen(QColor(Qt.blue), style=Qt.DashLine)))
self.plot_horlabel.append(TextItem(
color=QColor(Qt.black), anchor=(0, 1)))
for item in self.plot_horlabel + self.plot_horline:
self.addItem(item)
def on_stations_listWidget_currentItemChanged(self, current, previous):
if current is None:
return
self._reset_all_plots()
try:
wave = self.comm.query.get_matching_waveforms(
self.current_event, self.current_iteration,
self.current_station)
except Exception as e:
for component in ["Z", "N", "E"]:
plot_widget = getattr(self.ui, "%s_graph" % component.lower())
plot_widget.addItem(pg.TextItem(
text=str(e), anchor=(0.5, 0.5),
color=(200, 0, 0)))
return
event = self.comm.events.get(self.current_event)
great_circle_distance = locations2degrees(
event["latitude"], event["longitude"],
wave.coordinates["latitude"], wave.coordinates["longitude"])
tts = getTravelTimes(great_circle_distance, event["depth_in_km"],
model="ak135")
windows_for_station = \
self.current_window_manager.get_windows_for_station(
self.current_station)
def _init_label(self) -> None:
"""
Create label objects on axis.
"""
self._y_labels: Dict[str, pg.TextItem] = {}
for plot_name, plot in self._plots.items():
label = pg.TextItem(
plot_name, fill=CURSOR_COLOR, color=BLACK_COLOR)
label.hide()
label.setZValue(2)
label.setFont(NORMAL_FONT)
plot.addItem(label, ignoreBounds=True)
self._y_labels[plot_name] = label
self._x_label: pg.TextItem = pg.TextItem(
"datetime", fill=CURSOR_COLOR, color=BLACK_COLOR)
self._x_label.hide()
self._x_label.setZValue(2)
self._x_label.setFont(NORMAL_FONT)
plot.addItem(self._x_label, ignoreBounds=True)
position : tuple
'''
super(motormodel, self).__init__(deviceitem)
self.position = position
self.size = size
self.device = deviceitem.device
self.devicepen = pg.mkPen(color='g',width=2)
self.devicebrush = pg.mkBrush(color=[0,0,0,50])
self.rectItem = QGraphicsRectItem(QRect(QPoint(*position),QSize(*size)))
self.rectItem.setParentItem(self)
self.rectItem.setPen(self.devicepen)
self.rectItem.setBrush(self.devicebrush)
self.textItem = pg.TextItem(self.device.getMnemonic(),anchor=(0,1))
self.textItem.setParentItem(self)
self.textItem.setPos(QPoint(*self.position))
self.viewBox.doubleclicked.connect(self.show_params_controller)
self.viewBox.gain_zoom.connect(self.params_controller.apply_ygain_zoom)
self.viewBox.xsize_zoom.connect(self.apply_xsize_zoom)
self.params.param('xsize').setLimits([2./self.sample_rate, self.max_xsize*.95])
self.curves = []
self.channel_labels = []
for i in range(self.nb_channel):
color = '#7FFF00' # TODO
curve = pg.PlotCurveItem(pen=color)
self.plot.addItem(curve)
self.curves.append(curve)
txt = '{}: {}'.format(i, self.channel_names[i])
label = pg.TextItem(txt, color=color, anchor=(0.5, 0.5), border=None, fill=pg.mkColor((128,128,128, 200)))
self.plot.addItem(label)
self.channel_labels.append(label)
self.reset_curves_data()