Beispiel #1
0
def log_progress(sequence, every=None, size=None):
    from ipywidgets import IntProgress, HTML, VBox
    from IPython.display import display

    is_iterator = False
    if size is None:
        try:
            size = len(sequence)
        except TypeError:
            is_iterator = True
    if size is not None:
        if every is None:
            if size <= 200:
                every = 1
            else:
                every = size / 200     # every 0.5%
    else:
        assert every is not None, 'sequence is iterator, set every'

    if is_iterator:
        progress = IntProgress(min=0, max=1, value=1)
        progress.bar_style = 'info'
    else:
        progress = IntProgress(min=0, max=size, value=0)
    label = HTML()
    box = VBox(children=[label, progress])
    display(box)

    index = 0
    try:
        for index, record in enumerate(sequence, 1):
            if index == 1 or index % every == 0:
                if is_iterator:
                    label.value = '{index} / ?'.format(index=index)
                else:
                    progress.value = index
                    label.value = u'{index} / {size}'.format(
                        index=index,
                        size=size
                    )
            yield record
    except:
        progress.bar_style = 'danger'
        raise
    else:
        progress.bar_style = 'success'
        progress.value = index
        label.value = str(index or '?')
Beispiel #2
0
 def _repr_html_(self): 
     graph = HTML( self.get_html() )
     return graph._repr_html_() 
    th_iter = x_plot[iter, 2]

    p_cart.set_data(x_iter, 0.1 + H / 2)
    p_pend.set_data(x_iter+np.array([0,L*np.sin(th_iter)]),\
                    0.1+H/2+np.array([0,-L*np.cos(th_iter)]))
    return p_pend


anim = animation.FuncAnimation(fig,
                               animate,
                               init_func=init,
                               frames=len(t_plot),
                               interval=50,
                               blit=False,
                               repeat=False)
HTML(anim.to_jshtml())

plot_labels = ('x', 'v', 'theta', 'omega')
[plt.plot(tspan, x[:, j], linewidth=2, label=plot_labels[j]) for j in range(4)]
plt.xlabel('Time')
plt.ylabel('State')

plt.legend()
plt.show()

#%% Compare with many examples of Pole Placement
JLQR = np.zeros(len(tspan))
for k in range(len(tspan)):
    JLQR[k] = (x[k, :] - wr) @ Q @ (x[k, :] - wr) + (u(x[k, :])**2) * R

t_plot = tspan[::50]
Beispiel #4
0
 def printSampleDataList(self):
     display( HTML( self.env.getTemplate("sampleData.html").render( dataDefs = iteritems(self.dataDefs) ) ))
def style_notebook():
    style = open("./resources/style.css", "r").read()
    return HTML(style)
Beispiel #6
0
def setUp():
    display(
        HTML('<style>{}</style>'.format(
            formatter.get_style_defs('.highlight'))))
Beispiel #7
0
 def show_help(cls):
     """Display Documentation for class."""
     display(HTML(cls.get_help()))
