当前位置: 首页>>代码示例>>Python>>正文


Python mpld3.fig_to_html函数代码示例

本文整理汇总了Python中mpld3.fig_to_html函数的典型用法代码示例。如果您正苦于以下问题:Python fig_to_html函数的具体用法?Python fig_to_html怎么用?Python fig_to_html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fig_to_html函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show_d3

def show_d3(figure=None):
    """
    Show matplotlib fig using d3.js.
    """
    if figure:
        img = mpld3.fig_to_html(figure, d3_url=D3_URL)
    else:
        img = mpld3.fig_to_html(fig, d3_url=D3_URL)
    dat = img.replace('\n', '\r')
    print 'embed:', dat
开发者ID:engjoy,项目名称:suricate,代码行数:10,代码来源:sdk.py

示例2: render_webfigure

def render_webfigure(var_dict):

  userlon = float(var_dict['userlon'])
  userlat = float(var_dict['userlat'])
  data = var_dict['data']

  fig, ax = plt.subplots(figsize=(15,10))

  #return antlons, antlats, scss, cats, separations, geodesics, contour_lons, contour_lats
  antlons = data[0]
  antlats = data[1]
  scss = data[2]
  cats = data[3]
  contour_lons = data[6]
  contour_lats = data[7]

  #print userlon
  plt.plot(userlon, userlat, 'g*', ms=40)
  plt.scatter(antlons, antlats, c='r')
  for i in xrange(len(antlons)):
    label = '{} ({})'.format(scss[i], cats[i])
    plt.text(antlons[i]+.05, antlats[i], label)
    plt.plot(contour_lons[i], contour_lats[i])
    #print contour_lons[i], contour_lats[i]

  import json
  execfile("/Users/mwoods/Work/OldJobs/JobSearch/Pre-Insight/plotUSA.py")
  jdata = json.load(open("/Users/mwoods/Work/OldJobs/JobSearch/Pre-Insight/states.json"))
  i=0
  for state in jdata['geometries']:
    i+=1
    j=0
    # State only has one border, do not enter into 'for each border' loop.
    if len(state['coordinates'][0]) != 1:
      x,y = np.array(state['coordinates']).T
      plt.plot(x,y, 'b', lw=3)
      continue
    # There is a list with multiple borders (islands)
    for shape in state['coordinates']:
      x,y = np.array(shape[0]).T
      plt.plot(x,y, 'b', lw=3)
  plt.xlim(userlon-1, userlon+1)
  plt.ylim(userlat-1, userlat+1)
  plt.xlabel("Longitude")
  plt.ylabel("Latitude")
  #plt.gca().set_aspect('equal')


  #plt.hist(np.random.random(100))
  #plt.scatter(np.random.random(100), np.random.random(100))
  fig_html = mpld3.fig_to_html(fig)

  return mpld3.fig_to_html(fig)
开发者ID:BruisingCurve,项目名称:foodGrouper,代码行数:53,代码来源:graphics.py

示例3: pos_salaries_distribution

    def pos_salaries_distribution(self):
        """
        This is a function to analyze and plot salaries distribution by positions.

        Return:
        html: a string of html of by-position salaries distribution plot.
        pos: a dataframe with salaries statistics by positions.
        """
        salaries_pos_year = self.df[[self.year,'POS']].dropna()
        positions = ['C','PF','SF','SG','PG']
        salaries_pos_year = salaries_pos_year[salaries_pos_year['POS'].isin(positions)]
        pos = [salaries_pos_year[salaries_pos_year['POS'] == position].describe().rename(columns={self.year:position}) for position in positions] #store by-position salaries statistics into a list
        pos = pd.concat(pos, axis=1) #merge all by-position dataframes
        #convert all elements in dataframe into integers
        for position in positions:
            pos[position] = pos[position].apply(lambda x: int(x))

        ax = salaries_pos_year.boxplot(by='POS',sym='r*',figsize=(10,6))
        ax.set_axis_bgcolor('#EEEEEE')
        ax.grid(color='white', linestyle='solid')

        #add positions name text into the boxplot
        loc = salaries_pos_year.groupby('POS').median()
        for i in xrange(0,5):
            ax.text(i+1, 
                    loc[self.year][i], 
                    loc.index[i], 
                    ha='center',
                    va='bottom')
        plt.title('')
        ax.set_xlabel('Positions', fontsize=16)
        fig = ax.get_figure()
        html = mpld3.fig_to_html(fig)
        plt.close()
        return html, pos
开发者ID:HenryZhang990,项目名称:ds-1007-project,代码行数:35,代码来源:salaries_stats_analysis.py

