本文整理汇总了Python中pyqtgraph.graphicsItems.ScatterPlotItem类的典型用法代码示例。如果您正苦于以下问题:Python ScatterPlotItem类的具体用法?Python ScatterPlotItem怎么用?Python ScatterPlotItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScatterPlotItem类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: update_coordinates
def update_coordinates(self):
"""
Trigger the update of coordinates while keeping other features intact.
The method gets the coordinates by calling `self.get_coordinates`,
which in turn calls the widget's `get_coordinate_data`. The number of
coordinate pairs returned by the latter must match the current number
of points. If this is not the case, the widget should trigger
the complete update by calling `reset_graph` instead of this method.
"""
x, y = self.get_coordinates()
if x is None or not len(x):
return
if self.scatterplot_item is None:
if self.sample_indices is None:
indices = np.arange(self.n_valid)
else:
indices = self.sample_indices
kwargs = dict(x=x, y=y, data=indices)
self.scatterplot_item = ScatterPlotItem(**kwargs)
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.scatterplot_item_sel = ScatterPlotItem(**kwargs)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
else:
self._update_plot_coordinates(self.scatterplot_item, x, y)
self._update_plot_coordinates(self.scatterplot_item_sel, x, y)
self.update_labels()
self.update_density() # Todo: doesn't work: try MDS with density on
self._reset_view(x, y)
开发者ID:mstrazar,项目名称:orange3,代码行数:31,代码来源:owscatterplotgraph.py
示例2: setDataPointsVisibility
def setDataPointsVisibility(self, b):
if self.dataPoints is None:
if self.flags == 'peak':
chrom = self.ref.sample.massExtraction(self.ref.mass(), self.ref.sample.ppm, asChromatogram=True)
self.dataPoints = ScatterPlotItem(x=chrom.x_data, y=chrom.y_data)
else:
self.dataPoints = ScatterPlotItem(x=self.ref.x_data, y=self.ref.y_data)
if self.flags != 'spectra':
self.dataPoints.sigClicked.connect(self.requestSpectra)
self.pw.addDataItem(self.dataPoints)
self.dataPoints.setVisible(b)
开发者ID:jerkos,项目名称:metms,代码行数:11,代码来源:MetMplCanvas.py
示例3: _setup_plot
def _setup_plot(self):
self.__replot_requested = False
self.clear_plot()
variables = list(self.varmodel_selected)
if not variables:
return
coords = [self._get_data(var) for var in variables]
coords = numpy.vstack(coords)
p, N = coords.shape
assert N == len(self.data), p == len(variables)
axes = linproj.defaultaxes(len(variables))
assert axes.shape == (2, p)
mask = ~numpy.logical_or.reduce(numpy.isnan(coords), axis=0)
coords = coords[:, mask]
X, Y = numpy.dot(axes, coords)
X = plotutils.normalized(X)
Y = plotutils.normalized(Y)
pen_data, brush_data = self._color_data(mask)
size_data = self._size_data(mask)
shape_data = self._shape_data(mask)
if self.jitter_value > 0:
value = [0, 0.01, 0.1, 0.5, 1, 2][self.jitter_value]
rstate = numpy.random.RandomState(0)
jitter_x = (rstate.random_sample(X.shape) * 2 - 1) * value / 100
rstate = numpy.random.RandomState(1)
jitter_y = (rstate.random_sample(Y.shape) * 2 - 1) * value / 100
X += jitter_x
Y += jitter_y
self._item = ScatterPlotItem(
X, Y,
pen=pen_data,
brush=brush_data,
size=size_data,
shape=shape_data,
antialias=True,
data=numpy.arange(len(self.data))[mask]
)
self._item._mask = mask
self.viewbox.addItem(self._item)
for i, axis in enumerate(axes.T):
axis_item = AxisItem(line=QLineF(0, 0, axis[0], axis[1]),
label=variables[i].name)
self.viewbox.addItem(axis_item)
self.viewbox.setRange(QtCore.QRectF(-1.05, -1.05, 2.1, 2.1))
self._update_legend()
开发者ID:fdion,项目名称:orange3,代码行数:58,代码来源:owlinearprojection.py
示例4: update_data
def update_data(self, attr_x, attr_y):
self.shown_x = attr_x
self.shown_y = attr_y
self.remove_legend()
if self.scatterplot_item:
self.plot_widget.removeItem(self.scatterplot_item)
for label in self.labels:
self.plot_widget.removeItem(label)
self.labels = []
self.set_axis_title("bottom", "")
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))
else:
self.set_labels(axis, None)
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.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.update_labels()
self.make_legend()
self.plot_widget.replot()
开发者ID:vishnu-locket,项目名称:orange3,代码行数:52,代码来源:owscatterplotgraph.py
示例5: update_data
def update_data(self, attr_x, attr_y, reset_view=True):
self.master.warning(self.ID_MISSING_COORDS)
self.master.information(self.ID_MISSING_COORDS)
self._clear_plot_widget()
self.shown_x = attr_x
self.shown_y = attr_y
if self.scaled_data is None or not len(self.scaled_data):
self.valid_data = None
else:
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],
also_class_if_exists=False)
if not np.any(self.valid_data):
self.valid_data = None
if self.valid_data is None:
self.selection = None
self.n_points = 0
self.master.warning(
self.ID_MISSING_COORDS,
"Plot cannot be displayed because '{}' or '{}' is missing for "
"all data points".format(self.shown_x, self.shown_y))
return
x_data, y_data = self.get_xy_data_positions(
attr_x, attr_y, self.valid_data)
self.n_points = len(x_data)
if reset_view:
min_x, max_x = np.nanmin(x_data), np.nanmax(x_data)
min_y, max_y = np.nanmin(y_data), np.nanmax(y_data)
self.view_box.setRange(
QRectF(min_x, min_y, max_x - min_x, max_y - min_y),
padding=0.025)
self.view_box.init_history()
self.view_box.tag_history()
[min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
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 var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
if self.should_draw_density():
rgb_data = [pen.color().getRgb()[:3] for pen in color_data]
self.density_img = classdensity.class_density_image(
min_x, max_x, min_y, max_y, self.resolution,
x_data, y_data, rgb_data)
self.plot_widget.addItem(self.density_img)
data_indices = np.flatnonzero(self.valid_data)
if len(data_indices) != self.original_data.shape[1]:
self.master.information(
self.ID_MISSING_COORDS,
"Points with missing '{}' or '{}' are not displayed".
format(self.shown_x, self.shown_y))
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data
)
self.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.update_labels()
self.make_legend()
self.plot_widget.replot()
开发者ID:JingqinGao,项目名称:orange3,代码行数:86,代码来源:owscatterplotgraph.py
示例6: OWScatterPlotGraph
#.........这里部分代码省略.........
padding=0.025)
self.view_box.init_history()
self.view_box.tag_history()
[min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
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 var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
if self.should_draw_density():
rgb_data = [pen.color().getRgb()[:3] for pen in color_data]
self.density_img = classdensity.class_density_image(
min_x, max_x, min_y, max_y, self.resolution,
x_data, y_data, rgb_data)
self.plot_widget.addItem(self.density_img)
data_indices = np.flatnonzero(self.valid_data)
if len(data_indices) != self.original_data.shape[1]:
self.master.information(
self.ID_MISSING_COORDS,
"Points with missing '{}' or '{}' are not displayed".
format(self.shown_x, self.shown_y))
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data
)
self.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.update_labels()
self.make_legend()
self.plot_widget.replot()
def can_draw_density(self):
if self.data_domain is None:
return False
discrete_color = False
attr_color = self.attr_color
if attr_color != "" and attr_color != "(Same color)":
color_var = self.data_domain[attr_color]
discrete_color = color_var.is_discrete
continuous_x = False
continuous_y = False
if self.shown_x and self.shown_y:
continuous_x = self.data_domain[self.shown_x].is_continuous
continuous_y = self.data_domain[self.shown_y].is_continuous
return discrete_color and continuous_x and continuous_y
开发者ID:JingqinGao,项目名称:orange3,代码行数:67,代码来源:owscatterplotgraph.py
示例7: OWScatterPlotBase
#.........这里部分代码省略.........
Note. Pyqtgraph does not offer a method for this: setting coordinates
invalidates other data. We therefore retrieve the data to set it
together with the coordinates. Pyqtgraph also does not offer a
(documented) method for retrieving the data, yet using
`plot.data[prop]` looks reasonably safe. The alternative, calling
update for every property would essentially reset the graph, which
can be time consuming.
"""
data = dict(x=x, y=y)
for prop in ('pen', 'brush', 'size', 'symbol', 'data',
'sourceRect', 'targetRect'):
data[prop] = plot.data[prop]
plot.setData(**data)
def update_coordinates(self):
"""
Trigger the update of coordinates while keeping other features intact.
The method gets the coordinates by calling `self.get_coordinates`,
which in turn calls the widget's `get_coordinate_data`. The number of
coordinate pairs returned by the latter must match the current number
of points. If this is not the case, the widget should trigger
the complete update by calling `reset_graph` instead of this method.
"""
x, y = self.get_coordinates()
if x is None or not len(x):
return
if self.scatterplot_item is None:
if self.sample_indices is None:
indices = np.arange(self.n_valid)
else:
indices = self.sample_indices
kwargs = dict(x=x, y=y, data=indices)
self.scatterplot_item = ScatterPlotItem(**kwargs)
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.scatterplot_item_sel = ScatterPlotItem(**kwargs)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
else:
self._update_plot_coordinates(self.scatterplot_item, x, y)
self._update_plot_coordinates(self.scatterplot_item_sel, x, y)
self.update_labels()
self.update_density() # Todo: doesn't work: try MDS with density on
self._reset_view(x, y)
# Sizes
def get_sizes(self):
"""
Prepare data for sizes of points in the plot
The method is called by `update_sizes`. It gets the sizes
from the widget and performs the necessary scaling and sizing.
Returns:
(np.ndarray): sizes
"""
size_column = self.master.get_size_data()
if size_column is None:
return np.full((self.n_shown,),
self.MinShapeSize + (5 + self.point_width) * 0.5)
size_column = self._filter_visible(size_column)
size_column = size_column.copy()
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=RuntimeWarning)
size_column -= np.nanmin(size_column)
开发者ID:mstrazar,项目名称:orange3,代码行数:67,代码来源:owscatterplotgraph.py
示例8: update_data
def update_data(self, attr_x, attr_y):
self.shown_x = attr_x
self.shown_y = attr_y
self.remove_legend()
if self.scatterplot_item:
self.plot_widget.removeItem(self.scatterplot_item)
if self.scatterplot_item_sel:
self.plot_widget.removeItem(self.scatterplot_item_sel)
for label in self.labels:
self.plot_widget.removeItem(label)
self.labels = []
self.set_axis_title("bottom", "")
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 var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
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.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=np.arange(self.n_points),
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.update_labels()
self.make_legend()
self.view_box.init_history()
self.plot_widget.replot()
min_x, max_x = np.nanmin(x_data), np.nanmax(x_data)
min_y, max_y = np.nanmin(y_data), np.nanmax(y_data)
self.view_box.setRange(
QRectF(min_x, min_y, max_x - min_x, max_y - min_y),
padding=0.025)
self.view_box.tag_history()
开发者ID:VesnaT,项目名称:orange3,代码行数:68,代码来源:owscatterplotgraph.py
示例9: update_data
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)
self.labels = []
self.set_axis_title("bottom", "")
self.set_axis_title("left", "")
if self.scaled_data is None or not len(self.scaled_data):
self.valid_data = None
self.selection = 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],
also_class_if_exists=False)
x_data, y_data = self.get_xy_data_positions(
attr_x, attr_y, self.valid_data)
self.n_points = len(x_data)
if reset_view:
min_x, max_x = np.nanmin(x_data), np.nanmax(x_data)
min_y, max_y = np.nanmin(y_data), np.nanmax(y_data)
self.view_box.setRange(
QRectF(min_x, min_y, max_x - min_x, max_y - min_y),
padding=0.025)
self.view_box.init_history()
self.view_box.tag_history()
[min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
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 var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
if self.should_draw_density():
rgb_data = [pen.color().getRgb()[:3] for pen in color_data]
self.density_img = classdensity.class_density_image(min_x, max_x, min_y, max_y, self.resolution,
x_data, y_data, rgb_data)
self.plot_widget.addItem(self.density_img)
data_indices = np.flatnonzero(self.valid_data)
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data
)
self.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=data_indices,
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
self.update_labels()
self.make_legend()
self.plot_widget.replot()
开发者ID:pombredanne,项目名称:orange3,代码行数:83,代码来源:owscatterplotgraph.py
示例10: update_data
def update_data(self, attr_x, attr_y, reset_view=True):
self.master.Warning.missing_coords.clear()
self.master.Information.missing_coords.clear()
self._clear_plot_widget()
if self.shown_y != attr_y:
# 'reset' the axis text width estimation. Without this the left
# axis tick labels space only ever expands
yaxis = self.plot_widget.getAxis("left")
yaxis.textWidth = 30
self.shown_x, self.shown_y = attr_x, attr_y
if attr_x not in self.data.domain or attr_y not in self.data.domain:
data = self.sparse_to_dense()
self.set_data(data)
if self.jittered_data is None or not len(self.jittered_data):
self.valid_data = None
else:
self.valid_data = self.get_valid_list([attr_x, attr_y])
if not np.any(self.valid_data):
self.valid_data = None
if self.valid_data is None:
self.selection = None
self.n_points = 0
self.master.Warning.missing_coords(
self.shown_x.name, self.shown_y.name)
return
x_data, y_data = self.get_xy_data_positions(
attr_x, attr_y, self.valid_data)
self.n_points = len(x_data)
if reset_view:
min_x, max_x = np.nanmin(x_data), np.nanmax(x_data)
min_y, max_y = np.nanmin(y_data), np.nanmax(y_data)
self.view_box.setRange(
QRectF(min_x, min_y, max_x - min_x, max_y - min_y),
padding=0.025)
self.view_box.init_history()
self.view_box.tag_history()
[min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
for axis, var in (("bottom", attr_x), ("left", attr_y)):
self.set_axis_title(axis, var)
if var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
if self.should_draw_density():
rgb_data = [pen.color().getRgb()[:3] for pen in color_data]
self.density_img = classdensity.class_density_image(
min_x, max_x, min_y, max_y, self.resolution,
x_data, y_data, rgb_data)
self.plot_widget.addItem(self.density_img)
self.data_indices = np.flatnonzero(self.valid_data)
if len(self.data_indices) != len(self.data):
self.master.Information.missing_coords(
self.shown_x.name, self.shown_y.name)
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=self.data_indices,
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data
)
self.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=self.data_indices,
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
if self.show_reg_line:
_x_data = self.data.get_column_view(self.shown_x)[0]
_y_data = self.data.get_column_view(self.shown_y)[0]
_x_data = _x_data[self.valid_data]
_y_data = _y_data[self.valid_data]
assert _x_data.size
assert _y_data.size
self.draw_regression_line(
_x_data, _y_data, np.min(_x_data), np.max(_y_data))
self.update_labels()
self.make_legend()
self.plot_widget.replot()
开发者ID:randxie,项目名称:orange3,代码行数:94,代码来源:owscatterplotgraph.py
示例11: OWScatterPlotGraph
#.........这里部分代码省略.........
min_x, max_x = np.nanmin(x_data), np.nanmax(x_data)
min_y, max_y = np.nanmin(y_data), np.nanmax(y_data)
self.view_box.setRange(
QRectF(min_x, min_y, max_x - min_x, max_y - min_y),
padding=0.025)
self.view_box.init_history()
self.view_box.tag_history()
[min_x, max_x], [min_y, max_y] = self.view_box.viewRange()
for axis, var in (("bottom", attr_x), ("left", attr_y)):
self.set_axis_title(axis, var)
if var.is_discrete:
self.set_labels(axis, get_variable_values_sorted(var))
else:
self.set_labels(axis, None)
color_data, brush_data = self.compute_colors()
color_data_sel, brush_data_sel = self.compute_colors_sel()
size_data = self.compute_sizes()
shape_data = self.compute_symbols()
if self.should_draw_density():
rgb_data = [pen.color().getRgb()[:3] for pen in color_data]
self.density_img = classdensity.class_density_image(
min_x, max_x, min_y, max_y, self.resolution,
x_data, y_data, rgb_data)
self.plot_widget.addItem(self.density_img)
self.data_indices = np.flatnonzero(self.valid_data)
if len(self.data_indices) != len(self.data):
self.master.Information.missing_coords(
self.shown_x.name, self.shown_y.name)
self.scatterplot_item = ScatterPlotItem(
x=x_data, y=y_data, data=self.data_indices,
symbol=shape_data, size=size_data, pen=color_data, brush=brush_data
)
self.scatterplot_item_sel = ScatterPlotItem(
x=x_data, y=y_data, data=self.data_indices,
symbol=shape_data, size=size_data + SELECTION_WIDTH,
pen=color_data_sel, brush=brush_data_sel
)
self.plot_widget.addItem(self.scatterplot_item_sel)
self.plot_widget.addItem(self.scatterplot_item)
self.scatterplot_item.selected_points = []
self.scatterplot_item.sigClicked.connect(self.select_by_click)
if self.show_reg_line:
_x_data = self.data.get_column_view(self.shown_x)[0]
_y_data = self.data.get_column_view(self.shown_y)[0]
_x_data = _x_data[self.valid_data]
_y_data = _y_data[self.valid_data]
assert _x_data.size
assert _y_data.size
self.draw_regression_line(
_x_data, _y_data, np.min(_x_data), np.max(_y_data))
self.update_labels()
self.make_legend()
self.plot_widget.replot()
def draw_regression_line(self, x_data, y_data, min_x, max_x):
if self.show_reg_line and self.can_draw_regresssion_line():
slope, intercept, rvalue, _, _ = linregress(x_data, y_data)
start_y = min_x * slope + intercept
end_y = max_x * slope + intercept
开发者ID:randxie,项目名称:orange3,代码行数:67,代码来源:owscatterplotgraph.py
示例12: OWScatterPlotGraph
#.........这里部分代码省略.........
if self.scatterplot_item:
self.plot_widget.removeItem(self.scatterplot_item)
for label in self.labels:
self.plot_widget.removeItem(label)
self.labels = []
self.tooltip_data = []
self.set_axis_title("bottom", "")
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()
开发者ID:CHANAYA,项目名称:orange3,代码行数:67,代码来源:owscatterplotgraph.py
示例13: OWLinearProjection
#.........这里部分代码省略.........
if not variables:
return
coords = [self._get_data(var) for var in variables]
coords = numpy.vstack(coords)
p, N = coords.shape
assert N == len(self.data), p == len(variables)
axes = linproj.defaultaxes(len(variables))
assert axes.shape == (2, p)
mask = ~numpy.logical_or.reduce(numpy.isnan(coords), axis=0)
coords = coords[:, mask]
X, Y = numpy.dot(axes, coords)
X = plotutils.normalized(X)
Y = plotutils.normalized(Y)
pen_data, brush_data = self._color_data(mask)
size_data = self._size_data(mask)
shape_data = self._shape_data(mask)
if self.jitter_value > 0:
value = [0, 0.01, 0.1, 0.5, 1, 2][self.jitter_value]
rstate = numpy.random.RandomState(0)
jitter_x = (rstate.random_sample(X.shape) * 2 - 1) * value / 100
rstate = numpy.random.RandomState(1)
jitter_y = (rstate.random_sample(Y.shape) * 2 - 1) * value / 100
X += jitter_x
Y += jitter_y
self._item = ScatterPlotItem(
X, Y,
pen=pen_data,
brush=brush_data,
size=size_data,
shape=shape_data,
antialias=True,
data=numpy.arange(len(self.data))[mask]
)
self._item._mask = mask
self.viewbox.addItem(self._item)
for i, axis in enumerate(axes.T):
axis_item = AxisItem(line=QLineF(0, 0, axis[0], axis[1]),
label=variables[i].name)
self.viewbox.addItem(axis_item)
self.viewbox.setRange(QtCore.QRectF(-1.05, -1.05, 2.1, 2.1))
self._update_legend()
def _color_data(self, mask=None):
color_var = self.color_var()
if color_var is not None:
color_data = self._get_data(color_var)
if color_var.is_continuous:
color_data = plotutils.continuous_colors(color_data)
else:
color_data = plotutils.discrete_colors(
color_data, len(color_var.values)
)
if mask is not None:
color_data = color_data[mask]
开发者ID:fdion,项目名称:orange3,代码行数:67,代码来源:owlinearprojection.py
示例14: MSQtCanvas
class MSQtCanvas(QWidget, MSDialogController):
"""
DONE:the current peak is not updated while the user press up and down key on the treeView
TODO: think about a mjor redesign of those classes
"""
#linePlotted = pyqtSignal(object, str)
#lineRemoved = pyqtSignal(object)
def __init__(self, data, title, flags="chroma", parent=None, **k):
QWidget.__init__(self, parent)
MSDialogController.__init__(self, 0, parent)
self.model = self.qApp.model
self.view = self.qApp.view
self.data=data
self.title=title
self.flags=flags
if self.flags == 'peak':
if self.acTree not in (self.view.treeView_2, self.view.treeView_3):
print "Unknown Error"
return
idx=self.acTree.selectedIndexes()[0]
s = qApp.instance().dockControl.currentSample[1 if self.acTree is self.view.treeView_2 else 2]
if s is None:
print "unknow error"
return
values = map(float, idx.data().toString().split('/')[:2])
self.currentPeak = s.peakAt(*values)
#connection to update the selected Peak object
self.connect(self.acTree, SIGNAL("changedLine"), self.updateCurrentPeak)
self.minX, self.maxX, self.maxY = [0] * 3
#if flags != 'peak':
# self.minX, self.maxX, self.maxY = self.getMax()
self.pw = PlotWidget(self.minX, self.maxX, self.maxY, parent=self, **k)#parent=self,
#self.pw.setAttribute(Qt.WA_DeleteOnClose)#plotItem.setAttribute(Qt.WA_PaintOnScreen & Qt.WA_PaintUnclipped)
if k.get('antialiased', False):
self.pw.setRenderHint(0x01)#antialiasing i suppose
self.pw.setTitle(title)
self.pw.updateGrid()
self._setupUi()
self.connect(self, SIGNAL('linePlotted'), self.updateContextMenu)
self.connect(self.view.sampleTableView, SIGNAL("disHighlightRequested(QModelIndex)"), self.disHighlightOne)
self.connect(self.view.sampleTableView, SIGNAL("highlightRequested(QModelIndex)"), self.highlight)
self.connect(self.view.sampleTableView, SIGNAL("noHighlightRequested()"), self.disHighlight)
self.connect(self.view.ppmEditer, SIGNAL('valueChanged(double)'), self.redrawAll)
self.drawnItems = {}
self.trashItems=[]#why unecessary? nope to collect annotation stuff
self.textLabels = []
self.pixmaps = []
self.dataPoints = None
self._plotting(self.data)#initial plotting
def getMax(self):
localXmin =[]
localXmax = []
localYmax = []
for el in self.data:
if el is None:
continue
localXmin.append(min_f(el.x_data))
localXmax.append(max_f(el.x_data))
localYmax.append(max_l(el.y_data))
return min_f(np.array(localXmin)), max_f(np.array(localXmax)), max_l(np.array(localYmax))
def _plotting(self, data):
"""
refactor this shit
c = Line(chrom.x_data, chrom.y_data,
QColor.fromRgbF(*(self.ref.sample.color+(.7,))),
parent=self.pw.plotItem.vb,
scene=self.pw.scene())
#test scatter plot
self.scatter = ScatterPlotItem(x=chrom.x_data, y=chrom.y_data)
self.pw.addDataItem(self.scatter)
self.scatter.sigClicked.connect(self.requestSpectra)
"""
if self.flags == 'peak':
self.connect(self.pw.plotItem.vb, SIGNAL('showDiffOrSpectra(PyQt_PyObject)'), self.drawSpectra)
self.ref = sorted([e for e in data if e is not None], key=lambda x:x.height)[-1]
ppm = self.view.ppmEditer.value() if self.view.usePpm.isChecked() else self.ref.sample.ppm
chrom = self.ref.sample.massExtraction(self.ref.mass(),
ppm,
asChromatogram=True)
#show labels
#.........这里部分代码省略.........
开发者ID:jerkos,项目名称:metms,代码行数:101,代码来源:MetMplCanvas.py
注:本文中的pyqtgraph.graphicsItems.ScatterPlotItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论