def plot_anim(frame_gen, xlim=(0,5), ylim=(-10,10), n=1000, delay=20, max_frames=1000,
                   title=None, xlabel=None, ylabel=None, gif=False):
    """Produce an animation from a frame-generating function. 
    Works in two modes:
      - Return a Jupyter HTML5 wrapper around a rendered mp4 video of the animation
      - Create an animated gif file of the animation
    The first mode is default and recommended for in-notebook rendering.
    
    Args:
      frame_gen : Generator that takes domain array of points and yields
                  successive range arrays of points to plot as frames.
                  The frames will continue until the generator is exhausted.
      xlim = (xmin,xmax) : Horizontal plot range [default (0,5)]
      ylim = (ymin,ymax) : Vertical plot range   [default (-10,10)]
      n : Number of domain points
      delay : number of ms between frames
      max_frames : maximum number of saved frame [default 1000]
      title : plot title (optional)
      xlabel : plot x axis label (optional)
      ylabel : plot y axis label (optional)
      gif : Boolean, if true render gif file instead of outputting HTML5 (default false)
    
    Returns:
      HTML object containing mp4 video of animation (when gif false)
    
    Effects:
      Saves a gif file containing the animation (when gif true)
    """
    # Define domain points that remain fixed
    x = np.linspace(xlim[0],xlim[1],n)
    g = frame_gen(x)
    
    # Create empty plot set to desired fixed zoom
    fig, ax = plt.subplots()
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)
    if title:  plt.title(title)
    if xlabel: plt.xlabel(xlabel)
    if ylabel: plt.ylabel(ylabel)
    
    # Draw an empty line and save the handle to update later
    line, = ax.plot([], [], lw=2)
    
    # Define how to generate a blank frame
    def init_frame():
        line.set_data([],[])
        return (line,)
    
    # Define how to update a frame from a range input
    def animate(y):
        line.set_data(x,y)
        return (line,)
    
    # Define animation object using frame generator
    # Use blit to redraw only the changes that were made
    anim = animation.FuncAnimation(fig, animate, init_func=init_frame, save_count=max_frames,
                                   frames=g, interval=delay, blit=True)
    
    # Tidy up stray plot within the notebook itself
    plt.close()
    
    if gif:
        # Render animation as animated gif file
        anim.save(frame_gen.__name__+'.gif', writer='imagemagick')
    else:
        # Make sure that animation renders to HTML5 by default
        rc('animation', html='html5')
        # Convert animation to HTML5 and return
        return HTML(anim.to_html5_video())
Beispiel #9
0
nx.draw_planar(G,
               node_color="lightblue",
               edge_color="gray",
               font_size=24,
               width=2,
               with_labels=False,
               node_size=3500)

list(nx.all_shortest_paths(G, source="MED", target='BOG '))

nx.draw(G, with_labels=True, node_color='lightgreen')

# https://en.wikipedia.org/wiki/Dijkstra's_algorithm
print("Dijkstra's algorithm")
HTML(
    '<img src="https://upload.wikimedia.org/wikipedia/commons/2/23/Dijkstras_progress_animation.gif">'
)

# instruccion para calcular la ruta mas corta
list(nx.all_shortest_paths(G, source="BOG ", target='AGH'))

list(nx.all_shortest_paths(G, source="MED", target='BOG '))

#all_shortest_paths(G, source, target, weight=None, method='dijkstra')
list(nx.all_shortest_paths(G, source="BOG ", target='MED', weight=None))

#Devuelve una lista de nodos en la ruta más corta entre el origen y el destino utilizando el algoritmo A * ("A-star").
list(nx.astar_path(G, ("BOG "), ("MED"), weight='precio'))

list(nx.dijkstra_path(G, ("MED"), ("BOG "), weight='precio'))
Beispiel #10
0
# Create Reports ---------------------------------------------------------------
d = {
    'Forward Bearing': round(forwardInitialBearing, 4),
    'Backward Bearing': round(backwardInitialBearing, 4),
    'Distance': round(cumulativeOffset, 4)
}
html = "<b> Linear Misclosure</b>"
html += """<table border="1">
<tr><th>Pass 1 Bearing [degrees]</th><th>Pass 2 Bearing [degrees] </th><th>Cumulative Offset [m]</th></tr>"""
html += "<tr><td>{}</td>".format(d['Forward Bearing'])
html += "<td>{}</td>".format(d['Backward Bearing'])
html += "<td>{}</td>".format(d['Distance'])
html += "</tr></table>"
html += "<small><small> Bearings are relative to True North </small></small>"
display(HTML(html))

# OOS Verification
d = {
    'Run': pd.Series([run for run in runs]),
    'KP From': pd.Series(["{0:.4f}".format(kpFrom) for kpFrom in kpFroms]),
    'KP To': pd.Series([round(kpTo, 4) for kpTo in kpTos]),
    'HOOS Sigma': pd.Series([round(hoosSigma, 3) for hoosSigma in hoosSigmas]),
    'HOOS 2Sigma':
    pd.Series([round(hoos2Sigma, 3) for hoos2Sigma in hoos2Sigmas]),
    'VOOS Sigma': pd.Series([round(voosSigma, 3) for voosSigma in voosSigmas]),
    'VOOS 2Sigma':
    pd.Series([round(voos2Sigma, 3) for voos2Sigma in voos2Sigmas])
}

