本文整理汇总了Python中Orange.widgets.visualize.owlinearprojection.LegendItem.addItem方法的典型用法代码示例。如果您正苦于以下问题:Python LegendItem.addItem方法的具体用法?Python LegendItem.addItem怎么用?Python LegendItem.addItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.visualize.owlinearprojection.LegendItem
的用法示例。
在下文中一共展示了LegendItem.addItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OWMDS
# 需要导入模块: from Orange.widgets.visualize.owlinearprojection import LegendItem [as 别名]
# 或者: from Orange.widgets.visualize.owlinearprojection.LegendItem import addItem [as 别名]
#.........这里部分代码省略.........
emb_y = jitter(emb_y, jitter_factor, rstate=667)
if self.connected_pairs and self.__draw_similar_pairs:
if self._similar_pairs is None:
# This code requires storing lower triangle of X (n x n / 2
# doubles), n x n / 2 * 2 indices to X, n x n / 2 indices for
# argsort result. If this becomes an issue, it can be reduced to
# n x n argsort indices by argsorting the entire X. Then we
# take the first n + 2 * p indices. We compute their coordinates
# i, j in the original matrix. We keep those for which i < j.
# n + 2 * p will suffice to exclude the diagonal (i = j). If the
# number of those for which i < j is smaller than p, we instead
# take i > j. Among those that remain, we take the first p.
# Assuming that MDS can't show so many points that memory could
# become an issue, I preferred using simpler code.
m = self._effective_matrix
n = len(m)
p = (n * (n - 1) // 2 * self.connected_pairs) // 100
indcs = numpy.triu_indices(n, 1)
sorted = numpy.argsort(m[indcs])[:p]
self._similar_pairs = fpairs = numpy.empty(2 * p, dtype=int)
fpairs[::2] = indcs[0][sorted]
fpairs[1::2] = indcs[1][sorted]
for i in range(int(len(emb_x[self._similar_pairs]) / 2)):
item = QtGui.QGraphicsLineItem(
emb_x[self._similar_pairs][i * 2],
emb_y[self._similar_pairs][i * 2],
emb_x[self._similar_pairs][i * 2 + 1],
emb_y[self._similar_pairs][i * 2 + 1]
)
pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(204, 204, 204)), 2)
pen.setCosmetic(True)
item.setPen(pen)
self.plot.addItem(item)
data = numpy.arange(size)
self._scatter_item = item = ScatterPlotItem(
x=emb_x, y=emb_y,
pen=self._pen_data, brush=self._brush_data, symbol=self._shape_data,
size=self._size_data, data=data,
antialias=True
)
self.plot.addItem(item)
if self._label_data is not None:
if self.label_only_selected:
if self._selection_mask is not None:
for (x, y), text_item, selected \
in zip(self.embedding, self._label_data,
self._selection_mask):
if selected:
self.plot.addItem(text_item)
text_item.setPos(x, y)
else:
for (x, y), text_item in zip(self.embedding, self._label_data):
self.plot.addItem(text_item)
text_item.setPos(x, y)
self._legend_item = LegendItem()
viewbox = self.plot.getViewBox()
self._legend_item.setParentItem(self.plot.getViewBox())
self._legend_item.setZValue(viewbox.zValue() + 10)
self._legend_item.restoreAnchor(self.legend_anchor)
color_var = shape_var = None
color_index = self.cb_color_value.currentIndex()
示例2: OWDistributions
# 需要导入模块: from Orange.widgets.visualize.owlinearprojection import LegendItem [as 别名]
# 或者: from Orange.widgets.visualize.owlinearprojection.LegendItem import addItem [as 别名]
class OWDistributions(widget.OWWidget):
name = "Distributions"
description = "Display value distributions of a data feature in a graph."
icon = "icons/Distribution.svg"
priority = 100
inputs = [InputSignal("Data", Orange.data.Table, "set_data",
doc="Set the input data set")]
settingsHandler = settings.DomainContextHandler(
match_values=settings.DomainContextHandler.MATCH_VALUES_ALL)
#: Selected variable index
variable_idx = settings.ContextSetting(-1)
#: Selected group variable
groupvar_idx = settings.ContextSetting(0)
relative_freq = settings.Setting(False)
disc_cont = settings.Setting(False)
smoothing_index = settings.Setting(5)
show_prob = settings.ContextSetting(0)
want_graph = True
ASH_HIST = 50
bins = [ 2, 3, 4, 5, 8, 10, 12, 15, 20, 30, 50 ]
smoothing_facs = list(reversed([ 0.1, 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2, 4, 6, 10 ]))
def __init__(self):
super().__init__()
self.data = None
self.distributions = None
self.contingencies = None
self.var = self.cvar = None
varbox = gui.widgetBox(self.controlArea, "Variable")
self.varmodel = itemmodels.VariableListModel()
self.groupvarmodel = []
self.varview = QtGui.QListView(
selectionMode=QtGui.QListView.SingleSelection)
self.varview.setSizePolicy(
QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.varview.setModel(self.varmodel)
self.varview.setSelectionModel(
itemmodels.ListSingleSelectionModel(self.varmodel))
self.varview.selectionModel().selectionChanged.connect(
self._on_variable_idx_changed)
varbox.layout().addWidget(self.varview)
box = gui.widgetBox(self.controlArea, "Precision")
gui.separator(self.controlArea, 4, 4)
box2 = gui.widgetBox(box, orientation="horizontal")
self.l_smoothing_l = gui.widgetLabel(box2, "Smooth")
gui.hSlider(box2, self, "smoothing_index",
minValue=0, maxValue=len(self.smoothing_facs) - 1,
callback=self._on_set_smoothing, createLabel=False)
self.l_smoothing_r = gui.widgetLabel(box2, "Precise")
self.cb_disc_cont = gui.checkBox(
gui.indentedBox(box, sep=4),
self, "disc_cont", "Bin continuous variables",
callback=self._on_groupvar_idx_changed)
box = gui.widgetBox(self.controlArea, "Group by")
self.icons = gui.attributeIconDict
self.groupvarview = gui.comboBox(box, self, "groupvar_idx",
callback=self._on_groupvar_idx_changed, valueType=str,
contentsLength=12)
box2 = gui.indentedBox(box, sep=4)
self.cb_rel_freq = gui.checkBox(
box2, self, "relative_freq", "Show relative frequencies",
callback=self._on_relative_freq_changed)
gui.separator(box2)
self.cb_prob = gui.comboBox(
box2, self, "show_prob", label="Show probabilities",
orientation="horizontal",
callback=self._on_relative_freq_changed)
plotview = pg.PlotWidget(background=None)
self.mainArea.layout().addWidget(plotview)
w = QtGui.QLabel()
w.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
self.mainArea.layout().addWidget(w, Qt.AlignCenter)
self.plot = pg.PlotItem()
self.plot.hideButtons()
plotview.setCentralItem(self.plot)
self.plot_prob = pg.ViewBox()
self.plot.hideAxis('right')
self.plot.scene().addItem(self.plot_prob)
self.plot.getAxis("right").linkToView(self.plot_prob)
self.plot.getAxis("right").setLabel("Probability")
self.plot_prob.setZValue(10)
self.plot_prob.setXLink(self.plot)
self.update_views()
self.plot.vb.sigResized.connect(self.update_views)
#.........这里部分代码省略.........
示例3: OWMDS
# 需要导入模块: from Orange.widgets.visualize.owlinearprojection import LegendItem [as 别名]
# 或者: from Orange.widgets.visualize.owlinearprojection.LegendItem import addItem [as 别名]
#.........这里部分代码省略.........
size_data = stress(self.embedding, self._effective_matrix.X)
size_data = scale(size_data)
size_data = MinPointSize + size_data * point_size
elif have_data and self.size_index > 0:
size_var = self.sizevar_model[self.size_index]
size_data = column(self.data, size_var)
size_data = scale(size_data)
size_data = MinPointSize + size_data * point_size
else:
size_data = point_size
if self._label_data is None:
if have_data and self.label_index > 0:
label_var = self.labelvar_model[self.label_index]
label_data = column(self.data, label_var)
label_data = [label_var.repr_val(val) for val in label_data]
label_items = [pg.TextItem(text, anchor=(0.5, 0))
for text in label_data]
elif have_matrix_transposed and self.labelvar_model[self.label_index] == 'Attribute names':
attr = attributes(self.matrix)
label_items = [pg.TextItem(str(text), anchor=(0.5, 0))
for text in attr]
else:
label_items = None
self._label_data = label_items
self._scatter_item = item = ScatterPlotItem(
x=self.embedding[:, 0], y=self.embedding[:, 1],
pen=self._pen_data, symbol=self._shape_data,
brush=QtGui.QBrush(Qt.transparent),
size=size_data, data=numpy.arange(len(self.data)),
antialias=True
)
self.plot.addItem(item)
if self._label_data is not None:
for (x, y), text_item in zip(self.embedding, self._label_data):
self.plot.addItem(text_item)
text_item.setPos(x, y)
self._legend_item = LegendItem()
self._legend_item.setParentItem(self.plot.getViewBox())
self._legend_item.anchor(*self.legend_anchor)
color_var = shape_var = None
if have_data and 1 <= self.color_index < len(self.colorvar_model):
color_var = self.colorvar_model[self.color_index]
assert isinstance(color_var, Orange.data.Variable)
if have_data and 1 <= self.shape_index < len(self.shapevar_model):
shape_var = self.shapevar_model[self.shape_index]
assert isinstance(shape_var, Orange.data.Variable)
if shape_var is not None or \
(color_var is not None and color_var.is_discrete):
legend_data = mdsplotutils.legend_data(
color_var, shape_var, plotstyle=mdsplotutils.plotstyle)
for color, symbol, text in legend_data:
self._legend_item.addItem(
ScatterPlotItem(pen=color, brush=color, symbol=symbol,
size=10),
text
)
else:
self._legend_item.hide()
示例4: OWDistributions
# 需要导入模块: from Orange.widgets.visualize.owlinearprojection import LegendItem [as 别名]
# 或者: from Orange.widgets.visualize.owlinearprojection.LegendItem import addItem [as 别名]
#.........这里部分代码省略.........
box = gui.vBox(self.controlArea, "Group by")
self.icons = gui.attributeIconDict
self.groupvarview = gui.comboBox(
box, self, "groupvar_idx",
callback=self._on_groupvar_idx_changed,
valueType=str, contentsLength=12)
box2 = gui.indentedBox(box, sep=4)
self.cb_rel_freq = gui.checkBox(
box2, self, "relative_freq", "Show relative frequencies",
callback=self._on_relative_freq_changed,
tooltip="Normalize probabilities so that probabilities "
"for each group-by value sum to 1.")
gui.separator(box2)
self.cb_prob = gui.comboBox(
box2, self, "show_prob", label="Show probabilities:",
orientation=Qt.Horizontal,
callback=self._on_relative_freq_changed,
tooltip="Show probabilities for a chosen group-by value "
"(at each point probabilities for all group-by values sum to 1).")
self.plotview = pg.PlotWidget(background=None)
self.plotview.setRenderHint(QPainter.Antialiasing)
self.mainArea.layout().addWidget(self.plotview)
w = QLabel()
w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.mainArea.layout().addWidget(w, Qt.AlignCenter)
self.ploti = pg.PlotItem()
self.plot = self.ploti.vb
self.ploti.hideButtons()
self.plotview.setCentralItem(self.ploti)
self.plot_prob = pg.ViewBox()
self.ploti.hideAxis('right')
self.ploti.scene().addItem(self.plot_prob)
self.ploti.getAxis("right").linkToView(self.plot_prob)
self.ploti.getAxis("right").setLabel("Probability")
self.plot_prob.setZValue(10)
self.plot_prob.setXLink(self.ploti)
self.update_views()
self.ploti.vb.sigResized.connect(self.update_views)
self.plot_prob.setRange(yRange=[0, 1])
def disable_mouse(plot):
plot.setMouseEnabled(False, False)
plot.setMenuEnabled(False)
disable_mouse(self.plot)
disable_mouse(self.plot_prob)
self.tooltip_items = []
self.plot.scene().installEventFilter(
HelpEventDelegate(self.help_event, self))
pen = QPen(self.palette().color(QPalette.Text))
for axis in ("left", "bottom"):
self.ploti.getAxis(axis).setPen(pen)
self._legend = LegendItem()
self._legend.setParentItem(self.plot)
self._legend.hide()
self._legend.anchor((1, 0), (1, 0))
def update_views(self):
self.plot_prob.setGeometry(self.plot.sceneBoundingRect())
self.plot_prob.linkedViewChanged(self.plot, self.plot_prob.XAxis)
示例5: OWDistributions
# 需要导入模块: from Orange.widgets.visualize.owlinearprojection import LegendItem [as 别名]
# 或者: from Orange.widgets.visualize.owlinearprojection.LegendItem import addItem [as 别名]
#.........这里部分代码省略.........
distribution.get_distribution(self.data, self.var)
self.display_distribution()
def _density_estimator(self):
if self.cont_est_type == OWDistributions.Hist:
def hist(dist):
h, edges = numpy.histogram(dist[0, :], bins=10,
weights=dist[1, :])
return edges, h
return hist
elif self.cont_est_type == OWDistributions.ASH:
return lambda dist: ash_curve(dist, m=5)
elif self.cont_est_type == OWDistributions.Kernel:
return rect_kernel_curve
def display_distribution(self):
dist = self.distributions
var = self.var
assert len(dist) > 0
self.plot.clear()
bottomaxis = self.plot.getAxis("bottom")
bottomaxis.setLabel(var.name)
self.set_left_axis_name()
if var and var.is_continuous:
bottomaxis.setTicks(None)
curve_est = self._density_estimator()
edges, curve = curve_est(dist)
item = pg.PlotCurveItem()
item.setData(edges, curve, antialias=True, stepMode=True,
fillLevel=0, brush=QtGui.QBrush(Qt.gray),
pen=QtGui.QColor(Qt.white))
self.plot.addItem(item)
else:
bottomaxis.setTicks([list(enumerate(var.values))])
for i, w in enumerate(dist):
geom = QtCore.QRectF(i - 0.33, 0, 0.66, w)
item = DistributionBarItem(geom, [1.0],
[QtGui.QColor(128, 128, 128)])
self.plot.addItem(item)
def _on_relative_freq_changed(self):
self.set_left_axis_name()
if self.cvar and self.cvar.is_discrete:
self.display_contingency()
else:
self.display_distribution()
def display_contingency(self):
"""
Set the contingency to display.
"""
cont = self.contingencies
var, cvar = self.var, self.cvar
assert len(cont) > 0
self.plot.clear()
self._legend.clear()
bottomaxis = self.plot.getAxis("bottom")
bottomaxis.setLabel(var.name)
palette = colorpalette.ColorPaletteGenerator(len(cvar.values))
colors = [palette[i] for i in range(len(cvar.values))]
if var and var.is_continuous: