本文整理汇总了Python中pyqtgraph.graphicsItems.ScatterPlotItem.scene方法的典型用法代码示例。如果您正苦于以下问题:Python ScatterPlotItem.scene方法的具体用法?Python ScatterPlotItem.scene怎么用?Python ScatterPlotItem.scene使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyqtgraph.graphicsItems.ScatterPlotItem
的用法示例。
在下文中一共展示了ScatterPlotItem.scene方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OWScatterPlotGraph
# 需要导入模块: from pyqtgraph.graphicsItems import ScatterPlotItem [as 别名]
# 或者: from pyqtgraph.graphicsItems.ScatterPlotItem import scene [as 别名]
#.........这里部分代码省略.........
self.set_axis_title("left", "")
if self.scaled_data is None or not len(self.scaled_data):
self.valid_data = None
self.n_points = 0
return
index_x = self.attribute_name_index[attr_x]
index_y = self.attribute_name_index[attr_y]
self.valid_data = self.get_valid_list([index_x, index_y])
x_data, y_data = self.get_xy_data_positions(
attr_x, attr_y, self.valid_data)
x_data = x_data[self.valid_data]
y_data = y_data[self.valid_data]
self.n_points = len(x_data)
for axis, name, index in (("bottom", attr_x, index_x),
("left", attr_y, index_y)):
self.set_axis_title(axis, name)
var = self.data_domain[index]
if isinstance(var, DiscreteVariable):
self.set_labels(axis, get_variable_values_sorted(var))
color_data, brush_data = self.compute_colors()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=np.arange(self.n_points),
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data)
self.plot_widget.addItem(self.scatterplot_item)
self.plot_widget.addItem(self.tooltip)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.scatterplot_item.scene().sigMouseMoved.connect(self.mouseMoved)
self.update_labels()
self.make_legend()
self.plot_widget.replot()
def set_labels(self, axis, labels):
axis = self.plot_widget.getAxis(axis)
if labels:
ticks = [[(i, labels[i]) for i in range(len(labels))]]
axis.setTicks(ticks)
else:
axis.setTicks(None)
def set_axis_title(self, axis, title):
self.plot_widget.setLabel(axis=axis, text=title)
def get_size_index(self):
size_index = -1
attr_size = self.attr_size
if attr_size != "" and attr_size != "(Same size)":
size_index = self.attribute_name_index[attr_size]
return size_index
def compute_sizes(self):
size_index = self.get_size_index()
if size_index == -1:
size_data = np.full((self.n_points,), self.point_width)
else:
size_data = \
self.MinShapeSize + \
self.no_jittering_scaled_data[size_index] * self.point_width
size_data[np.isnan(size_data)] = self.MinShapeSize - 2
示例2: OWScatterPlotGraph
# 需要导入模块: from pyqtgraph.graphicsItems import ScatterPlotItem [as 别名]
# 或者: from pyqtgraph.graphicsItems.ScatterPlotItem import scene [as 别名]
class OWScatterPlotGraph(gui.OWComponent, ScaleScatterPlotData):
attr_color = ContextSetting("", ContextSetting.OPTIONAL)
attr_label = ContextSetting("", ContextSetting.OPTIONAL)
attr_shape = ContextSetting("", ContextSetting.OPTIONAL)
attr_size = ContextSetting("", ContextSetting.OPTIONAL)
point_width = Setting(10)
alpha_value = Setting(128)
show_grid = Setting(False)
show_legend = Setting(True)
tooltip_shows_all = Setting(False)
class_density = Setting(False)
resolution = 256
CurveSymbols = np.array("o x t + d s ?".split())
MinShapeSize = 6
DarkerValue = 120
UnknownColor = (168, 50, 168)
def __init__(self, scatter_widget, parent=None, _="None"):
gui.OWComponent.__init__(self, scatter_widget)
self.view_box = InteractiveViewBox(self)
self.plot_widget = pg.PlotWidget(viewBox=self.view_box, parent=parent,
background="w")
self.plot_widget.getPlotItem().buttonsHidden = True
self.plot_widget.setAntialiasing(True)
self.plot_widget.sizeHint = lambda: QtCore.QSize(500,500)
self.replot = self.plot_widget.replot
ScaleScatterPlotData.__init__(self)
self.density_img = None
self.scatterplot_item = None
self.scatterplot_item_sel = None
self.labels = []
self.master = scatter_widget
self.shown_attribute_indices = []
self.shown_x = ""
self.shown_y = ""
self.pen_colors = self.brush_colors = None
self.valid_data = None # np.ndarray
self.selection = None # np.ndarray
self.n_points = 0
self.gui = OWPlotGUI(self)
self.continuous_palette = ContinuousPaletteGenerator(
QColor(255, 255, 0), QColor(0, 0, 255), True)
self.discrete_palette = ColorPaletteGenerator()
self.selection_behavior = 0
self.legend = self.color_legend = None
self.__legend_anchor = (1, 0), (1, 0)
self.__color_legend_anchor = (1, 1), (1, 1)
self.scale = None # DiscretizedScale
self.subset_indices = None
# self.setMouseTracking(True)
# self.grabGesture(QPinchGesture)
# self.grabGesture(QPanGesture)
self.update_grid()
self._tooltip_delegate = HelpEventDelegate(self.help_event)
self.plot_widget.scene().installEventFilter(self._tooltip_delegate)
def new_data(self, data, subset_data=None, **args):
self.plot_widget.clear()
self.density_img = None
self.scatterplot_item = None
self.scatterplot_item_sel = None
self.labels = []
self.selection = None
self.valid_data = None
self.subset_indices = set(e.id for e in subset_data) if subset_data else None
self.set_data(data, **args)
def update_data(self, attr_x, attr_y, reset_view=True):
self.shown_x = attr_x
self.shown_y = attr_y
self.remove_legend()
if self.density_img:
self.plot_widget.removeItem(self.density_img)
self.density_img = None
if self.scatterplot_item:
self.plot_widget.removeItem(self.scatterplot_item)
self.scatterplot_item = None
if self.scatterplot_item_sel:
self.plot_widget.removeItem(self.scatterplot_item_sel)
self.scatterplot_item_sel = None
for label in self.labels:
self.plot_widget.removeItem(label)
#.........这里部分代码省略.........