def testFcn(self):
        x = np.linspace(0, 100, 1000)

        y = (np.random.rand(len(x)) - 0.5).cumsum()

        curve = make.curve(x, y, "ab", "b")
        range = make.range(0, 5)

        disp2 = make.computations(
            range,
            "TL",
            [
                (curve, "min=%.5f", lambda x, y: y.min()),
                (curve, "max=%.5f", lambda x, y: y.max()),
                (curve, "avg=%.5f", lambda x, y: y.mean()),
            ],
        )
        legend = make.legend("TR")
        items = [curve, range, disp2, legend]

        win = CurveDialog(edit=False, toolbar=True, parent=self)
        plot = win.get_plot()
        for item in items:
            plot.add_item(item)
        win.show()
Exemple #2
0
def plot( *items ):
    win = CurveDialog(edit=False, toolbar=True)
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    win.show()
    win.exec_()
Exemple #3
0
def taurusTrendMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    parser.add_option("-x", "--x-axis-mode", dest="x_axis_mode", default='d', metavar="t|d|e",
                      help="interpret X values as timestamps (t), time deltas (d) or event numbers (e). Accepted values: t|d|e")
    parser.add_option("-b", "--buffer", dest="max_buffer_size", default='16384',
                      help="maximum number of values to be plotted (when reached, the oldest values will be discarded)")
    parser.add_option("-a", "--use-archiving",
                      action="store_true", dest="use_archiving", default=False)
    parser.add_option("--demo", action="store_true", dest="demo",
                      default=False, help="show a demo of the widget")
    app = TaurusApplication(
        cmd_line_parser=parser, app_name="taurusplot2", app_version=taurus.Release.version)
    args = app.get_command_line_args()
    options = app.get_command_line_options()

    # check & process options
    stackModeMap = dict(t='datetime', d='deltatime', e='event')
    if options.x_axis_mode.lower() not in stackModeMap:
        parser.print_help(sys.stderr)
        sys.exit(1)

    stackMode = stackModeMap[options.x_axis_mode.lower()]

    if options.demo:
        args.append('eval:rand()')

    w = CurveDialog(edit=False, toolbar=True, wintitle="Taurus Trend")

    # set archiving
    if options.use_archiving:
        raise NotImplementedError('Archiving support is not yet implemented')
        w.setUseArchiving(True)

    w.add_tool(HRangeTool)
    # w.add_tool(TaurusCurveChooserTool)
    # w.add_tool(TimeAxisTool)

    if len(args) == 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    plot = w.get_plot()
    for a in args:
        item = TaurusTrendItem(stackMode=stackMode,
                               buffersize=int(options.max_buffer_size))
        plot.add_item(item)
        item.setModel(a)

    w.show()
    sys.exit(app.exec_())
Exemple #4
0
def hist(data):
	"""Plots histogram"""
	
	win = CurveDialog(edit=False, toolbar=True, wintitle="Histogram test")
	plot = win.get_plot()
	plot.add_item(make.histogram(data))
	win.show()
	win.exec_()
Exemple #5
0
def test():
    """Test"""
    from numpy.random import normal
    data = normal(0, 1, (2000, ))
    win = CurveDialog(edit=False, toolbar=True, wintitle="Histogram test")
    plot = win.get_plot()
    plot.add_item(make.histogram(data))
    win.show()
    win.exec_()
Exemple #6
0
def testTool(tool):
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog

    app = TaurusApplication()
    win = CurveDialog(edit=False, toolbar=True)
    win.add_tool(tool)
    win.show()
    win.exec_()
