本文整理汇总了Python中PyQt5.QtWidgets.QGraphicsScene.addPath方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsScene.addPath方法的具体用法?Python QGraphicsScene.addPath怎么用?Python QGraphicsScene.addPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QGraphicsScene
的用法示例。
在下文中一共展示了QGraphicsScene.addPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Traces
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import addPath [as 别名]
#.........这里部分代码省略.........
window_length = self.parent.value('window_length')
label_width = window_length * self.parent.value('label_ratio')
for row, one_label_item in enumerate(self.idx_label):
self.scene.addItem(one_label_item)
one_label_item.setPos(window_start - label_width,
self.parent.value('y_distance') * row +
self.parent.value('y_distance') / 2)
def add_time_labels(self):
"""Add time labels at the bottom."""
for text, pos in zip(self.idx_time, self.time_pos):
self.scene.addItem(text)
text.setPos(pos)
def add_traces(self):
"""Add traces based on self.data."""
y_distance = self.parent.value('y_distance')
self.chan = []
self.chan_pos = []
self.chan_scale = []
row = 0
for one_grp in self.parent.channels.groups:
for one_chan in one_grp['chan_to_plot']:
# channel name
chan_name = one_chan + ' (' + one_grp['name'] + ')'
# trace
dat = (self.data(trial=0, chan=chan_name) *
self.parent.value('y_scale'))
dat *= -1 # flip data, upside down
path = self.scene.addPath(Path(self.data.axis['time'][0],
dat))
path.setPen(QPen(QColor(one_grp['color']), LINE_WIDTH))
# adjust position
chan_pos = y_distance * row + y_distance / 2
path.setPos(0, chan_pos)
row += 1
self.chan.append(chan_name)
self.chan_scale.append(one_grp['scale'])
self.chan_pos.append(chan_pos)
def display_grid(self):
"""Display grid on x-axis and y-axis."""
window_start = self.parent.value('window_start')
window_length = self.parent.value('window_length')
window_end = window_start + window_length
if self.parent.value('grid_x'):
x_tick = self.parent.value('grid_xtick')
x_ticks = arange(window_start, window_end + x_tick, x_tick)
for x in x_ticks:
x_pos = [x, x]
y_pos = [0,
self.parent.value('y_distance') * len(self.idx_label)]
path = self.scene.addPath(Path(x_pos, y_pos))
path.setPen(QPen(QColor(LINE_COLOR), LINE_WIDTH,
Qt.DotLine))
if self.parent.value('grid_y'):
for one_label_item in self.idx_label:
x_pos = [window_start, window_end]
示例2: Spectrum
# 需要导入模块: from PyQt5.QtWidgets import QGraphicsScene [as 别名]
# 或者: from PyQt5.QtWidgets.QGraphicsScene import addPath [as 别名]
#.........这里部分代码省略.........
def display(self, data):
"""Make graphicsitem for spectrum figure.
Parameters
----------
data : ndarray
1D vector containing the data only
This function can be called by self.display_window (which reads the
data for the selected channel) or by the mouse-events functions in
traces (which read chunks of data from the user-made selection).
"""
value = self.config.value
self.scene = QGraphicsScene(value['x_min'], value['y_min'],
value['x_max'] - value['x_min'],
value['y_max'] - value['y_min'])
self.idx_fig.setScene(self.scene)
self.add_grid()
self.resizeEvent(None)
s_freq = self.parent.traces.data.s_freq
f, Pxx = welch(data, fs=s_freq,
nperseg=int(min((s_freq, len(data))))) # force int
freq_limit = (value['x_min'] <= f) & (f <= value['x_max'])
if self.config.value['log']:
Pxx_to_plot = log(Pxx[freq_limit])
else:
Pxx_to_plot = Pxx[freq_limit]
self.scene.addPath(Path(f[freq_limit], Pxx_to_plot),
QPen(QColor(LINE_COLOR), LINE_WIDTH))
def add_grid(self):
"""Add axis and ticks to figure.
Notes
-----
I know that visvis and pyqtgraphs can do this in much simpler way, but
those packages create too large a padding around the figure and this is
pretty fast.
"""
value = self.config.value
# X-AXIS
# x-bottom
self.scene.addLine(value['x_min'], value['y_min'],
value['x_min'], value['y_max'],
QPen(QColor(LINE_COLOR), LINE_WIDTH))
# at y = 0, dashed
self.scene.addLine(value['x_min'], 0,
value['x_max'], 0,
QPen(QColor(LINE_COLOR), LINE_WIDTH, Qt.DashLine))
# ticks on y-axis
y_high = int(floor(value['y_max']))
y_low = int(ceil(value['y_min']))
x_length = (value['x_max'] - value['x_min']) / value['x_tick']
for y in range(y_low, y_high):
self.scene.addLine(value['x_min'], y,
value['x_min'] + x_length, y,
QPen(QColor(LINE_COLOR), LINE_WIDTH))
# Y-AXIS