示例4: overall_salaries_trend

    def overall_salaries_trend(self):
        """
        This function is to analyze and plot nba salaries trend.

        Return:
        html: a string of html for the salaries trend plot.
        salaries: a dataframe with salaries statistical information (e.g., mean, min, max) in each year. 
        """
        years = xrange(2000,2016)
        salaries = [self.df[year].describe().apply(lambda x: int(x)) for year in years] #store salaries statistical information for each year in a list
        salaries = pd.concat(salaries, axis=1).T.drop(['25%','75%'],1) #merge all salaries statistical information dataframes into a dataframe

        fig = plt.figure(figsize=(10,6))
        ax = fig.add_subplot(111, axisbg='#EEEEEE')
        ax.grid(color='white', linestyle='solid')
        ave_salaries = self.df.mean() #calculate the average salaries for each year
        plt.bar(self.df.columns, ave_salaries, 0.5, color='#0077FF', alpha=0.5)
        ax.set_xlabel('Year', fontsize=16)
        ax.set_ylabel('Average Salaries', fontsize=16)
        ax.xaxis.set_label_coords(0.5,-0.08)
        ax.yaxis.set_label_coords(-0.14,0.5)
        plt.title('2000-2015 NBA Average Salaries Trend')
        html = mpld3.fig_to_html(fig)
        plt.close()
        return html, salaries
开发者ID:HenryZhang990,项目名称:ds-1007-project,代码行数:25,代码来源:salaries_stats_analysis.py

示例5: plot

    def plot(self, notebook=False, colormap='polar', scale=1, maptype='points', show=True, savename=None):

        # make a spatial map based on the scores
        fig = pyplot.figure(figsize=(12, 5))
        ax1 = pyplot.subplot2grid((2, 3), (0, 1), colspan=2, rowspan=2)
        if maptype is 'points':
            ax1, h1 = pointmap(self.scores, colormap=colormap, scale=scale, ax=ax1)
        elif maptype is 'image':
            ax1, h1 = imagemap(self.scores, colormap=colormap, scale=scale, ax=ax1)
        fig.add_axes(ax1)

        # make a scatter plot of sampled scores
        ax2 = pyplot.subplot2grid((2, 3), (1, 0))
        ax2, h2, samples = scatter(self.scores, colormap=colormap, scale=scale, thresh=0.01, nsamples=1000, ax=ax2, store=True)
        fig.add_axes(ax2)

        # make the line plot of reconstructions from principal components for the same samples
        ax3 = pyplot.subplot2grid((2, 3), (0, 0))
        ax3, h3, linedata = tsrecon(self.comps, samples, ax=ax3)

        plugins.connect(fig, LinkedView(h2, h3[0], linedata))
        plugins.connect(fig, HiddenAxes())

        if show and notebook is False:
            mpld3.show()

        if savename is not None:
            mpld3.save_html(fig, savename)
        elif show is False:
            return mpld3.fig_to_html(fig)
开发者ID:mathisonian,项目名称:thunder,代码行数:30,代码来源:pca.py

示例6: to_html

    def to_html(self):
        import matplotlib.pyplot as plt
        html = fig_to_html(self.content, figid="generatedchart")
        #closes fig element (refresh)
        plt.close()

        return html
开发者ID:armell,项目名称:RNASEqTool,代码行数:7,代码来源:content_representations.py

示例7: display_figure

def display_figure(fig, message=None, max_width='100%'):
    "Display widgets applicable to the specified element"
    if OutputMagic.options['fig'] == 'repr': return None

    figure_format = OutputMagic.options['fig']
    dpi = OutputMagic.options['dpi']
    backend = OutputMagic.options['backend']

    if backend == 'nbagg' and new_figure_manager_given_figure is not None:
        manager = new_figure_manager_given_figure(OutputMagic.nbagg_counter, fig)
        # Need to call mouse_init on each 3D axis to enable rotation support
        for ax in fig.get_axes():
            if isinstance(ax, Axes3D):
                ax.mouse_init()
        OutputMagic.nbagg_counter += 1
        manager.show()
        return ''
    elif backend == 'd3' and mpld3:
        fig.dpi = dpi
        mpld3.plugins.connect(fig, mpld3.plugins.MousePosition(fontsize=14))
        html = "<center>" + mpld3.fig_to_html(fig) + "<center/>"
    else:
        renderer = Store.renderer.instance(dpi=dpi)
        figdata = renderer.figure_data(fig, figure_format)
        if figure_format=='svg':
            figdata = figdata.encode("utf-8")
        b64 = base64.b64encode(figdata).decode("utf-8")
        (mime_type, tag) = MIME_TYPES[figure_format], HTML_TAGS[figure_format]
        src = HTML_TAGS['base64'].format(mime_type=mime_type, b64=b64)
        html = tag.format(src=src)
    plt.close(fig)
    return html if (message is None) else '<b>%s</b></br>%s' % (message, html)