Exemple #7
0
def plot(*items):
    win = CurveDialog(edit=False, toolbar=True, wintitle="CurveDialog test",
                      options=dict(title="Title", xlabel="xlabel",
                                   ylabel="ylabel"))
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #8
0
def plot(*items):
    win = CurveDialog(edit=False, toolbar=True, wintitle="CurveDialog test",
                      options=dict(title="Temperaturverlauf", xlabel="Zeit [s]",
                                   ylabel="Temperatur [\xb0C]"))
    win.add_tool(HRangeTool)
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    #plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #9
0
def taurusCurveMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    from taurus.qt.qtgui.extra_guiqwt.tools import TaurusCurveChooserTool, TimeAxisTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    app = TaurusApplication(cmd_line_parser=parser,
                            app_name="taurusplot2",
                            app_version=taurus.Release.version)
    args = app.get_command_line_args()

    win = CurveDialog(edit=False,
                      toolbar=True,
                      wintitle="TaurusPlot2",
                      options=dict(title="", xlabel="xlabel", ylabel="ylabel"))
    win.add_tool(HRangeTool)
    win.add_tool(TaurusCurveChooserTool)
    win.add_tool(TimeAxisTool)

    plot = win.get_plot()

    for a in args:
        mx_my = a.split('|')
        n = len(mx_my)
        if n == 1:
            mx, my = None, mx_my[0]
        elif n == 2:
            mx, my = mx_my
        else:
            print "Invalid model: %s\n" % mx_my
            parser.print_help(sys.stderr)
            sys.exit(1)
        # cycle colors
        style = make.style.next()
        color = style[0]
        linestyle = style[1:]
        plot.add_item(
            make.curve(mx, my, color=color, linestyle=linestyle, linewidth=2))

    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #10
0
def plot(*items):
    win = CurveDialog(
        edit=False,
        toolbar=True,
        wintitle="CurveDialog test",
        options=dict(title="Title", xlabel="xlabel", ylabel="ylabel"),
    )
    plot = win.get_plot()
    for item in items:
        plot.add_item(item)
    # plot.set_axis_font("left", QFont("Courier"))
    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #11
0
def get_point( *args ):
    """
    Plot curves and return selected point(s) coordinates
    """
    win = CurveDialog(_("Select one point then press OK to accept"), edit=True)
    default = win.add_tool(SelectPointTool, title="Test", on_active_item=True,
                           mode="create", end_callback=test_function)
    default.activate()
    plot = win.get_plot()
    for cx, cy in args:
        item = make.mcurve(cx, cy)
        plot.add_item(item)
    plot.set_active_item(item)
    win.show()
    if win.exec_():
        return default.get_coordinates()
Exemple #12
0
def taurusCurveMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    from taurus.qt.qtgui.extra_guiqwt.tools import TaurusCurveChooserTool, TimeAxisTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    app = TaurusApplication(
        cmd_line_parser=parser, app_name="taurusplot2", app_version=taurus.Release.version)
    args = app.get_command_line_args()

    win = CurveDialog(edit=False, toolbar=True, wintitle="TaurusPlot2",
                      options=dict(title="", xlabel="xlabel", ylabel="ylabel"))
    win.add_tool(HRangeTool)
    win.add_tool(TaurusCurveChooserTool)
    win.add_tool(TimeAxisTool)

    plot = win.get_plot()

    for a in args:
        mx_my = a.split('|')
        n = len(mx_my)
        if n == 1:
            mx, my = None, mx_my[0]
        elif n == 2:
            mx, my = mx_my
        else:
            print "Invalid model: %s\n" % mx_my
            parser.print_help(sys.stderr)
            sys.exit(1)
        # cycle colors
        style = make.style.next()
        color = style[0]
        linestyle = style[1:]
        plot.add_item(make.curve(mx, my, color=color,
                                 linestyle=linestyle, linewidth=2))

    win.get_itemlist_panel().show()
    plot.set_items_readonly(False)
    win.show()
    win.exec_()
Exemple #13
0
def test():
    """Test"""
    # -- Create QApplication
    import guidata
    _app = guidata.qapplication()
    # --
    import numpy as np
    x = np.linspace(-10, 10, 200)
    y = x*np.exp(-x)
    item = make.curve(x, y, color="b")
    
    win = CurveDialog()
    plot = win.get_plot()
    plot.add_item(item)
    plot.set_axis_direction("left", True)
    plot.set_axis_direction("bottom", True)
    win.show()
    win.exec_()
Exemple #14
0
def get_point(*args):
    """
    Plot curves and return selected point(s) coordinates
    """
    win = CurveDialog(_("Select one point then press OK to accept"), edit=True)
    default = win.add_tool(SelectPointTool,
                           title="Test",
                           on_active_item=True,
                           mode="create",
                           end_callback=test_function)
    default.activate()
    plot = win.get_plot()
    for cx, cy in args:
        item = make.mcurve(cx, cy)
        plot.add_item(item)
    plot.set_active_item(item)
    win.show()
    if win.exec_():
        return default.get_coordinates()
