本文整理汇总了Python中AnyQt.QtGui.QColor类的典型用法代码示例。如果您正苦于以下问题:Python QColor类的具体用法?Python QColor怎么用?Python QColor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QColor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: toggle_node_color_reg
def toggle_node_color_reg(self):
"""Update the node color for regression trees"""
def_color = QColor(192, 192, 255)
if self.regression_colors == self.COL_DEFAULT:
brush = QBrush(def_color.lighter(100))
for node in self.scene.nodes():
node.backgroundBrush = brush
elif self.regression_colors == self.COL_INSTANCE:
max_insts = len(self.model.instances)
for node in self.scene.nodes():
node.backgroundBrush = QBrush(def_color.lighter(
120 - 20 * len(node.node_inst.subset) / max_insts))
elif self.regression_colors == self.COL_MEAN:
minv = np.nanmin(self.dataset.Y)
maxv = np.nanmax(self.dataset.Y)
fact = 1 / (maxv - minv) if minv != maxv else 1
colors = self.scene.colors
for node in self.scene.nodes():
node.backgroundBrush = QBrush(
colors[fact * (node.node_inst.value[0] - minv)])
else:
nodes = list(self.scene.nodes())
variances = [node.node_inst.value[1] for node in nodes]
max_var = max(variances)
for node, var in zip(nodes, variances):
node.backgroundBrush = QBrush(def_color.lighter(
120 - 20 * var / max_var))
self.scene.update()
示例2: __init__
def __init__(self, i, mu1, mu2, sigma1, sigma2, phi, color):
OWPlotItem.__init__(self)
self.outer_box = QGraphicsPolygonItem(self)
self.inner_box = QGraphicsPolygonItem(self)
self.i = i
self.mu1 = mu1
self.mu2 = mu2
self.sigma1 = sigma1
self.sigma2 = sigma2
self.phi = phi
self.twosigmapolygon = QPolygonF([
QPointF(i, mu1 - sigma1), QPointF(i, mu1 + sigma1),
QPointF(i + 1, mu2 + sigma2), QPointF(i + 1, mu2 - sigma2),
QPointF(i, mu1 - sigma1)
])
self.sigmapolygon = QPolygonF([
QPointF(i, mu1 - .5 * sigma1), QPointF(i, mu1 + .5 * sigma1),
QPointF(i + 1, mu2 + .5 * sigma2), QPointF(i + 1, mu2 - .5 * sigma2),
QPointF(i, mu1 - .5 * sigma1)
])
if isinstance(color, tuple):
color = QColor(*color)
color.setAlphaF(.3)
self.outer_box.setBrush(color)
self.outer_box.setPen(QColor(0, 0, 0, 0))
self.inner_box.setBrush(color)
self.inner_box.setPen(color)
示例3: update_profiles_color
def update_profiles_color(self, selection):
color = QColor(self.color)
alpha = LinePlotStyle.UNSELECTED_LINE_ALPHA if not selection \
else LinePlotStyle.UNSELECTED_LINE_ALPHA_SEL
color.setAlpha(alpha)
x, y = self.profiles.getData()
self.profiles.setData(x=x, y=y, pen=self.make_pen(color))
示例4: __updatePen
def __updatePen(self):
self.prepareGeometryChange()
self.__boundingRect = None
if self.__dynamic:
if self.__dynamicEnabled:
color = QColor(0, 150, 0, 150)
else:
color = QColor(150, 0, 0, 150)
normal = QPen(QBrush(color), 2.0)
hover = QPen(QBrush(color.darker(120)), 2.1)
else:
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
hover = QPen(QBrush(QColor("#7D7D7D")), 2.1)
if self.__state & LinkItem.Empty:
pen_style = Qt.DashLine
else:
pen_style = Qt.SolidLine
normal.setStyle(pen_style)
hover.setStyle(pen_style)
if self.hover:
pen = hover
else:
pen = normal
self.curveItem.setPen(pen)
示例5: make_color_legend
def make_color_legend(self):
if self.attr_color is None:
return
use_shape = self.attr_shape == self.get_color()
if self.attr_color.is_discrete:
if not self.legend:
self.create_legend()
palette = self.discrete_palette
for i, value in enumerate(self._get_values(self.attr_color)):
color = QColor(*palette.getRGB(i))
pen = _make_pen(color.darker(self.DarkerValue), 1.5)
color.setAlpha(self.alpha_value if self.subset_indices is None else 255)
brush = QBrush(color)
self.legend.addItem(
ScatterPlotItem(
pen=pen, brush=brush, size=10,
symbol=self.CurveSymbols[i] if use_shape else "o"),
escape(value))
else:
legend = self.color_legend = LegendItem()
legend.setParentItem(self.plot_widget.getViewBox())
legend.restoreAnchor(self.__color_legend_anchor)
label = PaletteItemSample(self.continuous_palette, self.scale)
legend.addItem(label, "")
legend.setGeometry(label.boundingRect())
示例6: toggle_node_color_reg
def toggle_node_color_reg(self):
"""Update the node color for regression trees"""
def_color = QColor(192, 192, 255)
if self.regression_colors == self.COL_DEFAULT:
brush = QBrush(def_color.lighter(100))
for node in self.scene.nodes():
node.backgroundBrush = brush
elif self.regression_colors == self.COL_INSTANCE:
max_insts = len(self.tree_adapter.get_instances_in_nodes(
[self.tree_adapter.root]))
for node in self.scene.nodes():
node_insts = len(self.tree_adapter.get_instances_in_nodes(
[node.node_inst]))
node.backgroundBrush = QBrush(def_color.lighter(
120 - 20 * node_insts / max_insts))
elif self.regression_colors == self.COL_MEAN:
minv = np.nanmin(self.dataset.Y)
maxv = np.nanmax(self.dataset.Y)
fact = 1 / (maxv - minv) if minv != maxv else 1
colors = self.scene.colors
for node in self.scene.nodes():
node_mean = self.tree_adapter.get_distribution(node.node_inst)[0][0]
node.backgroundBrush = QBrush(colors[fact * (node_mean - minv)])
else:
nodes = list(self.scene.nodes())
variances = [self.tree_adapter.get_distribution(node.node_inst)[0][1]
for node in nodes]
max_var = max(variances)
for node, var in zip(nodes, variances):
node.backgroundBrush = QBrush(def_color.lighter(
120 - 20 * var / max_var))
self.scene.update()
示例7: make_color_legend
def make_color_legend(self):
color_index = self.get_color_index()
if color_index == -1:
return
color_var = self.domain[color_index]
use_shape = self.get_shape_index() == color_index
if color_var.is_discrete:
if not self.legend:
self.create_legend()
palette = self.discrete_palette
for i, value in enumerate(color_var.values):
color = QColor(*palette.getRGB(i))
brush = color.lighter(self.DarkerValue)
self.legend.addItem(
ScatterPlotItem(
pen=color, brush=brush, size=10,
symbol=self.CurveSymbols[i] if use_shape else "o"),
escape(value))
else:
legend = self.color_legend = LegendItem()
legend.setParentItem(self.plot_widget.getViewBox())
legend.restoreAnchor(self.__color_legend_anchor)
label = PaletteItemSample(self.continuous_palette, self.scale)
legend.addItem(label, "")
legend.setGeometry(label.boundingRect())
示例8: _get_same_colors
def _get_same_colors(self, subset):
"""
Return the same pen for all points while the brush color depends
upon whether the point is in the subset or not
Args:
subset (np.ndarray): a bool array indicating whether a data point
is in the subset or not (e.g. in the 'Data Subset' signal
in the Scatter plot and similar widgets);
Returns:
(tuple): a list of pens and list of brushes
"""
color = self.plot_widget.palette().color(OWPalette.Data)
pen = [_make_pen(color, 1.5) for _ in range(self.n_shown)]
if subset is not None:
brush = np.where(
subset,
*(QBrush(QColor(*col))
for col in (self.COLOR_SUBSET, self.COLOR_NOT_SUBSET)))
else:
color = QColor(*self.COLOR_DEFAULT)
color.setAlpha(self.alpha_value)
brush = [QBrush(color) for _ in range(self.n_shown)]
return pen, brush
示例9: _get_range_curve
def _get_range_curve(self):
color = QColor(self.color)
color.setAlpha(LinePlotStyle.RANGE_ALPHA)
bottom, top = nanmin(self.y_data, axis=0), nanmax(self.y_data, axis=0)
return pg.FillBetweenItem(
pg.PlotDataItem(x=self.x_data, y=bottom),
pg.PlotDataItem(x=self.x_data, y=top), brush=color
)
示例10: add_points
def add_points():
nonlocal cur, image_token
if image_token != self._image_token:
return
batch = visible[cur:cur + self.N_POINTS_PER_ITER]
batch_lat = lat[batch]
batch_lon = lon[batch]
x, y = self.Projection.latlon_to_easting_northing(batch_lat, batch_lon)
x, y = self.Projection.easting_northing_to_pixel(x, y, zoom, origin, map_pane_pos)
if self._jittering:
dx, dy = self._jittering_offsets[batch].T
x, y = x + dx, y + dy
colors = (self._colorgen.getRGB(self._scaled_color_values[batch]).tolist()
if self._color_attr else
repeat((0xff, 0, 0)))
sizes = self._size_coef * \
(self._sizes[batch] if self._size_attr else np.tile(10, len(batch)))
for x, y, is_selected, size, color, _in_subset in \
zip(x, y, selected[batch], sizes, colors, in_subset[batch]):
pensize2, selpensize2 = (.35, 1.5) if size >= 5 else (.15, .7)
pensize2 *= self._size_coef
selpensize2 *= self._size_coef
size2 = size / 2
if is_selected:
painter.setPen(QPen(QBrush(Qt.green), 2 * selpensize2))
painter.drawEllipse(x - size2 - selpensize2,
y - size2 - selpensize2,
size + selpensize2,
size + selpensize2)
color = QColor(*color)
color.setAlpha(self._opacity)
painter.setBrush(QBrush(color) if _in_subset else Qt.NoBrush)
painter.setPen(QPen(QBrush(color.darker(180)), 2 * pensize2))
painter.drawEllipse(x - size2 - pensize2,
y - size2 - pensize2,
size + pensize2,
size + pensize2)
im.save(self._overlay_image_path, 'PNG')
self.evalJS('markersImageLayer.setUrl("{}#{}"); 0;'
.format(self.toFileURL(self._overlay_image_path),
np.random.random()))
cur += self.N_POINTS_PER_ITER
if cur < len(visible):
QTimer.singleShot(10, add_points)
self._owwidget.progressBarAdvance(100 / n_iters, None)
else:
self._owwidget.progressBarFinished(None)
示例11: _update_shape_legend
def _update_shape_legend(self, labels):
self.shape_legend.clear()
if labels is None or self.scatterplot_item is None:
return
color = QColor(0, 0, 0)
color.setAlpha(self.alpha_value)
for label, symbol in zip(labels, self.CurveSymbols):
self.shape_legend.addItem(
ScatterPlotItem(pen=color, brush=color, size=10, symbol=symbol),
escape(label))
示例12: setWidgetCategory
def setWidgetCategory(self, desc):
"""
Set the widget category.
"""
self.category_description = desc
if desc and desc.background:
background = NAMED_COLORS.get(desc.background, desc.background)
color = QColor(background)
if color.isValid():
self.setColor(color)
示例13: make_shape_legend
def make_shape_legend(self):
if self.attr_shape is None or self.attr_shape == self.get_color():
return
if not self.legend:
self.create_legend()
color = QColor(0, 0, 0)
color.setAlpha(self.alpha_value)
for i, value in enumerate(self._get_values(self.attr_shape)):
self.legend.addItem(
ScatterPlotItem(pen=color, brush=color, size=10,
symbol=self.CurveSymbols[i]), escape(value))
示例14: draw_distributions
def draw_distributions(self):
"""Draw distributions with discrete attributes"""
if not (self.show_distributions and self.data is not None and self.domain.has_discrete_class):
return
class_count = len(self.domain.class_var.values)
class_ = self.domain.class_var
# we create a hash table of possible class values (happens only if we have a discrete class)
if self.domain_contingencies is None:
self.domain_contingencies = dict(
zip([attr for attr in self.domain if attr.is_discrete],
get_contingencies(self.data, skipContinuous=True)))
self.domain_contingencies[class_] = get_contingency(self.data, class_, class_)
max_count = max([contingency.max() for contingency in self.domain_contingencies.values()] or [1])
sorted_class_values = get_variable_values_sorted(self.domain.class_var)
for axis_idx, attr_idx in enumerate(self.attribute_indices):
attr = self.domain[attr_idx]
if attr.is_discrete:
continue
contingency = self.domain_contingencies[attr]
attr_len = len(attr.values)
# we create a hash table of variable values and their indices
sorted_variable_values = get_variable_values_sorted(attr)
# create bar curve
for j in range(attr_len):
attribute_value = sorted_variable_values[j]
value_count = contingency[:, attribute_value]
for i in range(class_count):
class_value = sorted_class_values[i]
color = QColor(*self.colors[i])
color.setAlpha(self.alpha_value)
width = float(value_count[class_value] * 0.5) / float(max_count)
y_off = float(1.0 + 2.0 * j) / float(2 * attr_len)
height = 0.7 / float(class_count * attr_len)
y_low_bottom = y_off + float(class_count * height) / 2.0 - i * height
curve = PolygonCurve(QPen(color),
QBrush(color),
xData=[axis_idx, axis_idx + width,
axis_idx + width, axis_idx],
yData=[y_low_bottom, y_low_bottom, y_low_bottom - height,
y_low_bottom - height],
tooltip=attr.name)
curve.attach(self)
示例15: refresh_integral_markings
def refresh_integral_markings(dis, markings_list, curveplot):
for m in markings_list:
if m in curveplot.markings:
curveplot.remove_marking(m)
markings_list.clear()
def add_marking(a):
markings_list.append(a)
curveplot.add_marking(a)
for di in dis:
if di is None:
continue # nothing to draw
color = QColor(di.get("color", "red"))
for el in di["draw"]:
if el[0] == "curve":
bs_x, bs_ys, penargs = el[1]
curve = pg.PlotCurveItem()
curve.setPen(pg.mkPen(color=QColor(color), **penargs))
curve.setZValue(10)
curve.setData(x=bs_x, y=bs_ys[0])
add_marking(curve)
elif el[0] == "fill":
(x1, ys1), (x2, ys2) = el[1]
phigh = pg.PlotCurveItem(x1, ys1[0], pen=None)
plow = pg.PlotCurveItem(x2, ys2[0], pen=None)
color = QColor(color)
color.setAlphaF(0.5)
cc = pg.mkBrush(color)
pfill = pg.FillBetweenItem(plow, phigh, brush=cc)
pfill.setZValue(9)
add_marking(pfill)
elif el[0] == "line":
(x1, y1), (x2, y2) = el[1]
line = pg.PlotCurveItem()
line.setPen(pg.mkPen(color=QColor(color), width=4))
line.setZValue(10)
line.setData(x=[x1[0], x2[0]], y=[y1[0], y2[0]])
add_marking(line)
elif el[0] == "dot":
(x, ys) = el[1]
dot = pg.ScatterPlotItem(x=x, y=ys[0])
dot.setPen(pg.mkPen(color=QColor(color), width=5))
dot.setZValue(10)
add_marking(dot)