def histogram( self, data, bins=None, logscale=None, title="", color=None, xaxis="bottom", yaxis="left", ): """ Make 1D Histogram `plot item` (:py:class:`guiqwt.histogram.HistogramItem` object) * data (1D NumPy array) * bins: number of bins (int) * logscale: Y-axis scale (bool) """ basename = _("Histogram") histparam = HistogramParam(title=basename, icon="histogram.png") curveparam = CurveParam(_("Curve"), icon="curve.png") curveparam.read_config(CONF, "histogram", "curve") if not title: global HISTOGRAM_COUNT HISTOGRAM_COUNT += 1 title = make_title(basename, HISTOGRAM_COUNT) curveparam.label = title if color is not None: curveparam.line.color = color if bins is not None: histparam.n_bins = bins if logscale is not None: histparam.logscale = logscale return self.phistogram(data, curveparam, histparam, xaxis, yaxis)
def mcurve(self, *args, **kwargs): """ Make a curve `plot item` based on MATLAB-like syntax (may returns a list of curves if data contains more than one signal) (:py:class:`guiqwt.curve.CurveItem` object) Example:: mcurve(x, y, 'r+') """ x, y, style = self.__get_arg_triple_plot(args) if isinstance(y, ndarray): y = [y] if not isinstance(style, list): style = [style] if len(y) > len(style): style = [style[0]]*len(y) basename = _("Curve") curves = [] for yi, stylei in zip(y, style): param = CurveParam(title=basename, icon='curve.png') if "label" in kwargs: param.label = kwargs.pop("label") else: global CURVE_COUNT CURVE_COUNT += 1 param.label = make_title(basename, CURVE_COUNT) update_style_attr(stylei, param) curves.append(self.pcurve(x, yi, param, **kwargs)) if len(curves) == 1: return curves[0] else: return curves
def mcurve(self, *args, **kwargs): """ Make a curve `plot item` based on MATLAB-like syntax (may returns a list of curves if data contains more than one signal) (:py:class:`guiqwt.curve.CurveItem` object) Example:: mcurve(x, y, 'r+') """ x, y, style = self.__get_arg_triple_plot(args) if isinstance(y, ndarray): y = [y] if not isinstance(style, list): style = [style] if len(y) > len(style): style = [style[0]] * len(y) basename = _("Curve") curves = [] for yi, stylei in zip(y, style): param = CurveParam(title=basename, icon="curve.png") if "label" in kwargs: param.label = kwargs.pop("label") else: global CURVE_COUNT CURVE_COUNT += 1 param.label = make_title(basename, CURVE_COUNT) update_style_attr(stylei, param) curves.append(self.pcurve(x, yi, param, **kwargs)) if len(curves) == 1: return curves[0] else: return curves
def histogram2D(self, X, Y, NX=None, NY=None, logscale=None, title=None, transparent=None, Z=None, computation=-1,interpolation=0): """ Make a 2D Histogram `plot item` (:py:class:`guiqwt.image.Histogram2DItem` object) * X: data (1D array) * Y: data (1D array) * NX: Number of bins along x-axis (int) * NY: Number of bins along y-axis (int) * logscale: Z-axis scale (bool) * title: item title (string) * transparent: enable transparency (bool) """ basename = _("2D Histogram") param = Histogram2DParam(title=basename, icon='histogram2d.png') if NX is not None: param.nx_bins = NX if NY is not None: param.ny_bins = NY if logscale is not None: param.logscale = int(logscale) if title is not None: param.label = title else: global HISTOGRAM2D_COUNT HISTOGRAM2D_COUNT += 1 param.label = make_title(basename, HISTOGRAM2D_COUNT) if transparent is not None: param.transparent = transparent param.computation = computation param.interpolation = interpolation return Histogram2DItem(X, Y, param, Z=Z)
def histogram(self, data, bins=None, logscale=None, title="", color=None, xaxis="bottom", yaxis="left"): """ Make 1D Histogram `plot item` (:py:class:`guiqwt.histogram.HistogramItem` object) * data (1D NumPy array) * bins: number of bins (int) * logscale: Y-axis scale (bool) """ basename = _("Histogram") histparam = HistogramParam(title=basename, icon='histogram.png') curveparam = CurveParam(_("Curve"), icon='curve.png') curveparam.read_config(CONF, "histogram", "curve") if not title: global HISTOGRAM_COUNT HISTOGRAM_COUNT += 1 title = make_title(basename, HISTOGRAM_COUNT) curveparam.label = title if color is not None: curveparam.line.color = color if bins is not None: histparam.n_bins = bins if logscale is not None: histparam.logscale = logscale return self.phistogram(data, curveparam, histparam, xaxis, yaxis)
def __set_image_param(self, param, title, alpha_mask, alpha, interpolation, **kwargs): if title: param.label = title else: global IMAGE_COUNT IMAGE_COUNT += 1 param.label = make_title(_("Image"), IMAGE_COUNT) if alpha_mask is not None: assert isinstance(alpha_mask, bool) param.alpha_mask = alpha_mask if alpha is not None: assert 0.0 <= alpha <= 1.0 param.alpha = alpha interp_methods = {"nearest": 0, "linear": 1, "antialiasing": 5} param.interpolation = interp_methods[interpolation] for key, val in list(kwargs.items()): if val is not None: setattr(param, key, val)
def curve(self, x, y, title="", color=None, linestyle=None, linewidth=None, marker=None, markersize=None, markerfacecolor=None, markeredgecolor=None, shade=None, curvestyle=None, baseline=None, xaxis="bottom", yaxis="left"): """ Make a curve `plot item` from x, y, data (:py:class:`guiqwt.curve.CurveItem` object) * x: 1D NumPy array * y: 1D NumPy array * color: curve color name * linestyle: curve line style (MATLAB-like string or "SolidLine", "DashLine", "DotLine", "DashDotLine", "DashDotDotLine", "NoPen") * linewidth: line width (pixels) * marker: marker shape (MATLAB-like string or "Cross", "Ellipse", "Star1", "XCross", "Rect", "Diamond", "UTriangle", "DTriangle", "RTriangle", "LTriangle", "Star2", "NoSymbol") * markersize: marker size (pixels) * markerfacecolor: marker face color name * markeredgecolor: marker edge color name * shade: 0 <= float <= 1 (curve shade) * curvestyle: "Lines", "Sticks", "Steps", "Dots", "NoCurve" * baseline (float: default=0.0): the baseline is needed for filling the curve with a brush or the Sticks drawing style. * xaxis, yaxis: X/Y axes bound to curve Example:: curve(x, y, marker='Ellipse', markerfacecolor='#ffffff') which is equivalent to (MATLAB-style support):: curve(x, y, marker='o', markerfacecolor='w') """ basename = _("Curve") param = CurveParam(title=basename, icon='curve.png') if not title: global CURVE_COUNT CURVE_COUNT += 1 title = make_title(basename, CURVE_COUNT) self.__set_param(param, title, color, linestyle, linewidth, marker, markersize, markerfacecolor, markeredgecolor, shade, curvestyle, baseline) return self.pcurve(x, y, param, xaxis, yaxis)
def __set_image_param(self, param, title, alpha_mask, alpha, interpolation, **kwargs): if title: param.label = title else: global IMAGE_COUNT IMAGE_COUNT += 1 param.label = make_title(_("Image"), IMAGE_COUNT) if alpha_mask is not None: assert isinstance(alpha_mask, bool) param.alpha_mask = alpha_mask if alpha is not None: assert (0.0 <= alpha <= 1.0) param.alpha = alpha interp_methods = {'nearest': 0, 'linear': 1, 'antialiasing': 5} param.interpolation = interp_methods[interpolation] for key, val in list(kwargs.items()): if val is not None: setattr(param, key, val)
def info_label(self, anchor, comps, title=None): """ Make an info label `plot item` (:py:class:`guiqwt.label.DataInfoLabel` object) """ basename = _("Computation") param = LabelParam(basename, icon="label.png") param.read_config(CONF, "plot", "info_label") if title is not None: param.label = title else: global LABEL_COUNT LABEL_COUNT += 1 param.label = make_title(basename, LABEL_COUNT) param.abspos = True param.absg = anchor param.anchor = anchor c = ANCHOR_OFFSETS[anchor] param.xc, param.yc = c return DataInfoLabel(param, comps)
def info_label(self, anchor, comps, title=None): """ Make an info label `plot item` (:py:class:`guiqwt.label.DataInfoLabel` object) """ basename = _("Computation") param = LabelParam(basename, icon='label.png') param.read_config(CONF, "plot", "info_label") if title is not None: param.label = title else: global LABEL_COUNT LABEL_COUNT += 1 param.label = make_title(basename, LABEL_COUNT) param.abspos = True param.absg = anchor param.anchor = anchor c = ANCHOR_OFFSETS[anchor] param.xc, param.yc = c return DataInfoLabel(param, comps)
def merror(self, *args, **kwargs): """ Make an errorbar curve `plot item` based on MATLAB-like syntax (:py:class:`guiqwt.curve.ErrorBarCurveItem` object) Example:: mcurve(x, y, 'r+') """ x, y, dx, dy, style = self.__get_arg_triple_errorbar(args) basename = _("Curve") curveparam = CurveParam(title=basename, icon="curve.png") errorbarparam = ErrorBarParam(title=_("Error bars"), icon="errorbar.png") if "label" in kwargs: curveparam.label = kwargs["label"] else: global CURVE_COUNT CURVE_COUNT += 1 curveparam.label = make_title(basename, CURVE_COUNT) update_style_attr(style, curveparam) errorbarparam.color = curveparam.line.color return self.perror(x, y, dx, dy, curveparam, errorbarparam)
def label(self, text, g, c, anchor, title=""): """ Make a label `plot item` (:py:class:`guiqwt.label.LabelItem` object) * text: label text (string) * g: position in plot coordinates (tuple) or relative position (string) * c: position in canvas coordinates (tuple) * anchor: anchor position in relative position (string) * title: label name (optional) Examples:: make.label("Relative position", (x[0], y[0]), (10, 10), "BR") make.label("Absolute position", "R", (0,0), "R") """ basename = _("Label") param = LabelParamWithContents(basename, icon="label.png") param.read_config(CONF, "plot", "label") if title: param.label = title else: global LABEL_COUNT LABEL_COUNT += 1 param.label = make_title(basename, LABEL_COUNT) if isinstance(g, tuple): param.abspos = False param.xg, param.yg = g else: param.abspos = True param.absg = g if c is None: c = ANCHOR_OFFSETS[anchor] param.xc, param.yc = c param.anchor = anchor return LabelItem(text, param)
def label(self, text, g, c, anchor, title=""): """ Make a label `plot item` (:py:class:`guiqwt.label.LabelItem` object) * text: label text (string) * g: position in plot coordinates (tuple) or relative position (string) * c: position in canvas coordinates (tuple) * anchor: anchor position in relative position (string) * title: label name (optional) Examples:: make.label("Relative position", (x[0], y[0]), (10, 10), "BR") make.label("Absolute position", "R", (0,0), "R") """ basename = _("Label") param = LabelParamWithContents(basename, icon='label.png') param.read_config(CONF, "plot", "label") if title: param.label = title else: global LABEL_COUNT LABEL_COUNT += 1 param.label = make_title(basename, LABEL_COUNT) if isinstance(g, tuple): param.abspos = False param.xg, param.yg = g else: param.abspos = True param.absg = g if c is None: c = ANCHOR_OFFSETS[anchor] param.xc, param.yc = c param.anchor = anchor return LabelItem(text, param)
def error( self, x, y, dx, dy, title="", color=None, linestyle=None, linewidth=None, errorbarwidth=None, errorbarcap=None, errorbarmode=None, errorbaralpha=None, marker=None, markersize=None, markerfacecolor=None, markeredgecolor=None, shade=None, curvestyle=None, baseline=None, xaxis="bottom", yaxis="left", ): """ Make an errorbar curve `plot item` (:py:class:`guiqwt.curve.ErrorBarCurveItem` object) * x: 1D NumPy array * y: 1D NumPy array * dx: None, or scalar, or 1D NumPy array * dy: None, or scalar, or 1D NumPy array * color: curve color name * linestyle: curve line style (MATLAB-like string or attribute name from the :py:class:`PyQt4.QtCore.Qt.PenStyle` enum (i.e. "SolidLine" "DashLine", "DotLine", "DashDotLine", "DashDotDotLine" or "NoPen") * linewidth: line width (pixels) * marker: marker shape (MATLAB-like string or attribute name from the :py:class:`PyQt4.Qwt5.QwtSymbol.Style` enum (i.e. "Cross", "Ellipse", "Star1", "XCross", "Rect", "Diamond", "UTriangle", "DTriangle", "RTriangle", "LTriangle", "Star2" or "NoSymbol") * markersize: marker size (pixels) * markerfacecolor: marker face color name * markeredgecolor: marker edge color name * shade: 0 <= float <= 1 (curve shade) * curvestyle: attribute name from the :py:class:`PyQt4.Qwt5.QwtPlotCurve.CurveStyle` enum (i.e. "Lines", "Sticks", "Steps", "Dots" or "NoCurve") * baseline (float: default=0.0): the baseline is needed for filling the curve with a brush or the Sticks drawing style. * xaxis, yaxis: X/Y axes bound to curve Example:: error(x, y, None, dy, marker='Ellipse', markerfacecolor='#ffffff') which is equivalent to (MATLAB-style support):: error(x, y, None, dy, marker='o', markerfacecolor='w') """ basename = _("Curve") curveparam = CurveParam(title=basename, icon="curve.png") errorbarparam = ErrorBarParam(title=_("Error bars"), icon="errorbar.png") if not title: global CURVE_COUNT CURVE_COUNT += 1 curveparam.label = make_title(basename, CURVE_COUNT) self.__set_param( curveparam, title, color, linestyle, linewidth, marker, markersize, markerfacecolor, markeredgecolor, shade, curvestyle, baseline, ) errorbarparam.color = curveparam.line.color if errorbarwidth is not None: errorbarparam.width = errorbarwidth if errorbarcap is not None: errorbarparam.cap = errorbarcap if errorbarmode is not None: errorbarparam.mode = errorbarmode if errorbaralpha is not None: errorbarparam.alpha = errorbaralpha return self.perror(x, y, dx, dy, curveparam, errorbarparam, xaxis, yaxis)
def error(self, x, y, dx, dy, title="", color=None, linestyle=None, linewidth=None, errorbarwidth=None, errorbarcap=None, errorbarmode=None, errorbaralpha=None, marker=None, markersize=None, markerfacecolor=None, markeredgecolor=None, shade=None, curvestyle=None, baseline=None, xaxis="bottom", yaxis="left"): """ Make an errorbar curve `plot item` (:py:class:`guiqwt.curve.ErrorBarCurveItem` object) * x: 1D NumPy array * y: 1D NumPy array * dx: None, or scalar, or 1D NumPy array * dy: None, or scalar, or 1D NumPy array * color: curve color name * linestyle: curve line style (MATLAB-like string or attribute name from the :py:class:`PyQt4.QtCore.Qt.PenStyle` enum (i.e. "SolidLine" "DashLine", "DotLine", "DashDotLine", "DashDotDotLine" or "NoPen") * linewidth: line width (pixels) * marker: marker shape (MATLAB-like string or attribute name from the :py:class:`PyQt4.Qwt5.QwtSymbol.Style` enum (i.e. "Cross", "Ellipse", "Star1", "XCross", "Rect", "Diamond", "UTriangle", "DTriangle", "RTriangle", "LTriangle", "Star2" or "NoSymbol") * markersize: marker size (pixels) * markerfacecolor: marker face color name * markeredgecolor: marker edge color name * shade: 0 <= float <= 1 (curve shade) * curvestyle: attribute name from the :py:class:`PyQt4.Qwt5.QwtPlotCurve.CurveStyle` enum (i.e. "Lines", "Sticks", "Steps", "Dots" or "NoCurve") * baseline (float: default=0.0): the baseline is needed for filling the curve with a brush or the Sticks drawing style. * xaxis, yaxis: X/Y axes bound to curve Example:: error(x, y, None, dy, marker='Ellipse', markerfacecolor='#ffffff') which is equivalent to (MATLAB-style support):: error(x, y, None, dy, marker='o', markerfacecolor='w') """ basename = _("Curve") curveparam = CurveParam(title=basename, icon='curve.png') errorbarparam = ErrorBarParam(title=_("Error bars"), icon='errorbar.png') if not title: global CURVE_COUNT CURVE_COUNT += 1 curveparam.label = make_title(basename, CURVE_COUNT) self.__set_param(curveparam, title, color, linestyle, linewidth, marker, markersize, markerfacecolor, markeredgecolor, shade, curvestyle, baseline) errorbarparam.color = curveparam.line.color if errorbarwidth is not None: errorbarparam.width = errorbarwidth if errorbarcap is not None: errorbarparam.cap = errorbarcap if errorbarmode is not None: errorbarparam.mode = errorbarmode if errorbaralpha is not None: errorbarparam.alpha = errorbaralpha return self.perror(x, y, dx, dy, curveparam, errorbarparam, xaxis, yaxis)