开发者ID:aashish24,项目名称:holoviews,代码行数:32,代码来源:display_hooks.py

示例8: draw_fig

def draw_fig(fig_type):
    """Returns html equivalent of matplotlib figure

    Parameters
    ----------
    fig_type: string, type of figure
            one of following:
                    * line
                    * bar

    Returns
    --------
    d3 representation of figure
    """

    with lock:
        fig, ax = plt.subplots()
        if fig_type == "line":
            ax.plot(x, y)
        elif fig_type == "bar":
            ax.bar(x, y)
        elif fig_type == "pie":
            ax.pie(pie_fracs, labels=pie_labels)
        elif fig_type == "scatter":
            ax.scatter(x, y)
        elif fig_type == "hist":
            ax.hist(y, 10, normed=1)
        elif fig_type == "area":
            ax.plot(x, y)
            ax.fill_between(x, 0, y, alpha=0.2)

    
    return mpld3.fig_to_html(fig)
开发者ID:Plommonsorbet,项目名称:mpld3-flask,代码行数:33,代码来源:routes.py

示例9: run

def run(data):
    global t0, lines, test
    
    print data
    #override t to be count of seconds
    t=time.time()-t0
    tdata.append(t)

    for sensor in all_data:
        for axis in all_data[sensor]:
            if axis=="x":i=0
            if axis=="y":i=1
            if axis=="z":i=2
            # if test==0: print sensor+" ("+axis+")"
            all_data[sensor][axis].append(data[sensor][i])
            lines[sensor][axis][0].set_data(tdata, all_data[sensor][axis])
    # all_lines=[[axis for axis in sensor.values()] for sensor in lines.values()]
    # test=1
    #MOVING WINDOW
    xmin, xmax = ax[0].get_xlim()
    if t >= xmax-1: #once the line get's 9 10ths of the way...
        #move the window by 5 seconds forward
        
        xmin+=5
        xmax+=5
        for i in range(len(axes)):
            ax[i].set_xlim(xmin, xmax)
        # print 'test'
        ax[0].figure.canvas.draw()
        ax[1].figure.canvas.draw()
        ax[2].figure.canvas.draw()
    html=mpld3.fig_to_html(fig)
    print html
    # mpld3.show(fig)
    return html
开发者ID:morganwallace,项目名称:hercubit_diary_study,代码行数:35,代码来源:html_graph.py

示例10: get_heatmap

def get_heatmap(ds):
    plt.close('all')
    corrmat = ds.corr()
    fig, ax = plt.subplots()
    sns.heatmap(corrmat, vmax=.8, square=True)
    heatmap_html = mpld3.fig_to_html(fig)
    return heatmap_html
开发者ID:njpatnode,项目名称:0.1.0,代码行数:7,代码来源:views.py

示例11: draw

 def draw(self, name=None, old=None, new=None):
     if name is not None and self.DONT_DRAW.match(name):
         return
     
     if self._FREEZE:
         return
     
     plot_and_message = ''
     
     # Better way would be a decorator or something that only goes into draw if not autoupdate
     if self.autoupdate:
         
         # Generate new figure object
         f = plt.figure(figsize=(self.figwidth, self.figheight))
         if PLOTPARSER.is_3d(self.kind):
             projection = '3d'
         else:
             projection = None
         ax = f.add_subplot(111, projection=projection)
         
         if self._color_state or self.kind not in ['spec', 'waterfall', 'contour', 'contour3d']:
             colorkwags = dict(color=self.color)
         else:
             colorkwags = dict(cmap=self.colormap, cbar=self.colorbar)
         
         self.spec_modified.plot(ax=ax,
                                 fig=f,
                                 kind=self.kind,
                                 norm=self.NORMUNITS_REV[self.norm_unit],
                                 **colorkwags
                                 )
         f.tight_layout() #Padding around plot
         lines = ax.get_lines()
         plt.close(f)
                                 
         #http://mpld3.github.io/modules/API.html
         if self.interactive:
             import mpld3
             if self.selectlines:
                 from line_plugin import HighlightLines
                 
                 for idx, col in enumerate(self.spec_modified.columns):
                     name = 'COLUMN(%s): %s' % (idx, col)
                     tooltip = mpld3.plugins.LineLabelTooltip(lines[idx], name)
                     #voffset=10, hoffset=10,  css=css)
                     mpld3.plugins.connect(f, tooltip)
                 
                 mpld3.plugins.connect(f, HighlightLines(lines))
             
             plot_and_message += mpld3.fig_to_html(f)
         else:
             plot_and_message += mpl2html(f)
         
         self.fig_old = f
     
     else:
         plot_and_message += html_figure(self.fig_old)
     
     # VALUE IS WHAT GUI LOOKS UP!!!
     self.value = plot_and_message