df = pd.DataFrame(d)
Beispiel #11
0
# coding: utf-8

# In[5]:


import AnuLibrary, writeFact
from IPython.display import HTML
# path = '/home/kishori/rule1E_tmp/2.1/'
relation_df = AnuLibrary.create_dataframe('hindi_dep_parser_original.dat') 
relation_df

HTML(relation_df.to_html(classes='table table-condensed'))

Beispiel #12
0
    plt.ylabel("Loss")
    plt.legend()
    plt.show()

    # %%capture
    fig = plt.figure(figsize=(8, 8))
    plt.axis("off")
    ims = [[plt.imshow(np.transpose(i, (1, 2, 0)), animated=True)]
           for i in img_list]
    ani = animation.ArtistAnimation(fig,
                                    ims,
                                    interval=1000,
                                    repeat_delay=1000,
                                    blit=True)

    HTML(ani.to_jshtml())

    # Grab a batch of real images from the dataloader
    real_batch = next(iter(train_loader))

    # Plot the real images
    plt.figure(figsize=(15, 15))
    plt.subplot(1, 2, 1)
    plt.axis("off")
    plt.title("Real Images")
    plt.imshow(
        np.transpose(
            vutils.make_grid(real_batch[0].to(device)[:64],
                             padding=5,
                             normalize=True).cpu(), (1, 2, 0)))
Beispiel #13
0
    source_img = io.imread(source_img_paths[nframe])
    ax1.imshow(source_img)
    ax1.set_xticks([])
    ax1.set_yticks([])

    target_label = io.imread(target_label_paths[nframe])
    ax2.imshow(target_label)
    ax2.set_xticks([])
    ax2.set_yticks([])

    target_synth = io.imread(target_synth_paths[nframe])
    ax3.imshow(target_synth)
    ax3.set_xticks([])
    ax3.set_yticks([])


fig = plt.figure(figsize=(12, 6))
ax1 = fig.add_subplot(131)
ax2 = fig.add_subplot(132)
ax3 = fig.add_subplot(133)

anim = ani.FuncAnimation(fig,
                         animate,
                         frames=len(target_label_paths),
                         interval=1000 / 24)
plt.close()

js_anim = HTML(anim.to_jshtml())

anim.save("output.gif", writer="imagemagick")
# # Introduction to 4 Tone CfL
#
# In this experiment, we increase the number of tonal parameter from 1 to 2 per plane. The first parameter is applied to positive values while the second is used on negative values

# In[ ]:

from IPython.display import HTML
HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 $('#toggle').attr('value', 'Show code')  
 } else {
 $('div.input').show();
 $('#toggle').attr('value', 'Hide code') 
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" id="toggle" value="Show code"></form>'''
     )

# # Prologue
#
# Let's start with the usual dependencies

# In[1]:

get_ipython().magic('matplotlib inline')
Beispiel #15
0
# reprinting the output again for clarity:
#
# <html><p>file1 = ../resources/idffiles/V_7_2/constructions.idf</p><p>file2 = ../resources/idffiles/V_7_2/constructions_diff.idf</p><table border="1"><tr><th>Object Key</th><th> Object Name</th><th> Field Name</th><th> file1</th><th> file2</th></tr><tr><td>MATERIAL</td><td>F08 Metal surface</td><td></td><td>not here</td><td>is here</td></tr><tr><td>MATERIAL</td><td>F08 Metal surface haha</td><td></td><td>is here</td><td>not here</td></tr><tr><td>MATERIAL</td><td>G05 25mm wood</td><td>Conductivity</td><td>0.15</td><td>0.155</td></tr><tr><td>CONSTRUCTION</td><td>Exterior Door</td><td>Outside Layer</td><td>F08 Metal surface</td><td>F08 Metal surface haha</td></tr></table></html>