Exemple #15
0
    def testFcn(self):
        x = np.linspace(0, 100, 1000)

        y = (np.random.rand(len(x)) - 0.5).cumsum()

        curve = make.curve(x, y, "ab", "b")
        range = make.range(0, 5)

        disp2 = make.computations(range, "TL",
                                  [(curve, "min=%.5f", lambda x, y: y.min()),
                                   (curve, "max=%.5f", lambda x, y: y.max()),
                                   (curve, "avg=%.5f", lambda x, y: y.mean())])
        legend = make.legend("TR")
        items = [curve, range, disp2, legend]

        win = CurveDialog(edit=False, toolbar=True, parent=self)
        plot = win.get_plot()
        for item in items:
            plot.add_item(item)
        win.show()
Exemple #16
0
def test():
    """Test"""
    # -- Create QApplication
    import guidata
    _app = guidata.qapplication()
    # --
    import numpy as np
    x = np.linspace(1, 10, 200)
    y = np.exp(-x)
    y[0] = 0
    item = make.curve(x, y, color="b")
    item = make.error(x, y, None, y*.23)
    
    win = CurveDialog()
    plot = win.get_plot()
    plot.set_axis_scale("left", "log")
    plot.set_axis_scale("bottom", "log")
#    plot.set_axis_limits("left", 4.53999297625e-05, 22026.4657948)
    plot.add_item(item)
    win.show()
    win.exec_()
Exemple #17
0
def taurusTrendMain():
    from taurus.qt.qtgui.extra_guiqwt.builder import make
    from taurus.qt.qtgui.application import TaurusApplication
    from guiqwt.plot import CurveDialog
    from guiqwt.tools import HRangeTool
    import taurus.core.util.argparse
    import sys

    parser = taurus.core.util.argparse.get_taurus_parser()
    parser.set_usage("%prog [options] [<model1> [<model2>] ...]")
    parser.set_description("a taurus application for plotting 1D data sets")
    parser.add_option(
        "-x",
        "--x-axis-mode",
        dest="x_axis_mode",
        default='d',
        metavar="t|d|e",
        help=
        "interpret X values as timestamps (t), time deltas (d) or event numbers (e). Accepted values: t|d|e"
    )
    parser.add_option(
        "-b",
        "--buffer",
        dest="max_buffer_size",
        default='16384',
        help=
        "maximum number of values to be plotted (when reached, the oldest values will be discarded)"
    )
    parser.add_option("-a",
                      "--use-archiving",
                      action="store_true",
                      dest="use_archiving",
                      default=False)
    parser.add_option("--demo",
                      action="store_true",
                      dest="demo",
                      default=False,
                      help="show a demo of the widget")
    app = TaurusApplication(cmd_line_parser=parser,
                            app_name="taurusplot2",
                            app_version=taurus.Release.version)
    args = app.get_command_line_args()
    options = app.get_command_line_options()

    # check & process options
    stackModeMap = dict(t='datetime', d='deltatime', e='event')
    if options.x_axis_mode.lower() not in stackModeMap:
        parser.print_help(sys.stderr)
        sys.exit(1)

    stackMode = stackModeMap[options.x_axis_mode.lower()]

    if options.demo:
        args.append('eval:rand()')

    w = CurveDialog(edit=False, toolbar=True, wintitle="Taurus Trend")

    # set archiving
    if options.use_archiving:
        raise NotImplementedError('Archiving support is not yet implemented')
        w.setUseArchiving(True)

    w.add_tool(HRangeTool)
    # w.add_tool(TaurusCurveChooserTool)
    # w.add_tool(TimeAxisTool)

    if len(args) == 0:
        parser.print_help(sys.stderr)
        sys.exit(1)

    plot = w.get_plot()
    for a in args:
        item = TaurusTrendItem(stackMode=stackMode,
                               buffersize=int(options.max_buffer_size))
        plot.add_item(item)
        item.setModel(a)

    w.show()
    sys.exit(app.exec_())
import datetime


