python类display()的实例源码

drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_movie(line, cell=None):
    toks = shlex.split(line)
    skip = 0
    publish = False
    display_id = None
    caption = None
    cptr = None;
    for i in range(len(toks)):
        if skip > 0:
            skip = skip-1
            continue
        tok = toks[i]
        if tok == "-publish":
            publish = True
        elif tok == "-caption":
            skip = 1
            caption = toks[i+1]
        elif tok == "-capture":
            skip = 1
            cptr = toks[i+1]
        elif tok == "-display":
            skip = 1
            display_id = toks[i+1]

    return Idv.make_movie(publish, caption, display_id=display_id, capture=cptr)
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def view_url_clicked(b):
        DrilsdownUI.do_display(HTML("<a target=ramadda href=" + b.url + ">" + b.name + "</a>"))
        display(IFrame(src=b.url, width=800, height=400))
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def publish_notebook(extra=None):
        # If we do this then the Javascript object shows up in the notebook
        # js = Javascript('IPython.notebook.save_checkpoint();')
        # display(js)
        file = Idv.getname()
        if file is None:
            return
        isl = '<isl><publish file="' + file + '"/></isl>'
        DrilsdownUI.status("Make sure you do 'File->Save and Checkpoint'. Check your IDV to publish the file")
        result = Idv.run_isl(isl);
        if not result.ok():
            print("Publication failed")
            return
        if result.get_results().strip()!="":
            print("Publication successful")
            print("URL: " + result.get_results())
            return
        print("Publication failed")
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def export_data(filename=None, display_id=None, load_data = False):
        DrilsdownUI.status("Exporting data ...")
        extra = ""
        if display_id is not None:
            extra += ' display="' + display_id + '" '
        if filename is  None:
            f = NamedTemporaryFile(suffix='.gif', delete=False) 
            filename = f.name;
        isl = '<isl><export file="' + f.name + '"' \
            + extra + '/></isl>'
        result = Idv.run_isl(isl)
        if not result.ok():
            return;
        if load_data:
            placeholder = false;
            #                return load_data(filename);
            # img = '<img src="data:image/gif;base64,{0}">'
        DrilsdownUI.status("data exported to: " + filename)
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def do_list(self, dir=None, display=False, label="Entries"):
        """make a list of RamaddaEntry objects that are children of the given entryId"""
        if dir is None:
            dir = self.dir
        files = os.listdir(dir)
        entries = []
        prefix = dir+"/"
        if prefix == "./":
            prefix = ""
        for i in range(len(files)):
            if files[i].startswith(".") is not True:
                entries.append(FileEntry(self, prefix + files[i]))

        if display:
            self.display_entries(label, entries)
        else:
            return entries
dfa.py 文件源码 项目:revex 作者: lucaswiman 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def live_subgraph(self):  # type: () -> nx.MultiDiGraph
        """
        Returns the graph of "live" states for this graph, i.e. the start state
        together with states that may be involved in positively matching a string
        (reachable from the start node and an ancestor of an accepting node).

        This is intended for display purposes, only showing the paths which
        might lead to an accepting state, or just the start state if no such
        paths exist.
        """
        graph = self.as_multidigraph
        accepting_states = {
            node for node in graph.node if graph.node[node]['accepting']
        }

        # Add a "sink" node with an in-edge from every accepting state. This is
        # is solely done because the networkx API makes it easier to find the
        # ancestor of a node than a set of nodes.
        sink = object()
        graph.add_node(sink)
        for state in accepting_states:
            graph.add_edge(state, sink)

        live_states = {self.start} | (nx.ancestors(graph, sink) & nx.descendants(graph, self.start))
        return graph.subgraph(live_states)
__init__.py 文件源码 项目:cube_browser 作者: SciTools 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def display(self):
        # XXX: Ideally, we might want to register an IPython display hook.
        self.on_change(None)
        IPython.display.display(self.form)
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def make_image(line, cell=None):