# <markdowncell>

# It does look like html :-). We need to redirect this output to a file and then open the file  in a browser to see what it looks like. Displayed below is the html file

# <codecell>

from eppy.useful_scripts import (
    doc_images, )  # no need to know this code, it just shows the image below
from IPython.display import HTML

h = HTML(open(doc_images.idfdiff_path, "r").read())
h

# <markdowncell>

# Pretty straight forward. Scroll up and look at the origin text files, and see how idfdiff.py understands the difference

# <markdowncell>

# Now let us try the same thin in csv format

# <codecell>

# %%bash
# python idfdiff.py idd file1 file2
os.system(
def display_html(html_string):
    display(HTML(html_string))
import seaborn as sns
import ast
import re
import scipy.stats as stats
import datetime
from statsmodels.stats.outliers_influence import variance_inflation_factor
import statsmodels.api as sm
from collections import Counter
import matplotlib.patches as mpatches
from sklearn.model_selection import train_test_split
import itertools
plt.rcParams['figure.dpi'] = 100

from IPython.display import HTML, Math
display(
    HTML("<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/"
         "latest.js?config=default'></script>"))
Math(r"e^\alpha")

### Load Data

train_adj_d = pd.read_csv('train_adj_r10_t01_d.csv')
val_adj_d = pd.read_csv('test_adj_r10_t01_d.csv')

print "---"
print "Q: What is the size of train_adj_d?"
print train_adj_d.shape
print "---"

## Split data into train and test
train_split_adj_d, test_split_adj_d = train_test_split(train_adj_d,
                                                       test_size=0.1)
Beispiel #18
0
def _display(html):
    return display(HTML(html))
Beispiel #19
0
def manim(line, cell):

    #Include manimlib imports if the user forgot to include them.
    if 'from manimlib.imports import *' not in cell:
        cell = 'from manimlib.imports import *\n' + cell

    #A temporary file to store current cell's code
    #This file and thus it's output media files
    #will be overwritten each time you execute the
    #cell. So, if you want to save a file use the
    #-o option.
    file_name = '__temp__.py'

    #parse the specified arguments. "parse_args" is
    #slightly modified manim function "manimlib.config.parse_cli()".
    #It takes an additional argument -v or --verbose.
    args = parse_args(line.strip().split())

    #if file name is provided using --file option then use
    #that name instead.
    if not args.file:
        args.file = file_name
    else:
        args.file += '.py'
    #display output cell beside input cell if args.no_split == False
    if not args.no_split:
        split_screen()

    #write to the file
    with open(args.file, 'w') as new_file:
        new_file.write(cell)

    #io.capture_output() suppress output until its
    #closed. So if args.verbose == true, then suppress
    #the output.
    if not args.verbose:
        capture_output = io.capture_output(stderr=args.quiet)
        capture_output.__enter__()

    #manim functions
    config = manimlib.config.get_configuration(args)
    manimlib.constants.initialize_directories(config)

    #end io.capture_output() if it was opened
    if not args.verbose:
        capture_output.__exit__(None, None, None)

    #es.main is a modified version of manimlib.extract_scene.main()
    #It takes the usual argument "config", plus an additional
    #argument arg.verbose. It is explicitly given args.verbose
    #because we don't want to suppress the list of scene class
    #which is displayed on the output when multiple classes are
    #present in the code.
    all_scene_objects = es.main(config, verbose=args.verbose, quiet=args.quiet)

    #this contain the html attributes to render, like the video
    #and images of the output file
    html_to_render = ''

    #default height and width of output screen
    height = 300
    width = 480

    #if resolution is explicitly provided then use provided values instead
    if args.frame_size:
        try:
            height, width = [
                int(x) for x in args.frame_size.strip().split(',')
            ]
        except Exception as e:
            print(e,
                  '\nFrame size should have a format, height,width',
                  file=sys.stderr)
            sys.exit(1)

    #loop through all the scene class objects to find the
    #location of their respective output media files.
    #Use their location to generate appropriate html code
    #and append it to "html_to_render".
    for x in all_scene_objects:
        dictionary = x.__dict__['file_writer'].__dict__
        if args.save_last_frame:
            html_to_render += get_image(dictionary['image_file_path'],
                                        width=width,
                                        height=height)
        if dictionary['write_to_movie']:
            html_to_render += get_video(dictionary['movie_file_path'],
                                        width=width,
                                        height=height)

    #finally display rendered HTML
    return HTML(html_to_render)
Beispiel #20
0
def code(string):
    assert isinstance(string, str)
    return HTML(f"<code>{escape(string)}</code>")
Beispiel #21
0
def display_df(df):
    "Display `df` in a notebook or defaults to print"
    try: from IPython.display import display, HTML
    except: return print(df)
    display(HTML(df.to_html()))
Beispiel #22
0
def well(s):
    s = safe(s)._repr_html_()
    return HTML('<div class="jupyter-extra-info">' + s + '</div>')
def play_mp3(file):
    return HTML('<audio src="'+file+'" controls><p>If you are reading this, it is because your browser does not support the audio element</p></audio>')
Beispiel #24
0
 def in_f(k, v):
     if k == 'headers':
         return HTML(html_formatter_for_mapping(v, open=False))
     else:
         return v
def show_video_file(url,width,height):
    return HTML('<video width="900" height="600" controls autoplay><source src="resources/MapBox-Isochrone-Continuous.ogg"</video>')
    def plot(self):
        print("Reading data")
        # Vemos cual es la extensión
        exten = self.file.split('.')
        extension = exten[len(exten) - 1]
        # Leemos los archivos .tsv
        if extension == 'tsv':
            df = pd.read_table(self.file)
            df = df.drop(
                list(df)[-1], 1
            )  #Para los archivos .tsv eliminamos la última columna que se suele leer y no tiene nada
            # Calculamos los índices para poder hacer los plots
            print("Calculate indexes")
            par = list(df)
            # Añadimos los índices
            df[len(par)] = df.index
            # Establecemos nombres a las columnas
            df.columns = ["Strike", "TC", "SP", "Index"]
            # Damos opción para indicar tags diferentes
            if self.tags != None:
                dfd = self.tags
                dfd.append("Indice")
                if (len(dfd) == len(list(df))):
                    df.columns = dfd
                else:
                    raise Exception("Number of tags: " + str(len(dfd) - 1) +
                                    "  missmatched column length  -->   " +
                                    str(len(list(df)) - 1))
        # Leemos archivos que acepta read_csv
        elif (extension == 'csv' or extension == 'txt'):
            df = pd.read_csv(self.file)

        name_data_frame = list(df)
        if self.normalization == True:
            print("Normalizing data")
            # Eliminamos temporalmente ultima columna
            num = df[list(df)[-1]]
            df = df.drop(list(df)[-1], 1)
            # Normalizamos los datos
            x = df.values  # returns a numpy array
            min_max_scaler = preprocessing.MinMaxScaler()
            x_scaled = min_max_scaler.fit_transform(x)
            df = pd.DataFrame(x_scaled)
            # Volvemos a añadir el dataFrame
            df[len(list(df))] = num
            df.columns = name_data_frame
        print("Calculating best ranges")
        # Inicializamos las variables
        max_range_values = []
        min_range_values = []
        final_max_value = 0
        final_min_value = 0
        #Creamos una lista con los nombres de las columnas
        pared = list(df)
        for l in range(0, len(pared) - 1):
            max1 = max(df[pared[l]])
            min1 = min(df[pared[l]])
            if l < len(pared) - 3:
                max2 = max(df[pared[l + 1]])
                min2 = min(df[pared[l + 1]])
                max_range_values.append(max(int(max1 * 2), int(max2 * 1.2)))
                min_range_values.append(min(min1 - 1, min2 - 1))
            if l == len(pared) - 2:
                max_range_values.append(max(df[pared[l]] * 1.2))
                min_range_values.append(min(df[pared[l]]))
                final_max_value = max(max_range_values)
                final_min_value = min(min_range_values)
        print("Plotting data")
        if self.library == 'pyplot':
            division = list(df)[-1]
            # Limpiamos la figura en caso de que tuviesemos algo
            plt.close()
            plt.figure()
            plt.clf()
            # Ofrece la opción de plotear de un solo color
            if self.color_unique == True:
                fig = parallel_coordinates(df, division, color=('#556270'))
            elif self.color_unique == False:
                fig = parallel_coordinates(df, division)
            # Ofrece la opcion de eliminar la leyenda
            if (self.remove_legend == True):
                plt.gca().legend_.remove()
            # Ofrece la opcion de guardar la gráfica
            if self.autosave == True:
                plt.savefig(self.save_file_name)
            # Mostramos la gráfica
            plt.show()
            fig = df

        elif self.library == 'plotly':
            # Vamos a generar unos indices para poder identificar las columnas en forma de ids
            levels = df[pared[-1]].unique()
            new_column = []
            for o in range(0, len(df[pared[-1]])):
                for q in range(0, len(levels)):
                    if df[pared[-1]][o] == levels[q]:
                        new_column.insert(o, q)
            df[len(list(df))] = new_column
            df = df.rename(columns={len(list(df)) - 1: "autoIndexes"})
            print(len(list(df)))

            if len(list(df)) == 8:
                data = [
                    go.Parcoords(
                        # Añadimos el id y los colores que vamos a usar
                        line=dict(color=df['autoIndexes'],
                                  colorscale=[[0, '#D7C16B'], [0.5, '#23D8C3'],
                                              [1, '#F3F10F']]),
                        dimensions=list([
                            # Vamos a añadiendo las diferentes subplots que se añaden al final
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[0],
                                 values=df[pared[0]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[1],
                                 values=df[pared[1]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[2],
                                 values=df[pared[2]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[3],
                                 values=df[pared[3]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[4],
                                 values=df[pared[4]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[5],
                                 values=df[pared[5]])
                        ]))
                ]
            #Tenemos esto para diferente numero de colimnas
            if len(list(df)) == 7:
                data = [
                    go.Parcoords(
                        line=dict(color=df['autoIndexes'],
                                  colorscale=[[0, '#D7C16B'], [0.5, '#23D8C3'],
                                              [1, '#F3F10F']]),
                        dimensions=list([
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[0],
                                 values=df[pared[0]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[1],
                                 values=df[pared[1]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[2],
                                 values=df[pared[2]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[3],
                                 values=df[pared[3]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[4],
                                 values=df[pared[4]])
                        ]))
                ]

            if len(list(df)) == 6:
                data = [
                    go.Parcoords(
                        line=dict(color=df['autoIndexes'],
                                  colorscale=[[0, '#D7C16B'], [0.5, '#23D8C3'],
                                              [1, '#F3F10F']]),
                        dimensions=list([
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[0],
                                 values=df[pared[0]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[1],
                                 values=df[pared[1]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[2],
                                 values=df[pared[2]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[3],
                                 values=df[pared[3]])
                        ]))
                ]
            if len(list(df)) == 5:
                data = [
                    go.Parcoords(
                        line=dict(color=df['autoIndexes'],
                                  colorscale=[[0, '#D7C16B'], [0.5, '#23D8C3'],
                                              [1, '#F3F10F']]),
                        dimensions=list([
                            dict(range=[final_min_value, final_max_value],
                                 constraintrange=[4, 8],
                                 label=pared[0],
                                 values=df[pared[0]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[1],
                                 values=df[pared[1]]),
                            dict(range=[final_min_value, final_max_value],
                                 label=pared[2],
                                 values=df[pared[2]])
                        ]))
                ]

            # Coloreamos el fondo de la figura
            layout = go.Layout(plot_bgcolor='#E5E5E5', paper_bgcolor='#E5E5E5')
            # Utilizamos la librería offline de plotly para hacer el gráfico
            fig = go.Figure(data=data, layout=layout)
            if self.autosave == True:
                off = offline.plot(fig,
                                   image='png',
                                   output_type='file',
                                   image_filename=self.save_file_name,
                                   filename=self.save_file_name)
            if self.autosave == False:
                off = offline.iplot(fig)
            display(HTML(off))

        elif self.library == 'bokeh':
            plots = []
            nombres = list(df)
            count = 0
            df.sort_values(nombres[1])
            colourname = []
            for i in range(0, len(nombres) - 2):
                # Generamos la figura
                p = figure(x_range=(1, 5),
                           x_axis_label=nombres[i] + '       ' +
                           nombres[i + 1],
                           y_range=(final_min_value, final_max_value),
                           plot_width=400,
                           plot_height=400)
                xs = []
                ys = []
                # Coloreamos  25%-25%-25%-25%
                for j in range(0, len(df[nombres])):
                    if i == 0:
                        if j < len(df[nombres[i]]) / 4:
                            colourname.append(colors[1])
                        elif j >= len(df[nombres[i]]) / 4 and j < (
                                2 * len(df[nombres[i]]) / 4):
                            colourname.append(colors[2])
                        elif j >= 2 * len(df[nombres[i]]) / 4 and j < 3 * len(
                                df[nombres[i]]) / 4:
                            colourname.append(colors[3])
                        elif j >= 3 * len(df[nombres[i]]) / 4 and j < 4 * len(
                                df[nombres[i]]) / 4:
                            colourname.append(colors[4])
                            # Añadimos los valores
                    xs.append([1, 5])
                    ys.append([df[nombres[i]][j], df[nombres[i + 1]][j]])
                    count += 1
                    # Generamos el plot
                if self.color_unique == True:
                    p.multi_line(xs, ys, line_width=4)
                else:
                    p.multi_line(xs, ys, color=colourname, line_width=4)
                p.add_tools(PanTool(), WheelZoomTool(), LassoSelectTool())
                plots.append(p)
            # Añadimos las diferentes gráficas generadas
            fig = gridplot([plots], sizing_mode='stretch_both')
            if self.autosave == True:
                save(fig)
                export_png(fig, filename=self.save_file_name)
            # Mostramos el total de las gráficas generadas
            show(fig)
        return fig
"""BERT Score
*   Precision: 0.8866757232634748
*   Recall       : 0.8992083258316165
*   F-1: 0.8926650442060877

### Show Text Embedding on 2D
"""

display_sents = []
print(KPOriginal)
print(ArgumentsOriginal[keys[0]])
print("===========")
for i, s in enumerate(ArgumentsOriginal):
    line = '<font color="#CD5C5C"><strong>' + s + '</strong></font>' if i in keys else s
    display_sents.append(line)
HTML('              '.join(display_sents))

# plot
mds = manifold.MDS(n_components=2, dissimilarity="precomputed")
embs = np.concatenate((doc_emb, sent_embs), 0)
dist_matrix = cosine_distances(embs, embs)
pns = mds.fit_transform(dist_matrix)
fixed_pns = pns - pns[0]

keys_idx = [idx + 1 for idx in keys]
other_idx = [idx for idx in range(1, len(ArgumentsOriginal)+1) if idx not in keys_idx]
plt.scatter(fixed_pns[0,0], fixed_pns[0,1], color='green',  marker='*', s=150, label='document')
plt.scatter(fixed_pns[keys_idx,0], fixed_pns[keys_idx, 1], color='blue', label='key sentences')
plt.scatter(fixed_pns[other_idx,0], fixed_pns[other_idx, 1], color='white', edgecolors='black', label='other sentences')
plt.xlim(-0.7, 0.7)
plt.ylim(-0.7, 0.7)
Beispiel #28
0
def display_css(widget, css_text):
    # this should still work in jupyterlab as of last attempt :)
    styletext = "<style>\n%s\n</style>" % css_text
    display(HTML(styletext))
Beispiel #29
0
 def jquploader(self, line):
     """
     Bring up an html cell with JQuery UI PLUpload widget that supports drag and drop
     Note that this is a demonstration prototype!
     """
     return HTML(biokbase.narrative.upload_handler.JQUERY_UI_EXAMPLE)
Beispiel #30
0
def pretty_print(df):
    return display(HTML(df.to_html().replace("\\n", "<br>")))
    df_rank_expanded = df_rank_expanded.interpolate()
    labels = df_expanded.columns
    return df_expanded, df_rank_expanded, labels


if __name__ == '__main__':
    # 处理mpl中文字体问题
    mpl.rcParams["font.sans-serif"] = ["SimHei"]
    mpl.rcParams["axes.unicode_minus"] = False
    # 连接hive读数据并数据预处理
    conn = hive.Connection(host='127.0.0.1', port=10000, auth='CUSTOM', username='******', password='******')
    df = pd.read_sql(
        sql="SELECT c_day,team_name,ten_days_buy_amt FROM data_market.ads_team_controlrates_monitor_so where c_day < '2020-08-24'",
        con=conn)
    data_res = df.set_index(['c_day', 'team_name']).unstack().fillna(0).head(11)
    # 去除一级行索引
    data_res1 = data_res.droplevel(level=0, axis=1)
    # 挑选几只战队和适当时间比较
    data_res1 = data_res1[['178战队', '698战队', 'Avenger战队', '众志战队', '传奇战队', '先锋战队', '光芒战队', '凌霄战队', '利刃战队', '北斗战队']]
    data_res2 = data_res1.loc['2020-08-13':'2020-08-23']
    # 平滑过渡
    df_expanded, df_rank_expanded, labels = prepare_data(data_res2)
    # 动画
    fig = plt.Figure(figsize=(6, 3.5), dpi=144)
    ax = fig.add_subplot()
    anim = FuncAnimation(fig=fig, func=update, frames=len(df_expanded),
                         interval=200, repeat=False)
    # 展示
    html = anim.to_html5_video()
    HTML(html)
Beispiel #32
0
def create():
    if request.method == "GET":
        return render_template('create.html')
    else:
        a = request.form.get("indexs")
        b = request.form.get("columns")
        c = request.form.get("values")
        btn1 = request.form.get("btn1")
        btn2 = request.form.get("btn2")
        on = False
        btn1 = btn1.strip()
        btn2 = btn2.strip()
        on = False

        if len(btn2) >= 1:
            on = True
        a3, b3 = [], []
        a2 = a.split(',')
        b2 = b.split(",")
        for aa in a2:
            if a == "":
                break
            a3.append(aa)

        for bb in b2:
            if b == "":
                break
            b3.append(bb)
        f = []

        d = c.strip().split(",")
        for i in d:
            f.append(i)
        f = np.array(f)
        len(b3)
        a3_size = len(a3)
        b3_size = len(b3)
        if on == True:
            f = np.array(f).reshape(int(f.size / int(btn2)), int(btn2))
        elif b3_size > 1 and on == False:
            f = np.array(f).reshape(int(f.size / b3_size), b3_size)
        else:
            f = np.array(f)
        a3_size
        if a3_size < 1 and b3_size < 1:
            c2 = pd.DataFrame(f, columns=None, index=None)
        elif b3_size > 0 and a3_size < 1:
            c2 = pd.DataFrame(f, columns=b3, index=None)
        else:
            c2 = pd.DataFrame(f, columns=b3, index=a3)

        if a3_size < 1 and b3_size < 1:
            c2.to_excel('static/excelfolder/to_csv.xlsx',
                        index=False,
                        header=False)
        if a3_size < 1 and b3_size > 0:
            c2.to_excel('static/excelfolder/to_csv.xlsx', index=False)
        if a3_size > 0 and b3_size > 0:
            c2.to_excel('static/excelfolder/to_csv.xlsx')
        ANS = HTML(c2.to_html())

        return render_template('create.html', posts=ANS)