class stockDataCollector(object):
    def __init__(self, stockName):
        super(stockDataCollector, self).__init__()
        self.stockName = stockName
        self.stockDataFrame = 0
        self.start = datetime.datetime(1900, 1, 1)
        self.end = datetime.date.today()

    def _getStockdata(self):
        self.stockDataFrame = data.DataReader(self.stockName, 'yahoo',
                                              self.start, self.end)
        return self.stockDataFrame


if __name__ == '__main__':
    _app = guidata.qapplication()
    main = stockDataCollector("AAPL")
    sro = main._getStockdata()
    x1 = sro.index
    x2 = x1.Date
    y1 = sro['Close'].values
    curve = make.curve(x1, y1, "ab", "b")
    gWindow = CurveDialog(edit=False, toolbar=False)
    plotw = gWindow.get_plot()
    plotw.add_item(curve)
    gWindow.show()
    gWindow.exec_()
class CentralWidget(QSplitter):
    def __init__(self, parent, toolbar):
        QSplitter.__init__(self, parent)
        # Define csvModel 提供csv處理的Model
        self.csvmodel = CsvFileModel()
        self.selectedRow = -1

        #connect error message
        self.connect(self.csvmodel, SIGNAL("ERROR_NOT_NONAME_ARRAY"),
                     partial(self.showErrorMessage, "NOT_NONAME_ARRAY"))

        # 連接csvlist與製造ImageListWithProperties
        imagelistwithproperties = ImageListWithProperties(self)

        self.addWidget(imagelistwithproperties)
        self.csvlist = imagelistwithproperties.csvlist
        self.connect(imagelistwithproperties, SIGNAL("PLOT"),
                     partial(self.csvmodel.plotCSV, self.csvlist))
        self.connect(imagelistwithproperties, SIGNAL("REMOVE"),
                     partial(self.csvmodel.removeCSV, self.csvlist))
        self.connect(imagelistwithproperties, SIGNAL("EXTRACT_ARRAY"),
                     partial(self.csvmodel.extractArray, self.csvlist))

        # View signal connect
        self.connect(self.csvlist,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     partial(self.csvmodel.plotCSV, self.csvlist))
        self.connect(self.csvlist, SIGNAL("currentRowChanged(int)"),
                     self.current_item_changed)
        self.connect(self.csvlist, SIGNAL("itemSelectionChanged()"),
                     self.selection_changed)

        self.properties = imagelistwithproperties.properties
        self.connect(self.properties, SIGNAL("apply_button_clicked()"),
                     self.properties_changed)

        # CsvModel signal connect
        self.connect(self.csvmodel, SIGNAL("CSV_UPDATED"), self.refresh_list)
        self.connect(self.csvmodel, SIGNAL("ARRAY_UPDATED"),
                     self.refresh_array_list)

        # 製造ArrayListWithProperties
        self.arraylistwithproperties = ArrayListWithProperties(self)
        self.arraylist = self.arraylistwithproperties.arraylist
        self.addWidget(self.arraylistwithproperties)
        self.connect(self.arraylistwithproperties, SIGNAL("PASTE_NO_NAME"),
                     partial(self.csvmodel.pasteArrayNoName, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PASTE_WITH_NAME"),
                     partial(self.csvmodel.pasteArrayWithName, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT"),
                     partial(self.csvmodel.plotArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("MODIFY_ARRAY"),
                     partial(self.csvmodel.modifyArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT_SCATTER"),
                     partial(self.csvmodel.plotScatter, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("PLOT_HISTOGRAM"),
                     self.plotHist)
        self.connect(self.arraylistwithproperties, SIGNAL("REMOVE"),
                     partial(self.csvmodel.removeArray, self.arraylist))
        self.connect(self.arraylistwithproperties, SIGNAL("OPEN_CURVEDIALOG"),
                     self.openCurveDialog)

        #arraylist action signal
        self.connect(self.arraylist, SIGNAL("currentRowChanged(int)"),
                     self.array_current_item_changed)
        self.arrayproperties = self.arraylistwithproperties.properties
        self.connect(self.arrayproperties, SIGNAL("apply_button_clicked()"),
                     self.array_properties_changed)
        self.connect(self.arraylist, SIGNAL("itemSelectionChanged()"),
                     self.array_selection_changed)
        self.connect(self.arraylist,
                     SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     partial(self.csvmodel.plotArray, self.arraylist))

        # 設定基本properity
        self.setContentsMargins(10, 10, 10, 10)
        self.setOrientation(Qt.Vertical)
        self.setStretchFactor(0, 0)
        self.setStretchFactor(1, 1)
        self.setHandleWidth(10)
        self.setSizes([1, 2])

    def refresh_list(self):
        self.csvlist.clear()
        for csv in self.csvmodel.csvName:
            self.csvlist.addItem(csv)

    def refresh_array_list(self):
        self.arraylist.clear()
        for array in self.csvmodel.arrayName:
            self.arraylist.addItem(array)

    def selection_changed(self):
        """Image list: selection changed, make right properity box selectable"""
        row = self.csvlist.currentRow()
        self.properties.setDisabled(row == -1)

    def array_selection_changed(self):
        """Array list: selection changed, make right properity box selectable"""
        row = self.arraylist.currentRow()
        self.arrayproperties.setDisabled(row == -1)

    def current_item_changed(self, row):
        """Image list: current image changed"""
        #csvdata, csvname = self.csvmodel.csvData[row], self.csvmodel.csvName[row]
        update_dataset(self.properties.dataset, self.csvmodel.csv[row])
        self.properties.get()

    def array_current_item_changed(self, row):
        """Image list: current image changed"""
        #csvdata, csvname = self.csvmodel.csvData[row], self.csvmodel.csvName[row]
        update_dataset(self.arrayproperties.dataset, self.csvmodel.array[row])
        self.arrayproperties.get()

    def plotHist(self):
        self.histWindow = HistogramWindow(
            self.csvmodel.arrayData[self.arraylist.currentRow()],
            self.csvmodel.arrayName[self.arraylist.currentRow()])
        self.histWindow.show()

    def openCurveDialog(self):
        self.curvedialog = CurveDialog(edit=False,
                                       toolbar=True,
                                       wintitle="CurveDialog",
                                       options=dict(title="Title",
                                                    xlabel="xlabel",
                                                    ylabel="ylabel"))
        plot = self.curvedialog.get_plot()
        for array in self.csvmodel.array:
            item = make.curve(np.array(range(array.data.size)),
                              array.data,
                              color="b")
            plot.add_item(item)
        plot.set_axis_font("left", QFont("Courier"))
        self.curvedialog.get_itemlist_panel().show()
        plot.set_items_readonly(False)
        self.curvedialog.show()
#
#==============================================================================
#     def lut_range_changed(self):
#         row = self.imagelist.currentRow()
#         self.lut_ranges[row] = self.item.get_lut_range()
#==============================================================================

#==============================================================================
#     def show_data(self, data, lut_range=None):
#         plot = self.imagewidget.plot
#         if self.item is not None:
#             self.item.set_data(data)
#             if lut_range is None:
#                 lut_range = self.item.get_lut_range()
#             self.imagewidget.set_contrast_range(*lut_range)
#             self.imagewidget.update_cross_sections()
#         else:
#             self.item = make.image(data)
#             plot.add_item(self.item, z=0)
#         plot.replot()
#==============================================================================

    def properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        row = self.csvlist.currentRow()
        csvdata = self.csvmodel.csv[row]
        update_dataset(csvdata, self.properties.dataset)
        self.csvmodel.csvName[row] = csvdata.title
        self.refresh_list()
        #self.show_data(image.data)

    def array_properties_changed(self):
        """The properties 'Apply' button was clicked: updating image"""
        print("apply button click")
        row = self.arraylist.currentRow()
        arraydata = self.csvmodel.array[row]
        update_dataset(arraydata, self.arrayproperties.dataset)
        self.csvmodel.arrayName[row] = arraydata.title
        self.refresh_array_list()


#==============================================================================
#     def add_image(self, image):
#         self.images.append(image)
#         #self.lut_ranges.append(None)
#         self.refresh_list()
#         self.imagelist.setCurrentRow(len(self.images)-1)
#         plot = self.imagewidget.plot
#         plot.do_autoscale()
#==============================================================================

#def add_csv_from_file(self, filename):

    def showErrorMessage(self, message):
        print("error")
        if message == "NOT_NONAME_ARRAY":
            QMessageBox.about(
                self, "Error message box",
                "Please make sure the data in the clip board is an array")