开发者ID:Schroedingberg,项目名称:scikit-spectra,代码行数:60,代码来源:Corrspecgram.py

示例12: plot_to_html

def plot_to_html( name = None ):
    """Converts a matplotlib figure, such that it can be displayed in an html page
        either using an embedded svg tag (default)
        or by using mpld3 
    """
    result = ""
    if mpld3_available and use_mpld3 :
        html = mpld3.fig_to_html( plt.gcf() )
        result = html
    else:
        figStr = io.StringIO()
        plt.savefig( figStr, format='svg', bbox_inches='tight' )
        result = figStr.getvalue()
    
    if write_pdfs and name:
        if not os.path.exists(pdf_output_dir):
            os.makedirs(pdf_output_dir)

        filename = os.path.join(pdf_output_dir, name + '.pdf')
        filepath = os.path.join(filename)
        plt.savefig( filepath, bbox_inches='tight' )
        result = '<a href="%s" > %s </a>' % ( filename, result )
        
    plt.clf()
        
    return result
开发者ID:Haider-BA,项目名称:walberla,代码行数:26,代码来源:report.py

示例13: map_plot

def map_plot():
    import matplotlib.pyplot as plt, mpld3
    import numpy as np
    from mpl_toolkits.basemap import Basemap

    fig, ax = plt.subplots()
    m = Basemap()
    #m = Basemap(projection='ortho',lat_0=0,lon_0=0,resolution='l')     
    #m = Basemap(projection='moll',lon_0=0,resolution='l')     
    # Shift 'lon' from [0,360] to [-180,180], make numpy array
    #tmp_lon = np.array([lon[n]-360 if l>=180 else lon[n] 
    #                   for n,l in enumerate(lon)])  # => [0,180]U[-180,2.5]
    
    #i_east, = np.where(tmp_lon>=0)  # indices of east lon
    #i_west, = np.where(tmp_lon<0)   # indices of west lon
    #lon = np.hstack((tmp_lon[i_west], tmp_lon[i_east]))  # stack the 2 halves
    
    # Correspondingly, shift the 'air' array
    #tmp_air = np.array(air)
    #air = np.hstack((tmp_air[:,i_west], tmp_air[:,i_east]))
    #poly_paths = m.drawcoastlines().get_paths() # coastline polygon paths
    #X,Y = np.meshgrid(lon,lat)
    
    m.etopo()
    #m.contourf(X, Y, air, 40, alpha=.75, cmap='jet')
    #ticks=range(-90,90,30)
    #ax.set_yticks(ticks)
    
    #ax.set_ylabel("Latitude", fontsize=16)
    #ax.set_xlabel("Longitude", fontsize=16)
    #plt.colorbar()
    
    # D3 Works!
    #mpld3.display(fig)
    return mpld3.fig_to_html(fig,template_type="general")
开发者ID:axnsantana,项目名称:vimap,代码行数:35,代码来源:default.py

示例14: simple_plot

def simple_plot():
    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt, mpld3
    fig, ax = plt.subplots()
    plot = ax.plot([3,1,4,1,5], 'ks-', mec='w', mew=5, ms=20)
    return mpld3.fig_to_html(fig, template_type = "general")
开发者ID:axnsantana,项目名称:vimap,代码行数:7,代码来源:default.py

示例15: generate_histogram

def generate_histogram(dates, values):
    """
    Generate a barchart from the given information.

    This function receives a list of floats and a list of labels
    and uses them to generates a barchart histogram.

    Keyword arguments:
    values -- a list of values for each bar of the chart.
    labels -- a list of labels for each bar of the chart.
    """
    #n_groups = len(values)


    fig, axes = plt.subplots()
    axes.plot(dates, values, 'o--')
    plt.ylim([0, 5])
    one_mon_rel = relativedelta(months=1)
    plt.xlim([min(dates), max(dates) + one_mon_rel])
    fig.set_size_inches(12, 5)
    plt.xlabel('Videos through time')
    plt.ylabel('Mean video scores')
    plt.title('Channel\'s video progress through time')
    plt.legend()
    plt.tight_layout()

    return mpld3.fig_to_html(fig)
开发者ID:karavias,项目名称:datamining,代码行数:27,代码来源:dm_plotlib.py


注:本文中的mpld3.fig_to_html函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。