#    toks = line.split(" ")
    toks = shlex.split(line);
    skip = 0
    publish = False
    caption = None
    display_id = None
    cptr = None;
    for i in range(len(toks)):
        if skip > 0:
            skip = skip-1
            continue
        tok = toks[i].strip()
        if tok == "":
            continue
        if tok == "-publish":
            publish = True
        elif tok == "-caption":
            skip = 1
            caption = toks[i+1]
        elif tok == "-capture":
            skip = 1
            cptr = toks[i+1]
        elif tok == "-display":
            skip = 1
            display_id = toks[i+1]
        elif tok == "-help":
            print("%make_image <-display displayid> <-caption caption> <-publish>")
            return
        else:
            print("Unknown argument:" + tok)
            print("%make_image <-display displayid> <-caption caption> <-publish>")
            return

    DrilsdownUI.do_display(Idv.make_image(publish, caption, display_id=display_id, display=False, capture=cptr))
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def do_display(comp):
        """Call this to display a component that can later be cleared with the Clear button"""
        display(comp)
        DrilsdownUI.displayedItems.append(comp)
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def make_image(publish=False, caption=None, display=True, display_id=None, capture=None):
        return Idv.make_imageOrMovie(True, publish, caption, display, display_id, capture)
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def do_list(self, url=None, display=False, label="Entries"):
        """make a list of RamaddaEntry objects that are children of the given entryId"""
        if url is None:
            url = self.url
        catalog = read_url(url)
        root = ET.fromstring(catalog)
        entries = []
        for child in root:
            # print("child:" + child.tag)
            self.get_entries(root, url, child, entries)

        if display:
            self.display_entries(label, entries)
        else:
            return entries
drilsdown.py 文件源码 项目:ipython-IDV 作者: Unidata 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def do_list(self, entry_id=None, display=False, label="Entries"):
        """make a list of RamaddaEntry objects that are children of the given entry_id"""
        if entry_id is None:
            entry_id = self.entryId
        csv = read_url(self.make_url("/entry/show?entryid=" + entry_id
                                     + "&output=default.csv&escapecommas=true&fields="
                                       "name,id,type,icon,url,size&orderby=name"))
        entries = self.make_entries(csv)
        if display:
            self.display_entries(label, entries)
        else:
            return entries
save_and_load.py 文件源码 项目:RFHO 作者: lucfra 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def save_fig(name, root_dir=None, notebook_mode=True, default_overwrite=False, extension='pdf', **savefig_kwargs):
    if root_dir is None: root_dir = os.getcwd()
    directory = check_or_create_dir(join_paths(root_dir, FOLDER_NAMINGS['PLOTS_DIR']),
                                    notebook_mode=notebook_mode)

    filename = join_paths(directory, '%s.%s' % (name, extension))  # directory + '/%s.pdf' % name
    if not default_overwrite and os.path.isfile(filename):
        # if IPython is not None:
        #     IPython.display.display(tuple(IFrame(filename, width=800, height=600)))  # FIXME not working!
        overwrite = input('A file named %s already exists. Overwrite (Leave string empty for NO!)?' % filename)
        if not overwrite:
            print('No changes done.')
            return
    plt.savefig(filename, **savefig_kwargs)
    # print('file saved')
