Пример #1
0
        if msg['msg_type'] == 'stream':
            # stdout/stderr
            # stream names are in msg['content']['name'], if you want to handle
            # them differently
            print("%s: %s" % (topic, msg['content']['text']))
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)


if __name__ == '__main__':
    if len(sys.argv) > 1:
        pattern = sys.argv[1]
    else:
        # This gets the security file for the default profile:
        pattern = 'ipcontroller-client.json'
    cf = find_connection_file(pattern)
    print("Using connection file %s" % cf)
    main(cf)
Пример #2
0
        topic = idents[0].decode('utf8', 'replace')
        if msg['msg_type'] == 'stream':
            # stdout/stderr
            # stream names are in msg['content']['name'], if you want to handle
            # them differently
            print("%s: %s" % (topic, msg['content']['text']))
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)

if __name__ == '__main__':
    if len(sys.argv) > 1:
        pattern = sys.argv[1]
    else:
        # This gets the security file for the default profile:
        pattern = 'ipcontroller-client.json'
    cf = find_connection_file(pattern)
    print("Using connection file %s" % cf)
    main(cf)
Пример #3
0
    def plot_plotly(self, plotly_filename=None, mpl_type=False, xlim=None, ylim=None, title=None, figsize=None,
                    xlabel=None, ylabel=None, fontsize=None, show_legend=True, grid=False):
        """
        Plot data using plotly library in IPython

        :param plotly_filename: name for resulting plot file on server (use unique name, else the same plot will be showen)
        :type plotly_filename: None or str
        :param bool mpl_type: use or not plotly converter from matplotlib (experimental parameter)
        :param xlim: x-axis range
        :param ylim: y-axis range
        :type xlim: None or tuple(x_min, x_max)
        :type ylim: None or tuple(y_min, y_max)
        :param title: title
        :type title: None or str
        :param figsize: figure size
        :type figsize: None or tuple(weight, height)
        :param xlabel: x-axis name
        :type xlabel: None or str
        :param ylabel: y-axis name
        :type ylabel: None or str
        :param fontsize: font size
        :type fontsize: None or int
        :param bool show_legend: show or not labels for plots
        :param bool grid: show grid or not
        """
        import plotly.plotly as py
        from plotly import graph_objs
        from ipykernel import connect

        plotly_filename = self.plotly_filename if plotly_filename is None else plotly_filename
        try:
            connection_file_path = connect.find_connection_file()
            connection_file = os.path.basename(connection_file_path)
            if '-' in connection_file:
                kernel_id = connection_file.split('-', 1)[1].split('.')[0]
            else:
                kernel_id = connection_file.split('.')[0]
        except Exception as e:
            kernel_id = "no_kernel"

        PLOTLY_API_USER, PLOTLY_API_KEY, PLOTLY_USER = self._plotly_config()
        save_name = '{user}_{id}:{name}'.format(user=PLOTLY_USER, id=kernel_id, name=plotly_filename)
        py.sign_in(PLOTLY_API_USER, PLOTLY_API_KEY)

        if mpl_type:
            self.plot(new_plot=True, xlim=xlim, ylim=ylim, title=title, figsize=figsize, xlabel=xlabel, ylabel=ylabel,
                      fontsize=fontsize, grid=grid)
            mpl_fig = plt.gcf()
            update = dict(
                layout=dict(
                    showlegend=show_legend
                ),
                data=[dict(name=leg) for leg in mpl_fig.legends]
            )

            return py.iplot_mpl(mpl_fig, width=self.figsize[0] * 60,
                                update=update,
                                height=self.figsize[1] * 60,
                                filename=save_name,
                                fileopt='overwrite')

        xlabel = self.xlabel if xlabel is None else xlabel
        ylabel = self.ylabel if ylabel is None else ylabel
        title = self.title if title is None else title
        figsize = self.figsize if figsize is None else figsize
        fontsize = self.fontsize if fontsize is None else fontsize

        layout = graph_objs.Layout(yaxis={'title': ylabel, 'ticks': ''}, xaxis={'title': xlabel, 'ticks': ''},
                                   showlegend=show_legend, title=title,
                                   font=graph_objs.Font(family='Courier New, monospace', size=fontsize),
                                   width=figsize[0] * self.PLOTLY_RESIZE,
                                   height=figsize[1] * self.PLOTLY_RESIZE
        )

        fig = self._plot_plotly(layout)

        return py.iplot(fig, width=figsize[0] * self.PLOTLY_RESIZE, height=figsize[1] * self.PLOTLY_RESIZE,
                        filename=save_name)
        topic = idents[0].decode('utf8', 'replace')
        if msg['msg_type'] == 'stream':
            # stdout/stderr
            # stream names are in msg['content']['name'], if you want to handle
            # them differently
            print("{}: {}".format(topic, msg['content']['text']))
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)
        elif msg['msg_type'] == 'error':
            # Python traceback
            c = msg['content']
            print(topic + ':')
            for line in c['traceback']:
                # indent lines
                print('    ' + line)

if __name__ == '__main__':
    if len(sys.argv) > 1:
        pattern = sys.argv[1]
    else:
        # This gets the security file for the default profile:
        pattern = 'ipcontroller-client.json'
    cf = find_connection_file(pattern, profile='ssh')
    print("Using connection file {}".format(cf))
    main(cf)