dfa.py 文件源码 项目:revex 作者: lucaswiman 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _draw(self, full=False):  # pragma: no cover
        # type: (bool) -> None
        """
        Hack to draw the graph and open it in preview or display in an ipython
        notebook (if running).
        """
        import os, sys, tempfile, shutil
        if full:
            graph = self.as_multidigraph
        else:
            graph = self.live_subgraph

        invisible_start_node = object()
        graph.add_node(invisible_start_node, attr_dict={'label': ''}, color='white')
        graph.add_edge(invisible_start_node, self.start, attr_dict={'label': ' start'})

        if 'ipykernel' in sys.modules:
            import IPython.display
            directory = tempfile.mkdtemp()
            dotpath = os.path.join(directory, 'out.dot')
            pngpath = os.path.join(directory, 'out.png')
            try:
                nx.drawing.nx_agraph.write_dot(graph, dotpath)
                os.system(
                    'dot -Tpng {dotpath} -o {pngpath}'.format(**locals()))
                with open(pngpath, 'rb') as f:  # type: ignore
                    IPython.display.display(IPython.display.Image(data=f.read()))
            finally:
                shutil.rmtree(directory)
        elif sys.platform == 'darwin':
            nx.drawing.nx_agraph.write_dot(graph, '/tmp/foo_%s.dot' % id(graph))
            os.system(
                'dot -Tpng /tmp/foo_{0}.dot -o /tmp/foo_{0}.png'.format(id(graph)))
            os.system('open /tmp/foo_{0}.png'.format(id(graph)))
        else:
            raise NotImplementedError(
                'See https://github.com/lucaswiman/revex/issues/19. '
                'Patches welcome!')
api.py 文件源码 项目:papermill 作者: nteract 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def record(name, value):
    """
    Records the value as part of the executing cell's output to be retrieved
    during inspection.

    Args:
        name (str): Name of the value
        value: The value to record.

    """
    # IPython.display.display takes a tuple of objects as first parameter
    # `http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display`
    ip_display(({RECORD_OUTPUT_TYPE: {name: value}},), raw=True)
api.py 文件源码 项目:papermill 作者: nteract 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def display(name, obj):
    """
    Displays an object with the reference 'name'.

    Args:
        name (str): Name of the output.
        obj: An object that can be displayed in the notebook.

    """
    data, metadata = IPython.core.formatters.format_display_data(obj)
    metadata['papermill'] = dict(name=name)
    ip_display(data, metadata=metadata, raw=True)
__init__.py 文件源码 项目:cube_browser 作者: SciTools 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, plots):
        """
        Compiles non-axis coordinates into sliders, the values from which are
        used to reconstruct plots upon movement of slider.

        Args:

        * plot
            cube_browser plot instance to display with slider.

        """
        if not isinstance(plots, Iterable):
            plots = [plots]
        self.plots = plots

        # Mapping of coordinate/alias name to axis.
        self._axis_by_name = {}
        # Mapping of cube-id to shared cache.
        self._cache_by_cube_id = {}
        # Mapping of plot-id to coordinate/alias name.
        self._names_by_plot_id = {}
        # Mapping of coordinate/alias name to plots.
        self._plots_by_name = {}
        self._build_mappings()

        self._slider_by_name = {}
        self._name_by_slider_id = {}
        if self._axis_by_name:
            name_len = max([len(name) for name in self._axis_by_name])
        children = []
        for axis in self._axis_by_name.values():
            if hasattr(axis, 'coord') and axis.coord.units.is_time_reference():
                pairs = [(axis.coord.units.num2date(axis.coord.points[i]), i)
                         for i in range(axis.size)]
            elif hasattr(axis, 'coord'):
                pairs = [(axis.coord.points[i], i) for i in range(axis.size)]
            else:
                pairs = [(i, i) for i in range(axis.size)]
            options = OrderedDict(pairs)
            slider = ipywidgets.SelectionSlider(options=options)
            slider.observe(self.on_change, names='value')
            self._slider_by_name[axis.name] = slider
            self._name_by_slider_id[id(slider)] = axis.name
            # Explicitly control the slider label in order to avoid
            # fix width widget description label wrapping issues.
            # XXX: Adjust px/em scale-factor dynamically based on font-size.
            scale_factor = .65
            width = u'{}em'.format(int(name_len * scale_factor))
            label = ipywidgets.Label(axis.name, padding=u'0.3em', width=width)
            hbox = ipywidgets.HBox(children=[label, slider])
            children.append(hbox)

        # Layout the sliders in a consitent order.
        self.form = ipywidgets.VBox()
        key = lambda hbox: hbox.children[0].value
        self.form.children = sorted(children, key=key)


问题


面经


文章

微信
公众号

扫码关注公众号