Пример #1
0
def plot_LP_YP(file, outfile='Lx-P.html',
      title='L-P Relation for Radio Halo Clusters',
      categories = ["Limit+SZ", "Limit-SZ", "RHclusters"],
      colors=['#462066', '#00AAA0', '#FF7A5A'],
      xaxis_label='0.1-2.4 keV X-ray Luminosity (x 1E+44 erg/s)',
      yaxis_label='1.4 GHz Radio Halo Power (x 1E+24 W/Hz)',
      label_font_size='14pt', title_font_size='16pt',
      x_range=[1, 50], y_range=[0.1,100], xsize=600, ysize=600,
      x_axis_type="log", y_axis_type="log",
      legend=["Upper limits on RH power, with SZ",
        "Upper limits on RH power, no SZ", "RH detections"],
      TOOLS="crosshair,pan,wheel_zoom,box_zoom,reset,hover,hover,hover,hover,previewsave",
      withSZ=False, withLP=True):

    clusters = filter_clusters(file)
    output_file(outfile, title=title)


    if withSZ == True and withLP == True:
        p1 = plot_LP(clusters)
        p2 = plot_YP(clusters)
        p2.y_range = p1.y_range
        p = gridplot([[p1,p2]], toolbar_location='above')
        show(p)
    elif withLP != True and withSZ == True:
        p2 = plot_YP(clusters)
        show(p2)
    elif withLP == True and withSZ != True:
        p1 = plot_LP(clusters)
        show(p1)
Пример #2
0
def main(sa):
    pains_filename = sa[0]
    fp_list = FileHandler.SlnFile(pains_filename).get_fingerprint_list()
    clusters = clust(fp_list)
    p = pca_plot(fp_list, clusters)
    output_file("PCA_w_hclust.html")
    show(p)
Пример #3
0
    def plot(size, text, free):

        print text
        print size
        print free
        data = {
            'left': [],
            'right': [],
            'text': [],
            'color': [],
            'text_center': []
        }

        left = 0
        for i in xrange(0, len(size)):
            data['left'].append(left)
            data['right'].append(left + size[i] * graph_width)
            left = data['right'][i]
            if free[i] is 1:
                data['color'].append("Green")
            else:
                data['color'].append("Yellow")
            data['text'].append(text[i])
            data['text_center'].append((data['right'][i] - data['left'][i])/2 + data['left'][i])

        print data['text']
        output_file("test.html")
        plot = figure(width=graph_width, height=300)
        plot.quad(top=1, bottom=0, left=data['left'], right=data['right'],
                  color=data['color'],
                  name="hello", line_color="black")
        plot.text(x=data['text_center'], y=0.5, angle=math.pi/2, text=data['text'], text_align="center")

        show(plot)
Пример #4
0
	def plot(self, thresh):

		# Source the lists defined earlier (which will contain values once one of the
		# above methods is called. This step is necessary for the functionality of the HoverTool created later.
		source1 = ColumnDataSource(data=dict(ggx=gx, ggy=gy))
		source2 = ColumnDataSource(data=dict(rrx=rx, rry=ry))
		source3 = ColumnDataSource(data=dict(ggsize=gsize, rrsize=rsize))
		
		# Name the bokeh output.
		output_file("quality.html")

		# Generate the dynamic bokeh figure, called 'p.'
		p = figure(plot_width=1000, plot_height=500) 
		p.title = "Quality-ranked Variants across Genomic Position"

		# Generate a 'threshold line' based on the user's quality score threshold.
		thresh_line = Span(location = thresh, dimension='width', line_color='blue', line_width=3)
		p.renderers.extend([thresh_line])

		# Add x and y axis labels.
		p.yaxis.axis_label = "Phred-scaled Quality Score"
		p.xaxis.axis_label = "Position (kilobases)"

		# Generate the hover function for each red and green circle that is plotted.
		r1 = p.circle(gx, gy, size=gsize, color='green', alpha=0.5, legend="Pass Variant", source=source1)
		r1_hover = HoverTool(renderers=[r1], tooltips=[('Position (kb)', '@ggx') , ('Quality', '@ggy')])
		p.add_tools(r1_hover)

		r2 = p.circle(rx, ry, size=gsize, color='red', alpha=0.5, legend="Fail Variant", source=source2)
		r2_hover = HoverTool(renderers=[r2], tooltips=[('Position (kb)', '@rrx') , ('Quality', '@rry')])
		p.add_tools(r2_hover)

		# Add a legend to the figure.
		p.legend.location = "top_left"
		show(p)
Пример #5
0
def bokeh2(X):
    Y = de_mean_matrix(X)    

    TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave,box_select"
    
    hover = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),
        ]
    )

    bplt.output_file("data.html", title="Rescaling")
    
    s1 = bplt.figure(width=500, plot_height=250, title="Data", tools=[hover, TOOLS])
    s1.scatter(X[:,0].A1, X[:,1].A1, marker="circle",
              line_color="#6666ee", fill_color="#ee6666",
              fill_alpha=0.5, size=12)
    
    s2 = bplt.figure(width=500, plot_height=250, title="De-meaned", tools=TOOLS)
    s2.scatter(Y[:,0].A1, Y[:,1].A1, marker="circle",
              line_color="#6666ee", fill_color="#ee6666",
              fill_alpha=0.5, size=12)
    
    # put all the plots in a VBox
    p = bplt.vplot(s1, s2)
    
    # show the results
    bplt.show(p)
Пример #6
0
def main():
    xs = np.linspace(-np.pi, np.pi, 100, endpoint=True)
    xs = np.linspace(0, 4*np.pi, 100)
    ys_exp = np.exp(xs)
    ys_sin = np.sin(xs)
    ys_cos = np.sin(xs)
    ys_tan = np.tan(xs)

    output_file("grid_example.html")

    fig1 = figure(width=250, plot_height=250, title=None)
    fig1.circle(xs, ys_exp, size=10, color="navy", alpha=0.5)

    fig2 = figure(width=250, plot_height=250,
                  x_range=fig1.x_range, title=None)
    fig2.triangle(xs, ys_sin, size=10, color="firebrick", alpha=0.5)

    fig3 = figure(width=250, height=250,
                  x_range=fig2.x_range, y_range=fig2.y_range, title=None)
    fig3.square(xs, ys_cos, color="olive")

    fig4 = figure(width=250, height=250, title=None)
    fig4.line(xs, ys_tan, color="green")

    show(gridplot([[fig1, fig2],
                   [fig3, fig4]]))
Пример #7
0
 def __init__(self, data, title="test", xlabel="test", ylabel="test"):
     self.__data = data
     self.__p1 = figure(title=title, tools="save", background_fill="#E8DDCB")
     self.__p1.legend.location = "top_left"
     self.__p1.xaxis.axis_label = xlabel
     self.__p1.yaxis.axis_label = ylabel
     output_file("histogram.html", title=title)
Пример #8
0
def main():
    """
    create empty binary tree Mobile
    make a balanced mobile out of it    
    """
    max_depth = 3
    prob_child = .75

    mobile1 = Mobile(max_depth, prob_child)
    mobile1.print_mobile()
    print
    
    x = 20
    y = 30
    stringLength = 5
    mass = 10.0
    armLength = 12.0
    armLength_L = 6
    mobile1.build_balanced_mobile_top_down(x, y, stringLength, mass, armLength, armLength_L)

    mobile1.print_mobile()

    output_file("test.html")

    # create a new plot with a title and axis labels
    s1 = figure(title="The Mobile  - " + " Mass: " + str(mass) 
        + ", Depth: " + str(mobile1.depth), 
           x_axis_label='x', y_axis_label='y', title_text_font_size='14pt', plot_width=700)

    s1.xgrid.grid_line_color = None
    s1.ygrid.grid_line_color = None
    
    # draw the mobile
    mobile1.draw_mobile(s1)
    show(s1)
Пример #9
0
    def startPlot(self, **kwargs):
        """prepare everything for a plot.

        returns the current figure.
        """
        self.bokeh_figure = bk.figure()
        bk.output_file('/dev/null')
Пример #10
0
def show_plot():
  ticker = request.form['ticker']	
  today_string = time.strftime("%x")
  today_list = today_string.split("/")
  year = int(today_list[2]) + 2000
  month = int(today_list[0])-1
  if month == 0:
    month = 12
    year -= 1
  start_date=(str(year) + '-' + str(month) + '-' + today_list[1])	
  url = "https://www.quandl.com/api/v3/datasets/WIKI/" + ticker + ".json?start_date=" + start_date
  r = requests.get(url)
  if r.status_code == 404:
    return redirect('/error')
  if r.status_code == 400:
    return redirect('/bad-request')
  j = json.loads(r.text)
  data = pd.DataFrame(data=j['dataset']['data'], columns=j['dataset']['column_names'])
  data = data.set_index(['Date'])
  data.index = pd.to_datetime(data.index)
  output_file("test.html")
  p = figure(plot_width=400, plot_height=400, x_axis_type="datetime")
  p.line(data.index, data['Close'], line_width=2)		
  script, div = components(p)	
  return render_template('show-plot.css', name=j['dataset']['name'], stock=ticker, script=script, div=div)
Пример #11
0
def plot_k(df):
    i_src = ColumnDataSource(df[df.open <  df.close])
    d_src = ColumnDataSource(df[df.open >= df.close])
    w = 16*60*60*1000 # half day in ms

    TOOLS = "pan,xwheel_zoom,ywheel_zoom,box_zoom,reset,save"

    p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1500, plot_height=640, title = "MSFT Candlestick") # hei 880
    p.toolbar.active_scroll = "auto"
    p.xaxis.major_label_orientation = pi/4
    p.grid.grid_line_alpha=0.3
    p.background_fill_color = "black"

    p.segment('date', 'high', 'date', 'low', source=i_src, color="red")
    p.segment('date', 'high', 'date', 'low', source=d_src, color="green")

    p.vbar('date', w, 'open', 'close', source=i_src, name="kline", fill_color="red", line_color="red")
    p.vbar('date', w, 'open', 'close', source=d_src, name="kline", fill_color="green", line_color="green")

    p.add_tools(HoverTool(tooltips= [("date","@ToolTipDates"),
                                     ("close","@close{0,0.00}"),
                                     ("high","@high{0,0.00}"),
                                     ("low","@low{0,0.00}")], names= ["kline",], ))
    p.add_tools(CrosshairTool(line_color='grey'))

    inc_process(df, p)

    output_file("candlestick.html", title="candlestick.py example", mode='inline')
    gridplot()
    show(p)  # open a browser
Пример #12
0
def render_table(sym):
    df = get_data(sym)

    text_input = TextInput(value=sym.upper(), title="Label:")
    mids = (df['open'] + df['close'])/2
    spans = abs(df['open'] - df['close'])
    inc = df['close'] > df['open']
    dec = df['close'] < df['open']
    w = 12*60*60*1000 # half day in ms

    TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

    global p
    p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=750, plot_height=300, toolbar_location="left")

    p.title = sym.upper() + " Candlestick"
    p.xaxis.major_label_orientation = pi/4
    p.grid.grid_line_alpha=0.3

    p.segment(df.date, df.high, df.date, df.low, color="black")
    p.rect(df.date[inc], mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color="black")
    p.rect(df.date[dec], mids[dec], w, spans[dec], fill_color="#F2583E", line_color="black")

    session = push_session(curdoc())

    curdoc().add_periodic_callback(update, 1000)

    session.show() # open the document in a browser

    session.loop_until_closed() # run forever
    output_file("candlestick.html", title="candlestick.py example")
Пример #13
0
def bokeh_plot(df):
    tooltip = """
        <div>
            <div>
                <img
                src="@image_files" height="60" alt="image"
                style="float: left; margin: 0px 15px 15px 0px; image-rendering: pixelated;"
                border="2"
                ></img>
            </div>
            <div>
                <span style="font-size: 17px;">@source_filenames</span>
            </div>
        </div>
              """
    filenames = b64_image_files(df['images'])
    df['image_files'] = filenames
    colors_raw = cm.viridis((df['time'] - df['time'].min()) /
                            (df['time'].max() - df['time'].min()), bytes=True)
    colors_str = ['#%02x%02x%02x' % tuple(c[:3]) for c in colors_raw]
    df['color'] = colors_str
    source = ColumnDataSource(df)
    bplot.output_file('plot.html')
    hover0 = HoverTool(tooltips=tooltip)
    hover1 = HoverTool(tooltips=tooltip)
    tools0 = [t() for t in TOOLS] + [hover0]
    tools1 = [t() for t in TOOLS] + [hover1]
    pca = bplot.figure(tools=tools0)
    pca.circle('PC1', 'PC2', color='color', source=source)
    tsne = bplot.figure(tools=tools1)
    tsne.circle('tSNE-0', 'tSNE-1', color='color', source=source)
    p = bplot.gridplot([[pca, tsne]])
    bplot.show(p)
Пример #14
0
    def plot(self, output_file="termite.html"):
        t = blz.Data(self.input_file)
        df = pd.read_csv(self.input_file)

        MAX =  blz.compute(t.weight.max())
        MIN = blz.compute(t.weight.min())

        # Create a size variable to define the size of the the circle for the plot.
        t = blz.transform(t, size=blz.sqrt((t.weight - MIN)/(MAX - MIN))*50)

        WORDS = t['word'].distinct()
        WORDS = into(list, WORDS)
        topics = t['topic'].distinct()
        topics = into(list, topics)
        # Convert topics to strings
        TOPICS = [str(i) for i in topics]

        source = into(pd.DataFrame, t)

        plt.output_file(output_file)

        data_source = ColumnDataSource(source)

        p = plt.figure(x_range=TOPICS, y_range=WORDS,
               plot_width=1000, plot_height=1700,
               title=self.title)

        p.circle(x="topic", y="word", size="size", fill_alpha=0.6, source=data_source)
        #p.xaxis().major_label_orientation = np.pi/3
        logging.info("generating termite plot for file %s" % self.input_file)
        plt.show(p)
Пример #15
0
def choropleth_usa_states(scores, filename, title='USA States Choropleth'):
    """
    Plot choropleth of US states based on a score for each state
    """
    states = us_states.data.copy()
    
    del states['HI']
    del states['AK']
    
    state_xs = [states[code]['lons'] for code in states]
    state_ys = [states[code]['lats'] for code in states]
    
    state_colors = []
    for state in states:
        try:
            ind = 4 - min(int(scores[state.lower()]*4), 4)
            state_colors.append(PuRd5[ind])
        except KeyError:
            state_colors.append('white')
    
    p = figure(title=title, toolbar_location='left', plot_width=1100, plot_height=700)
    
    p.patches(state_xs, state_ys, fill_color=state_colors, fill_alpha=0.7,
        line_color='#884444', line_width=2)
    
    output_file(filename, title=title)

    show(p)
    
    return
def plot_summaries(output_directory, normalized_counts, chromosomes):
    bp.output_file(output_directory + "/summary.html")
    
    for chromosome in chromosomes:
        plot_summary(normalized_counts, chromosome)

    bp.save()
Пример #17
0
def analyze_amendement():
    api = NDApi()

    df = pandas.DataFrame(api.synthese())

    colormap = {
        u'UMP': '#0000CD',
        u'ECOLO': '#32CD32',
        u'SRC': '#FF69B4',
        u'NI': 'grey',
        u'GDR': '#DC143C',
        u'UDI': '#87CEFA',
        u'RRDP': '#FFFF00',
    }

    df['colors'] = df.groupe_sigle.map(lambda x: colormap[x])

    print df.describe()

    output_file('amendement_analysis.html', title=u'Analyse amendement')

    p = figure(title=u'Amendement')
    p.xaxis.axis_label = u'Signé'
    p.yaxis.axis_label = u'Adopté'

    p.scatter(df.amendements_signes, df.amendements_adoptes, color=df.colors, fill_alpha=0.6, size=10)

    show(p)
Пример #18
0
def main():
    xs=np.linspace(-5,5,num=100,endpoint=True)
    ys=xs**2
    output_file("example_with_option.html")
    p=figure(title="quadratic curve",x_axis_label="x",y_axis_label="y")
    p.line(xs,ys,legend="y=x^2")
    show(p)
Пример #19
0
def Main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-st", dest="stationId", nargs = '*', help="Please provide a list of station Id.")
    parser.add_argument("-ct", dest="cityName", nargs = '*', help="Please provide a list of city names corresponding to stations.")
    args = parser.parse_args()
    CurrentPath = os.getcwd()
    for i in range(len(args.stationId)):
        FilePath= (CurrentPath+'/DataFiles/GDD_Data_'+args.cityName[i]+'.csv')
        Data, Date, MaxTemp, MinTemp = extract_data_from_csv(FilePath)
        Data['date'] = pd.to_datetime(Date)
        Data['left'] = Data.date - pd.DateOffset(days=0.5)
        Data['right'] = Data.date + pd.DateOffset(days=0.5)
        PlotDate =[]
        plotDate = Data['right']
        Data = Data.set_index(['date'])
        Data.sort_index(inplace=True)
        source = ColumnDataSource(data=Data)
        AverageTemp = []
        for index in range(len(MinTemp)):
            Average=(MinTemp[index]+MaxTemp[index])/2
            AverageTemp.append(Average)
    
        percent = 5
        Min_5_95, Max_5_95 =percentile_Calculation(MinTemp,MaxTemp,percent)
        percent = 25
        Min_25_75, Max_25_75 =percentile_Calculation(MinTemp,MaxTemp,percent)

        plot = make_plot(source,AverageTemp,Min_5_95,Max_5_95,Min_25_75,Max_25_75, MinTemp,MaxTemp,plotDate,args.cityName[i])
        output_file("./Plots/Op1_"+args.cityName[i]+".html", title="Optional Task # 1 ("+args.cityName[i]+")")
        save(plot)
Пример #20
0
def Main():
#    parser = argparse.ArgumentParser()
#    parser.add_argument("-st", dest="stationId", nargs = '*', help="Please provide a list of station Id.")
#    parser.add_argument("-ct", dest="cityName", nargs = '*', help="Please provide a list of city names corresponding to stations.")
	
#    args = parser.parse_args()
	
#city = args.cityName[0]
	
    #cities = { 
    #    args.cityName[0] : {'ID':args.stationId[0]},
    #    args.cityName[1] : {'ID':args.stationId[1]},
    #    args.cityName[2] : {'ID':args.stationId[2]}
    #}
	
   
#    for c in cities.keys():
    
    global source
    source = DataSet('St_Johns')
    plot = make_plot(source, city)
    city_select.on_change('value', update_plot)
	
    # add to document
    output_file("./Plots/Op5.html", title="Optional Task # 5")
    save(HBox(city_select, plot))
	
    curdoc().add_root(HBox(city_select, plot))
Пример #21
0
def index():
    if request.method == 'GET':
        return render_template('index.html')
    else:
#request was a POST
        app.vars['abbrev'] = request.form['abbrev']

        abbrev = app.vars['abbrev']

        f = open('%s.txt'%(app.vars['abbrev']),'w')
        f.write('Stock abbreviation: %s'%(app.vars['abbrev']))
        f.close()

        #Get the closing value of the stock over the last month into a pandas Series:
        StockURL = 'https://www.quandl.com/api/v3/datasets/WIKI/' + abbrev + '.csv'
        dataSet = pd.read_csv(StockURL, parse_dates=['Date'])

        output_file('templates/datetime_'+abbrev+'.html')

        p = figure(width=800, height=250, x_axis_type="datetime", title=abbrev, y_axis_label='Price (in dollars)')

        #p.grid.bounds(dataSet['Date'][0], dataSet['Date'][29])
        #print dataSet['Date'][0], dataSet['Date'][29]
        p.line(dataSet[0:30]['Date'], dataSet[0:30]['Close'], color='navy', alpha=0.5, legend = 'Closing price')
        if 'adjustedClose' in request.form:
            p.line(dataSet[0:30]['Date'], dataSet[0:30]['Adj. Close'], color='purple', alpha=0.5, legend = 'Adjusted Closing price')
        if 'openValue' in request.form:
            p.line(dataSet[0:30]['Date'], dataSet[0:30]['Open'], color='red', alpha=0.5, legend = 'Opening price')
        if 'adjustedOpen' in request.form:
            p.line(dataSet[0:30]['Date'], dataSet[0:30]['Adj. Open'], color='black', alpha=0.5, legend = 'Adjusted opening price')
            
        p.legend.orientation = "top_left"

        save(p)
        return render_template('datetime_'+abbrev+'.html')
Пример #22
0
def gap_test():
    from math import pi

    import pandas as pd

    from bokeh.plotting import figure, show, output_file
    from bokeh.sampledata.stocks import MSFT

    df = pd.DataFrame(MSFT)[:50]
    df["date"] = pd.to_datetime(df["date"])

    mids = (df.open + df.close)/2
    spans = abs(df.close-df.open)

    inc = df.close > df.open
    dec = df.open > df.close
    w = 12*60*60*1000  # half day in ms

    TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

    p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, title="MSFT Candlestick")
    p.xaxis.major_label_orientation = pi/4
    p.grid.grid_line_alpha = 0.3

    p.segment(df.date, df.high, df.date, df.low, color="black")
    p.rect(df.date[inc], mids[inc], w, spans[inc], fill_color="#D5E1DD", line_color="black")
    p.rect(df.date[dec], mids[dec], w, spans[dec], fill_color="#F2583E", line_color="black")

    output_file(config.bokeh_output_dir + 'candlestick.html', title='candlestick.py example')

    save(p)
    return send_from_directory(config.static_files_path,
                               config.bokeh_output_dir + 'candlestick.html')
Пример #23
0
def main():
    xs=list(range(-5,5+1,1))
    ys=list(map(lambda x:x**2,xs))
    output_file("minimum_example.html")
    p=figure()
    p.line(xs,ys)
    show(p)
Пример #24
0
    def bokeh_plot(self):
        import os
        from bokeh.plotting import line
        from bokeh.plotting import hold, figure, show, output_file
        import numpy as np
        import bokeh.embed as embed

        figure()
        hold()

        for i in self.SensorDict:
            line(
                self.SensorDict[i]['dates'], self.SensorDict[i]['values']
            )
            print(len(self.SensorDict[i]['dates']))
            #print(self.SensorDict[i]['dates'][0])
            #print(self.SensorDict[i]['values'][0])
        print('tjo')
        os.chdir('..')
        os.chdir('..')

        output_file('plot.html', title='Plot22')




        show()
Пример #25
0
def plot_interactive(mergepkl, noisepkl=None, thresh=6.0, thresh_link=7.0, ignoret=None, savehtml=True, url_path='plots'):
    """ Backwards compatible function for making interactive candidate summary plot """

    data = readdata(mergepkl)
    circleinds = calcinds(data, thresh, ignoret)
    crossinds = calcinds(data, -1*thresh, ignoret)
    edgeinds = calcinds(data, thresh_link, ignoret)

    workdir = os.path.dirname(mergepkl)
    fileroot = os.path.basename(mergepkl).rstrip('_merge.pkl').lstrip('cands_')

    logger.info('Total on target time: {} s'.format(calcontime(data, inds=circleinds+crossinds+edgeinds)))

    if noisepkl:
        noiseplot = plotnoisecum(noisepkl)
    else:
        noiseplot = None

    combined = plotall(data, circleinds=circleinds, crossinds=crossinds, edgeinds=edgeinds,
                       htmlname=None, noiseplot=noiseplot, url_path=url_path, fileroot=fileroot)

    if savehtml:
        output_file(mergepkl.rstrip('.pkl') + '.html')
        save(combined)
    else:
        return combined
Пример #26
0
def graph():
  global dataset
  global list

  url='https://www.quandl.com/api/v3/datasets/WIKI/'+dataset+'/data.csv'
  df=pd.read_csv(url,parse_dates=['Date'])
  output_file('graph.html')
  p=figure(title='Data from Quandle WIKI set',x_axis_label='Date',x_axis_type='datetime')  
  att=list
  p.line(df['Date'],df[att],legend=att,color="blue",line_width=1)
  comp=dataset

  template = jinja2.Template("""
  <!DOCTYPE html>
  <html>
    <head>
    <link rel="stylesheet" href="http://cdn.pydata.org/bokeh/release/bokeh-0.9.2.min.css" type="text/css" />
    <script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.9.2.min.js"></script>
    {{ script | safe }}
    </head>
    <body>
      <div class=page>
        <h1>Generated graph for {{ comp }} </h1>
        {{ div | safe }}
      </div>
    </body>
  </html> 
   """)
  script, div = components(p)

  return template.render(script=script, div=div,comp=comp)  
Пример #27
0
def visualize_data(data_output_file):
    from bokeh.plotting import figure, output_file, save, vplot
    from bokeh.models import ColumnDataSource, FactorRange

    plots = []

    # output to static HTML file
    output_file(data_output_file, title='Eye Tracking Data', mode='cdn')

    for file_name, file_data in data.iteritems():
        # prepare the data
        line_types = [line_data[0] for line_data in file_data]
        #line_types_top = [line_data[0] + '2.0' for line_data in file_data]
        #line_types_bot = [line_data[0] + '1.0' for line_data in file_data]
        times = [line_data[1] for line_data in file_data]
        start_times = [line_data[2] for line_data in file_data]
        end_times = [line_data[3] for line_data in file_data]
        descs = [line_data[4] for line_data in file_data]

        #x0 = [0 for type_ in line_types]

        '''source = ColumnDataSource({
            'time': times,
            'start': start_times,
            'end': end_times,
            'line_types_top': line_types_top,
            'line_types_bot': line_types_bot,
        })'''

        source = ColumnDataSource({
            'x': [(t1 + t2)/2 for t1, t2 in zip(start_times, end_times)],
            'y': line_types,
            'width': times,
            'height': [0.7 for _ in line_types],
            'fill_color': ['red' if 'Incorrect' in desc \
                    else 'green' for desc in descs]
        })

        # create a new plot
        plot = figure(
           tools='pan,reset,save',
           title=file_name, y_range=FactorRange(factors=line_types[::-1]),
           x_range=[0, sum(times)],
           x_axis_label='Time (ms)', y_axis_label='Line Type'
        )

        plot.rect(x='x', y='y', width='width', height='height', \
            fill_color='fill_color', source=source)

        #plot.quad(left='start', right='end', \
        #    top='line_types_top', bottom='line_types_bot', source=source)
    
        # add some renderers
        #plot.segment(x0, line_types, times, line_types, \
        #    line_width=2, line_color="green")

        plots.append(plot)

    # show the results
    save(vplot(*plots))
Пример #28
0
def results():  #remember the function name does not need to match the URL
	idx = str.upper(request.form['inputticker'])
	p = re.compile('\W')
	idx = p.sub('',idx)
	
	call = baseurl+idx+suffixurl
	rj = requests.get(call).json()
	rj = rj['dataset']
	data = pd.DataFrame(rj['data'], columns=rj['column_names'])	

	x = pd.to_datetime(data.iloc[:,0])
	y = data.iloc[:,-1]

	toollist = "pan,box_zoom,reset,save,resize"

	output_file("templates/output.html", title='Volatility Index Graph')
	p = figure(x_axis_label=data.columns[0], y_axis_label=data.columns[-1], \
	x_axis_type="datetime", tools=toollist, plot_width=800, plot_height=500)
	p.line(x, y, line_width=1, line_color="CornflowerBlue")
	p.title = codes.Name.values[codes.Ticker.values==idx][0]
	p.responsive = True

	script, div = components(p)

	return render_template('output.html', script=script, div=div)
Пример #29
0
    def plot(self, output_file="termite.html"):
        import blaze as blz
        from odo import into
        import pandas as pd
        import bokeh.plotting as plt
        from bokeh.models.sources import ColumnDataSource

        t = blz.Data(self.input_file)

        MAX = blz.compute(t.weight.max())
        MIN = blz.compute(t.weight.min())

        # Create a size variable to define the size of the the circle for the plot.
        t = blz.transform(t, size=blz.sqrt((t.weight - MIN)/(MAX - MIN))*50)

        WORDS = t['word'].distinct()
        WORDS = into(list, WORDS)
        topics = t['topic'].distinct()
        topics = into(list, topics)
        # Convert topics to strings
        TOPICS = [str(i) for i in topics]

        source = into(pd.DataFrame, t)

        plt.output_file(output_file)

        data_source = ColumnDataSource(source)

        p = plt.figure(x_range=TOPICS, y_range=WORDS,
                       plot_width=1000, plot_height=1700,
                       title=self.title)

        p.circle(x="topic", y="word", size="size", fill_alpha=0.6, source=data_source)
        plt.show(p)
Пример #30
0
def values(generations):
    generation_indexes = range(len(generations))

    fig = figure()

    fig.xaxis.axis_label = 'generation'

    maxes = [max([value for game, value in generation])
             for generation in generations]
    mins = [min([value for game, value in generation])
            for generation in generations]
    averages = [sum([value for game, value in generation]) / len(generation)
                for generation in generations]

    value_groups = (
        ('max value', 'green', maxes),
        ('min value', 'red', mins),
        ('average value', 'blue', averages),
    )

    for name, color, values in value_groups:
        fig.line(generation_indexes, values, color=color, legend=name)

    output_file("values.html")
    show(fig)
def circles_main():
    '''
    red, blue, yellow and green circles are used for testing and plotting with boken
    Convention for all lists of coordinates is x = list[0] and y = list[1]
    substations is in the form [([x1,y1], name), ([x2,y2], name), ...]
    '''
    '''
    circles = []
    circle_file = open('substations.csv', 'r')
    circle_file.readline()
    for line in circle_file:
        circle_line = line.split(',')
        file_name = circle_line[0] + '.csv'
        circles.append(Circle(circle_line[0], [float(circle_line[1]), float(circle_line[2])], create_circle_linestring([float(circle_line[1]), float(circle_line[2])]), file_name, random.choice(['red', 'blue', 'yellow', 'green', 'purple', 'orange', 'pink'])))
    '''
    red_circle_centre = [50, -10]
    blue_circle_centre = [-20,29]
    yellow_circle_centre = [300, 350]
    green_circle_centre = [0, 0]

    # test cases for kml circles
    red_circle = Circle('red', red_circle_centre, create_circle_linestring(red_circle_centre), 'red_circle.csv', 'red')
    blue_circle = Circle('blue', blue_circle_centre, create_circle_linestring(blue_circle_centre), 'blue_cirlce.csv', 'blue')
    green_circle = Circle('green', green_circle_centre, create_circle_linestring(green_circle_centre), 'green_circle.csv', 'green')
    yellow_circle = Circle('yellow', yellow_circle_centre, create_circle_linestring(yellow_circle_centre), 'yellow_circle.csv', 'yellow')
    

    circles = [red_circle, blue_circle, green_circle, yellow_circle]  # list of all the circle objects
    
    for circle in circles:  # cycle through the list of circles and check which ones are touching, without checking the same pair twice
        for other_circle in circles:
            if not(other_circle == circle):
                if circles_overlapping(circle, other_circle): # if circles are touching (within 200km of each other)
                    print('{} and {} are overlapping'.format(circle.name, other_circle.name))
                    print(get_theoretical_intercepts(circle, other_circle))

                    # get the index of the closest coordinate in the linestring to the theoretical intercept value
                    left_intercept = circle.linestring.index(get_closest_coord(get_theoretical_intercepts(circle, other_circle)[0], circle.linestring)) 
                    right_intercept = circle.linestring.index(get_closest_coord(get_theoretical_intercepts(circle, other_circle)[1], circle.linestring))
                    
                    # determine which occurs first, leftmost intercept or rightmost intercept
                    if right_intercept > left_intercept:
                        top_iteration = right_intercept
                        lower_iteration = left_intercept
                    else:
                        top_iteration = left_intercept
                        lower_iteration = right_intercept
                    
                    # in the case of two overlapping circles, no more than half of the perimeter should be removed. 
                    if (top_iteration - lower_iteration) > 314:  # check is the amount of circle to the removed is greater than half of the linestring
                        to_keep = []  # keep the greater segment of the linestring in the circle
                        for i in range(lower_iteration, top_iteration):
                            to_keep.append(circle.linestring[i])
                        circle.linestring = []
                        for element in to_keep:
                            circle.linestring.append(element)
                        write_csv(circle)
                        print(lower_iteration, top_iteration) 
                    else:
                        to_remove = []  # remove the smaller segment of the linestring in the circle
                        for i in range(lower_iteration, top_iteration):
                            to_remove.append(circle.linestring[i])
                        for element in to_remove:
                            circle.linestring.remove(element)
                        write_csv(circle)
                        print(lower_iteration, top_iteration)                  
                else:
                    print('{} and {} are NOT overlapping\n'.format(circle.name, other_circle.name))
                
    output_file('circle.html')

    # Add plot
    p = figure(  # plotting figure used for testing
        title = 'Circles Testing',
        x_axis_label = 'X axis (km)', 
        y_axis_label = 'Y Axis (km)'
    )
    '''
    for circle in circles:
        for coord in circle.linestring:
            circle.x.append(coord[0])
            circle.y.append(coord[1])
        p.line(circle.x, circle.y, legend=circle.name, line_width=2, color=circle.color)
    # LineString circles
    '''
    
    #Render glyph
    # had to manually format the linestrings to plot them with bokeh
    # an iterative method would be better for dealing with large amounts of circles
    redX = []
    redY = []
    for coord in red_circle.linestring:
        redX.append(coord[0])
        redY.append(coord[1])

    
    blueX = []
    blueY = []
    for coord in blue_circle.linestring:
        blueX.append(coord[0])
        blueY.append(coord[1])
    
    greenX = []
    greenY = []
    for coord in green_circle.linestring:
        greenX.append(coord[0])
        greenY.append(coord[1])

    yellowX = []
    yellowY = []
    for coord in yellow_circle.linestring:
        yellowX.append(coord[0])
        yellowY.append(coord[1])
    
    p.line(redX, redY,legend='Red Circle', line_width=2, color='red')
    p.line(blueX,blueY,legend='Blue Circle', line_width=2, color='blue')
    p.line(greenX,greenY,legend='Green Circle', line_width=2, color='green')
    p.line(yellowX,yellowY,legend='Yellow Circle', line_width=2, color='yellow')
    
    show(p)  # output results in circles.html (opens automatically)
import pandas as pd

from bokeh.plotting import Figure, show, output_file, ColumnDataSource
from bokeh.models import HoverTool

df = pd.read_csv('../../data/processed/mean_success_housing.csv')
df['success_metric'] = df['_c0']
print df.head()

source1 = ColumnDataSource(data=df)
hover1 = HoverTool(tooltips=[("zipcode",
                              "@zipcode"), ("success_metric",
                                            "@success_metric")])

p = Figure(title='Mean Success by zip vs Housing Costs',
           x_axis_label='$/sq. ft.',
           y_axis_label='success_metric',
           tools=['crosshair,resize,reset,save', hover1])

p.circle('2016_02', 'success_metric', color='red', alpha=0.4, source=source1)

output_file("../../reports/figures/mean_success_housing.html",
            title="Success vs Housing cost")
show(p)
Пример #33
0
    def plot(
        self,
        plot_height: int = 900,
        plot_width: int = 900,
        output: str = None,
    ):
        # Set up map options
        map_hover = HoverTool(tooltips=[("Latitude", "@lats"),
                                        ("Longitude", "@lons")],
                              names=["locs"])
        map_options = dict(tools=[map_hover, "pan,wheel_zoom,reset"],
                           plot_width=plot_width,
                           plot_height=plot_height)
        # Get plot bounds in web mercator
        try:
            min_lat, min_lon, max_lat, max_lon = (min(self.lats), min(
                self.lons), max(self.lats), max(self.lons))
        except ValueError as e:
            print(e)
            print("Setting map bounds to NZ")
            min_lat, min_lon, max_lat, max_lon = (-47., 165., -34., 179.9)
        # Add a 10% pad
        lat_pad = 0.25 * (max_lat - min_lat)
        lon_pad = 0.25 * (max_lon - min_lon)
        min_lat = min_lat - lat_pad
        max_lat = max_lat + lat_pad
        min_lon = min_lon - lon_pad
        max_lon = max_lon + lon_pad

        bottom_left = transform(self._proj_in, self._map_proj, min_lon,
                                min_lat)
        top_right = transform(self._proj_in, self._map_proj, max_lon, max_lat)
        map_x_range = (bottom_left[0], top_right[0])
        map_y_range = (bottom_left[1], top_right[1])

        # Make map
        map_plot = figure(
            title=
            "Seismographs - WebMercator projection bias: distances somewhat inaccurate",
            x_range=map_x_range,
            y_range=map_y_range,
            x_axis_type="mercator",
            y_axis_type="mercator",
            match_aspect=True,
            **map_options)
        url = 'http://a.basemaps.cartocdn.com/rastertiles/voyager/{Z}/{X}/{Y}.png'
        attribution = "Tiles by Carto, under CC BY 3.0. Data by OSM, under ODbL"
        map_plot.add_tile(WMTSTileSource(url=url, attribution=attribution))
        # tile_provider = get_provider(CARTODBPOSITRON)
        # map_plot.add_tile(tile_provider)

        # Plot stations
        station_source = ColumnDataSource({
            'y': self.y,
            'x': self.x,
            'lats': self.lats,
            'lons': self.lons,
            'codes': self.codes
        })
        map_plot.triangle(x="x",
                          y="y",
                          size=10,
                          color="blue",
                          alpha=1.0,
                          source=station_source,
                          name="stations")
        labels = LabelSet(x="x",
                          y="y",
                          text="codes",
                          level="glyph",
                          x_offset=2,
                          y_offset=2,
                          source=station_source,
                          render_mode="css",
                          text_font_size="20px")
        map_plot.add_layout(labels)

        # Hack to make invisbile circles of possible locations
        lat_locs, lon_locs, x_locs, y_locs = [], [], [], []
        x_range = map_x_range[1] - map_x_range[0]
        y_range = map_y_range[1] - map_y_range[0]
        for x in np.arange(map_x_range[0] - x_range, map_x_range[1] + x_range,
                           self._precision):
            for y in np.arange(map_y_range[0] - y_range,
                               map_y_range[1] + y_range, self._precision):
                x_locs.append(x)
                y_locs.append(y)
                lon, lat = transform(self._map_proj, self._proj_in, x, y)
                lat_locs.append(lat)
                lon_locs.append(lon)
        possible_locations = ColumnDataSource({
            'y':
            y_locs,
            'x':
            x_locs,
            'lats':
            lat_locs,
            'lons':
            lon_locs,
            'codes': ["location" for _ in x_locs]
        })
        map_plot.rect(x="x",
                      y="y",
                      width=self._precision,
                      height=self._precision,
                      source=possible_locations,
                      fill_color="pink",
                      fill_alpha=0.0,
                      line_color="black",
                      line_alpha=0.0,
                      name="locs")

        # Make circles
        sliders = []
        for station, x, y in zip(self.stations, self.x, self.y):
            # Work out a rough bias in distance due to Web Mercator projection
            dist, _, _ = gps2dist_azimuth(station.latitude, station.longitude,
                                          station.latitude,
                                          station.longitude + 1)
            # dist is distance in km for 1 degree
            _x, _y = transform(self._proj_in, self._map_proj,
                               station.longitude + 1, station.latitude)
            map_dist = abs(x - _x)
            scale_factor = map_dist / dist
            _source = ColumnDataSource({
                "x": [x],
                "y": [y],
                "lats": [station.latitude],
                "lons": [station.longitude],
                "codes": [station.code],
                "radius": [10000]
            })
            circle = map_plot.circle(x='x',
                                     y='y',
                                     source=_source,
                                     radius=10000 * scale_factor,
                                     line_color="red",
                                     fill_alpha=0.0,
                                     line_alpha=1.0,
                                     radius_dimension="x")

            slider = Slider(start=1,
                            end=100,
                            value=10.0,
                            step=self._slider_step,
                            title=f"{station.code} radius (km)")

            callback = CustomJS(
                args=dict(renderer=circle),
                code=
                f"renderer.glyph.radius = cb_obj.value * 1000 * {scale_factor};"
            )

            slider.js_on_change('value', callback)
            sliders.append(slider)

        layout = row(map_plot, column(*sliders))

        if output:
            output_file(output)
            save(layout)
        else:
            show(layout)
Пример #34
0
from bokeh.plotting import figure, show, output_file
from bokeh.tile_providers import get_provider, Vendors

output_file("tile_source.html")

# create plot and add tools
p = figure(x_range=(-2000000, 2000000),
           y_range=(1000000, 7000000),
           x_axis_type="mercator",
           y_axis_type="mercator")
p.add_tile(get_provider(Vendors.CARTODBPOSITRON))

show(p)
Пример #35
0
from bokeh.plotting import figure, output_file, show, ColumnDataSource

output_file("toolbar.html")

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    desc=['A', 'b', 'C', 'd', 'E'],
))

TOOLTIPS = [
    ("index", "$index"),
    ("(x,y)", "($x, $y)"),
    ("desc", "@desc"),
]

p = figure(plot_width=400,
           plot_height=400,
           tooltips=TOOLTIPS,
           title="Mouse over the dots")

p.circle('x', 'y', size=20, source=source)

show(p)
from bokeh.models import BoxAnnotation
from bokeh.plotting import figure, output_file, show
from bokeh.sampledata.glucose import data

output_file("box_annotation.html", title="box_annotation.py example")

TOOLS = "pan,wheel_zoom,box_zoom,reset,save"

#reduce data size
data = data.loc['2010-10-06':'2010-10-13']

p = figure(x_axis_type="datetime", tools=TOOLS)

p.line(data.index.to_series(), data['glucose'], line_color="gray", line_width=1, legend_label="glucose")

low_box = BoxAnnotation(top=80, fill_alpha=0.1, fill_color='red')
mid_box = BoxAnnotation(bottom=80, top=180, fill_alpha=0.1, fill_color='green')
high_box = BoxAnnotation(bottom=180, fill_alpha=0.1, fill_color='red')

p.add_layout(low_box)
p.add_layout(mid_box)
p.add_layout(high_box)

p.title.text = "Glucose Range"
p.xgrid[0].grid_line_color=None
p.ygrid[0].grid_line_alpha=0.5
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Value'

show(p)
Пример #37
0
    'X393 2022MY 544e4 H9211', 'X760 2020MY 335e3 M9023A',
    'L663 2020MY 110 664e6 Y9079A', 'L560 2021MY I6+PHEV 355e3 T9122A'
]

data['dates_str'] = data.dates
# data['dates_str'] = data['dates_str'].replace(np.nan, 'NA')
data['survival_curve'] = data['survival_curve'].round(2)
data['pdf_curve'] = data['pdf_curve'].round(5)
data.dates = pd.to_datetime(data.dates, format='%Y/%m/%d',
                            exact=True)  #TODO check date format
data = data[data.gateway.isin(gateways)]
#
# selected_program = comp['Program Display Name'][comp['total_sum_complexity']>18].values
# data = data[data['test_case'].isin(selected_program)]

output_file(f'dashboard -{model_folder}.html',
            title='Indicative Risk of Programme Delays')

# tcases = data.test_case.unique(
tcases = [i for i in tcases if i in data.test_case.unique()]

sdat = {}
for tc in tcases:
    sdat[tc] = data[data.test_case == tc]

intro_text = f"""
            <p align =right>JLR Corporate and Strategy \ Business Transformation Office \ Analytics CoE</p>            
            <br>
            <br>
            <center><h1>Given delays in current programme gateways, what are the likelihood of subsequent delays?</h1></center>
            <br>
            This visualisation shows the likelihood of various programmes's future gateways' completion dates, given their complexities and the magnitude of current delays as of {date_asof}. 
Пример #38
0
                                    y=list(red_stats['PTS']),
                                    desc=list(red_stats['Player']),
                                    season=list(red_stats['Season'])))

# Define a hover as player and season
hover = HoverTool(tooltips=[
    ('Player', '@desc'),
    ('Season', '@season'),
])

# Define and show graph
plot = figure(plot_width=1000, plot_height=400, tools=[hover])
plot.circle('x', 'y', source=source, size=10, color="red", alpha=0.5)
plot.xaxis.axis_label = 'Usage %'
plot.yaxis.axis_label = 'Points'
output_file('USGvPoints.html')
show(plot)

# Determination of the optimal number of clusters
# Define dataframe to apply the KMeans algorithm
df = red_stats.loc[:, ['PTS', 'AST', 'TRB', 'STL', 'BLK', 'FG%', '3P', '3PA', '3P%', '2P',
                       '2PA', '2P%', 'eFG%', 'USG%']]

# Selection of optimal number of clusters:
inertia = {}
sil_coeff = {}
for k in range(2, 21):
    # Instantiate  KMeans and fit data
    scaler = StandardScaler()
    kmeans = KMeans(n_clusters=k)
    pipeline = make_pipeline(scaler, kmeans)
Пример #39
0
    plt.tick_params(axis='x',labelsize=6,labelrotation=90)
    plt.show()


# %%
yr = 2007
p_no = 3
from bokeh.core.properties import value
from bokeh.plotting import figure
from bokeh.io import show, output_file
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Dropdown
from bokeh.models.callbacks import CustomJS

output_file("bars.html")
xlabels=[]
for key, value in cities.items():
    z = ",\n"
    z = z.join(value)
    xlabels.append(key + ': ' + z)

i = 0
yr_ind=0
p_value = [[0 for x in range(3)] for x in range(18)]
years=[2006,2007,2008,2009,2010,2011,2012,2014,2015,2017]
for v in years:
    if v == yr:
        break
    yr_ind=yr_ind+1
for state, city_list in tp.items():
Пример #40
0
                -big_angle + angles,
                -big_angle + angles,
                color="black")

# game labels
xr = radii[-1] * np.cos(np.array(-big_angle / 2 + angles))
yr = radii[-1] * np.sin(np.array(-big_angle / 2 + angles))
label_angle = np.array(-big_angle / 2 + angles)
label_angle[label_angle < -np.pi / 2] += np.pi
p.text(xr,
       yr,
       df_cnt.game,
       angle=label_angle,
       text_font_size="11pt",
       text_align="center",
       text_baseline="middle")

# display legeends for languages
p.rect([-40, -40, -40, -40], [30, 10, -10, -30],
       width=30,
       height=13,
       color=list(lang_color.values()))
p.text([-15, -15, -15, -15], [30, 10, -10, -30],
       text=list(lang_color),
       text_font_size="9pt",
       text_align="left",
       text_baseline="middle")

output_file("burtin.html", title="Gaming Community Languages")
show(p)
import bokeh.plotting as plt
import bokeh.layouts as lay

import multi_gen.period as period
import multi_gen.runs as runs

save_file = 'susceptible_sim_0_bt_period_plots.html'
plt.output_file(save_file)

sim = period.PlotData.create(runs.runs[1])

layout = lay.column(
    sim[runs.summaries[0]][runs.tables[1]][runs.columns[2]][runs.reg],
    sim[runs.summaries[0]][runs.tables[1]][runs.columns[2]][runs.log],
    sim[runs.summaries[1]][runs.tables[1]][runs.columns[2]][runs.reg],
    sim[runs.summaries[1]][runs.tables[1]][runs.columns[2]][runs.log],
    sim[runs.summaries[0]][runs.tables[2]][runs.columns[2]][runs.reg],
    sim[runs.summaries[0]][runs.tables[2]][runs.columns[2]][runs.log],
    sim[runs.summaries[1]][runs.tables[2]][runs.columns[2]][runs.reg],
    sim[runs.summaries[1]][runs.tables[2]][runs.columns[2]][runs.log],
)
plt.show(layout)
Пример #42
0
def create_bokeh_choro(ff, prop=0):
    """Creates Interactive Bokeh Choropleth for US counties transportationdata.

    Arguments:
        ff {dict} -- Dictionary containing filled dataframes

    Keyword Arguments:
        prop {int} -- Select the property for which choropleth needs to be created (default: {0})
    """
    year = 0
    # Very Important Function
    assert isinstance(prop, int)
    assert isinstance(year, int)
    assert len(ff['CA'][0].columns) > prop >= 0
    assert len(ff['CA'][0].index) > year >= 0
    try:
        # del states["HI"]
        del states["AK"]
    except:
        pass
    nyears = len(ff['CA'][0].index)
    state_xs = [states[code]["lons"] for code in states]
    state_ys = [states[code]["lats"] for code in states]
    county_xs = []
    county_ys = []
    district_name = []
    for cs in bokeh_counties.values():
        for dname in cs:
            county_xs.append([counties[code]["lons"]
                              for code in counties if counties[code]["detailed name"] == dname][0])
            county_ys.append([counties[code]["lats"]
                              for code in counties if counties[code]["detailed name"] == dname][0])
            district_name.append(dname)
    if isinstance(palette, dict):
        color_mapper = LogColorMapper(
            palette=palette[list(palette.keys())[-1]])
    else:
        color_mapper = LogColorMapper(palette=palette)
    pvalues = []

    for yx in range(nyears):
        yvalues = []
        for state in ff.keys():
            for cs in ff[state]:
                yvalues.append(cs.iloc[yx, prop])
        pvalues.append(yvalues)
    alldat = {}
    syear = ff['CA'][0].index[0]
    for ix, yy in enumerate(range(syear, syear + nyears)):
        alldat[str(yy)] = pvalues[ix]
    # alldat = {str(i): v for i, v in enumerate(pvalues)}
    source = ColumnDataSource(data=dict(
        x=county_xs, y=county_ys,
        name=district_name, pvalue=pvalues[0], **alldat))
    TOOLS = "pan,wheel_zoom,reset,hover,save"
    p = figure(title=f"{ff['CA'][0].columns[prop]} across Counties", tools=TOOLS, plot_width=1800,
               plot_height=700, x_axis_location=None, y_axis_location=None)
    p.toolbar.active_scroll = "auto"
    p.toolbar.active_drag = 'auto'
    p.background_fill_color = "#B0E0E6"
    p.patches(state_xs, state_ys, fill_alpha=1.0, fill_color='#FFFFE0',
              line_color="#884444", line_width=2, line_alpha=0.3)
    p.patches('x', 'y', source=source,
              fill_color={'field': 'pvalue', 'transform': color_mapper},
              fill_alpha=0.8, line_color="white", line_width=0.3)
    hover = p.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    property = ff['CA'][0].columns[prop]
    hover.tooltips = [("County", "@name"), (property,
                                            "@pvalue"), ("(Long, Lat)", "($x, $y)")]

    output_file("US_transport.html", title="US Public Transport")
    slider = Slider(start=int(ff['CA'][0].index[0]), end=int(ff['CA'][0].index[-1]),
                    value=int(ff['CA'][0].index[0]), step=1, title="Start Year")

    def update(source=source, slider=slider, window=None):
        """ Update the map: change the bike density measure according to slider
            will be translated to JavaScript and Called in Browser """
        data = source.data
        v = cb_obj.getv('value')
        print(data[v])
        data['pvalue'] = [x for x in data[v]]
        source.trigger('change')
        # source.change.emit()
    slider.js_on_change('value', CustomJS.from_py_func(update))
    show(column(p, widgetbox(slider),))
Пример #43
0
from bokeh.models import Range1d

# create some data using python lists
x1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y1 = [0, 8, 2, 4, 6, 9, 15, 18, 19, 25, 28]

# EXERCISE: create two more data sets, x2, y2 and x3, y3, however
# you want. Make sure the corresponding x and y data are the same length
x2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y2 = [1, 3, 5, 8, 13, 7, 2, 12, 15, 16, 4]

x3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y3 = [0, 7, 1, 2, 3, 4, 5, 6, 7, 8, 28]

# specify and output static HTML file
output_file("scatter.html")

# EXERCISE: Plot all the sets of points on different plots p1, p2, p3.
# Try setting `color` (or `line_color`) and `alpha` (or `line_alpha`).
# You can also set `line_dash` and `line_width`. One example is given.
p1 = figure(plot_width=300, plot_height=300)
p1.line(x1, y1, size=12, color="red", alpha=0.5)

p2 = figure(plot_width=300, plot_height=300)
p2.line(x2, y2, size=10, color="blue", alpha=0.5, line_dash="dashed")

p3 = figure(plot_width=300, plot_height=300)
p3.line(x3, y3, size=13, color="green", alpha=0.5)

# create a figure
p4 = figure()
    #               fam_id=plink_mt.uid, ind_id=plink_mt.uid)
    pca_evals, pca_scores, pca_loadings = hl.hwe_normalized_pca(
        pca_mt.GT, k=20, compute_loadings=True)
    pca_af_ht = pca_mt.annotate_rows(
        pca_af=hl.agg.mean(pca_mt.GT.n_alt_alleles()) / 2).rows()
    pca_loadings = pca_loadings.annotate(
        pca_af=pca_af_ht[pca_loadings.key].pca_af)
    # pca_scores.write(
    #    f"{tmp_dir}/ddd-elgh-ukbb/chr1_chr20_XY_pca_scores.ht", overwrite=True)
    # pca_loadings.write(
    #    f"{tmp_dir}/ddd-elgh-ukbb/chr1_chr20_XY_pca_loadings.ht", overwrite=True)

    pca_mt = pca_mt.annotate_cols(scores=pca_scores[pca_mt.col_key].scores)

    variants, samples = related_mt.count()
    print(
        'Projecting population PCs for {} related samples...'.format(samples))
    #related_scores = pc_project(related_mt, pca_loadings)
    #relateds = related_mt.cols()
    #relateds = relateds.annotate(scores=related_scores[relateds.key].scores)

    pca_mt.write(f"{tmp_dir}/ddd-elgh-ukbb/chr1_chr20_XY_pca.mt",
                 overwrite=True)
    p = hl.plot.scatter(pca_mt.scores[0],
                        pca_mt.scores[1],
                        title='PCA',
                        xlabel='PC1',
                        ylabel='PC2')
    output_file(f"{temp_dir}/ddd-elgh-ukbb/pca.html")
    save(p)
Пример #45
0
qmax = groups.quantile(q=1.00)
upper.score = [min([x,y]) for (x,y) in zip(list(qmax.loc[:,'score']),upper.score)]
lower.score = [max([x,y]) for (x,y) in zip(list(qmin.loc[:,'score']),lower.score)]

# stems
p.segment(cats, upper.score, cats, q3.score, line_width=2, line_color="black")
p.segment(cats, lower.score, cats, q1.score, line_width=2, line_color="black")

# boxes
p.rect(cats, (q3.score+q2.score)/2, 0.7, q3.score-q2.score,
    fill_color="#E08E79", line_width=2, line_color="black")
p.rect(cats, (q2.score+q1.score)/2, 0.7, q2.score-q1.score,
    fill_color="#3B8686", line_width=2, line_color="black")

# whiskers (almost-0 height rects simpler than segments)
p.rect(cats, lower.score, 0.2, 0.01, line_color="black")
p.rect(cats, upper.score, 0.2, 0.01, line_color="black")

# outliers
if not out.empty:
    p.circle(outx, outy, size=6, color="#F38630", fill_alpha=0.6)

p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = "white"
p.grid.grid_line_width = 2
p.xaxis.major_label_text_font_size="12pt"

output_file("boxplot.html", title="boxplot.py example")

show(p)
Пример #46
0
    ############### progress ###############
    elapsed_time = time.strftime("%H:%M:%S",
                                 time.gmtime(time.time() - starttime))
    printstring = f'Plotting: {geneid}    File: {filecounter} / {total}   Elapsed time: {elapsed_time}'
    if len(printstring) < printlen:
        print(' ' * printlen, end='\r')
    print(printstring, end='\r')
    printlen = len(printstring)
    filecounter += 1
    #######################################

    # make output dir and create output filename
    if not os.path.exists(outdir + '/plots'):
        os.makedirs(outdir + '/plots')
    out = f'{outdir}/plots/{geneid}.html'
    output_file(out)

    seq = holydict[geneid].sequence
    pos = holydict[geneid].positions
    score = holydict[geneid].score
    flag = holydict[geneid].over_threshold
    pwa_score = pwa(score, frame_extend=24)
    protlen = len(seq)
    hyrophilicity_parker_score = frame_avg(hyrophilicity_parker[geneid],
                                           frame_extend=10)

    # create a new plot with a title and axis labels
    p = figure(title=fastaheader[geneid][1:],
               y_range=(-0.03, 1.03),
               y_axis_label='Scores',
               plot_width=1200,
Пример #47
0
    
    return p




# =============================================================================================

#        Task5: draw the figure and add bokeh server for interactive visualization

# =============================================================================================

# call datasource_construction function to get the source
source = datasource_construct(df) 

# call draw_plot function to create the plots
p = draw_plot(source)
layout = column(p, row(select_category, width=200)) 


# ======= using bokeh server to run the application ========
# reference: https://bokeh.pydata.org/en/latest/docs/user_guide/server.html
curdoc().add_root(layout)


# ======= optional: output the result file ========
output_file('dvc_exc2_skeleton.html')


show(p)
Пример #48
0
df_blood = df[SELECTION].copy()
print(df_blood)

dfPositive = df_blood[df_blood['SARS-Cov-2 exam result'] == "positive"]
dfNegative = df_blood[df_blood['SARS-Cov-2 exam result'] == "negative"]

dfPosAge = dfPositive['Patient age quantile']
dfNegAge = dfNegative['Patient age quantile']

del dfPositive['SARS-Cov-2 exam result']
del dfNegative['SARS-Cov-2 exam result']

print(dfPositive)

# set output file
output_file("test.html", title="Scatter visualization of blood tests")

dcPositive = dfPositive.to_dict("list")
dcNegative = dfNegative.to_dict("list")

# print(dcBlood['Patient age quantile'])

bloodvaluelist = list(dcPositive)

bloodvaluelist.remove('Patient age quantile')

figures = []

sourcePos = ColumnDataSource(dfPositive)
sourceNeg = ColumnDataSource(dfNegative)
Пример #49
0
    colors=colors,
))

TOOLTIPS = [
    ("index", "$index"),
    # ("(x,y)", "($x, $y)"),
    ("(t,l)", "(@top, @left)"),
    # ("fill color", "$color[hex, swatch]:fill_color"),
    ("desc", "@desc"),
]

p = figure(plot_width=800,
           plot_height=600,
           tooltips=TOOLTIPS,
           title="Calendar")
output_file("calendar.html")
p.xaxis[0].axis_label = 'Weekday (Sun-Fri)'
p.yaxis[0].axis_label = 'Hour (12AM-12AM)'

p.quad(top='top',
       bottom='bottom',
       left='left',
       right='right',
       color='colors',
       source=source)

source2 = ColumnDataSource(data=dict(
    x=left,
    y=top,
    names=desc,
))
Пример #50
0
    def _plot(self, FluxObj, ncols=1, output_type='save', out_file=None, 
            suptitle='', plot_width=1000, plot_height=450, 
            sizing_mode='scale_both', merge_tools=False, link_x=True, **kwargs): 
        """ 
        Private routine for aggregated validation plots that are used by
        the :meth:`.QaQc.plot` and :meth:`.Data.plot` methods.
        """
        # get daily and monthly time series with internal names, get units
        monthly = False
        if hasattr(FluxObj, 'monthly_df'):
            # will run correction as of now if it is a QaQc
            monthly = True
            monthly_df = FluxObj.monthly_df.rename(columns=FluxObj.inv_map) 
            # avoid plotting single point- errors out bokeh datetime axis, etc.
            for c in monthly_df.columns:
                if monthly_df[c].notna().sum() <= 1:
                    monthly_df.drop(c, axis=1, inplace=True)
            monthly_source = ColumnDataSource(monthly_df)

        # so that the correction is run, may change this
        FluxObj.df.head(); # if Data, need to access to calc vp/vpd 
        df = FluxObj.df.rename(columns=FluxObj.inv_map) 
        variables = FluxObj.variables
        units = FluxObj.units 
        # bokeh column sources for tooltips
        daily_source=ColumnDataSource(df)
        # for aggregating plots
        daily_line = []
        daily_scatter = []
        monthly_line = []
        monthly_scatter = []

        if output_type == 'save':
            output_file(out_file)

        def _get_units(plt_vars, units):
            """
            Helper function to figure out units for multivariate plots.
            If none of plt_vars exist return None, if multiple units are found
            print a warning that vars have different units. Returns string if 
            one or more units are found- first found if multiple. 
            """
            ret = [] 
            for v in plt_vars:
                unit = units.get(v, None)
                if unit is not None:
                    ret.append(unit)
            if len(ret) == 0:
                ret = None
            elif len(set(ret)) > 1:
                print(
                    'WARNING: variables: {} are not of the same units'.format(
                        ','.join(plt_vars)
                    )
                )
                ret = ret[0]
            elif len(set(ret)) == 1:
                ret = ret[0]

            return ret


        # run through each plot, daily then monthly versions
        #### 
        # energy balance time series plots
        #### 
        plt_vars = ['LE', 'H', 'Rn', 'G']
        colors = ['blue', 'red', 'black', 'green']
        title = 'Daily Surface Energy Balance Components'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='energy_balance_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Energy balance components time series grapths missing all '
                'variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Surface Energy Balance Components'
            fig = figure(x_axis_label=x_label, y_axis_label=y_label,title=title,
                width=plot_width, height=plot_height, 
                name='energy_balance_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)

        #### 
        # incoming shortwave and ASCE potential clear sky time series plots
        #### 
        plt_vars = ['sw_in', 'rso']
        # only plot if we have both
        if set(plt_vars).issubset(df.columns):
            labels = ['Station Rs', 'ASCE Rso']
            colors = ['black', 'red']
            title =\
                'Daily Incoming Shortwave (Rs) and ASCE Clear Sky Shortwave '+\
                'Radiation (Rso)'
            x_label = 'date'
            y_label = _get_units(plt_vars, units)
            fig = figure(x_axis_label=x_label, y_axis_label=y_label, 
                title=title, width=plot_width, height=plot_height, 
                name='Rs_daily'
            )
            fig = Plot.add_lines(
                fig, df, plt_vars, colors, x_label, daily_source, labels=labels
            )
            if fig is not None:
                daily_line.append(fig)
                ## same for monthly fig (removed for now)
                #title='Monthly Incoming Shortwave and ASCE Potential Radiation'
                #fig = figure(
                #    x_axis_label=x_label,y_axis_label=y_label,title=title,
                #    width=plot_width, height=plot_height
                #)
                #fig = Plot.add_lines(
                #    fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                #    labels=labels
                #)
                #monthly_line.append(fig)
        else:
            print(
                'Shortwave and potential clear sky radiation time series '
                'grapths missing all variables'
            )

        #### 
        # multiple soil heat flux sensor time series plots
        #### 
        # keep user names for these in hover 
        g_re = re.compile('^[gG]_[\d+mean|corr]|G$')
        g_vars = [
            v for v in variables if g_re.match(v) and v in df.columns
        ]
        num_lines = len(g_vars)
        if num_lines > 1:
            rename_dict = {k:variables[k] for k in g_vars}
            tmp_df = df[g_vars].rename(columns=rename_dict)
            tmp_source = ColumnDataSource(tmp_df)
            plt_vars = list(rename_dict.values())
            colors = Viridis256[0:-1:int(256/num_lines)]
            title = 'Daily Soil Heat Flux (Multiple Sensors)'
            x_label = 'date'
            y_label = _get_units(g_vars, units)
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                plot_width=plot_width, plot_height=plot_height, name='G_daily'
            )
            fig = Plot.add_lines(
                fig, tmp_df, plt_vars, colors, x_label, tmp_source, 
                labels=plt_vars
            )
            if fig is not None:
                daily_line.append(fig)
            if fig is not None and monthly:
                # same for monthly fig
                g_vars = [
                    v for v in variables if g_re.match(v) and v in \
                        monthly_df.columns
                ]
                num_lines = len(g_vars)
                if num_lines > 1:
                    tmp_df = monthly_df[g_vars].rename(columns=rename_dict)
                    tmp_source = ColumnDataSource(tmp_df)
                    title = 'Monthly Soil Heat Flux (Multiple Sensors)'
                    fig = figure(
                        x_axis_label=x_label, y_axis_label=y_label,title=title,
                        plot_width=plot_width, plot_height=plot_height, 
                        name='G_monthly'
                    )
                    fig = Plot.add_lines(
                        fig, tmp_df, plt_vars, colors, x_label, tmp_source,
                        labels=plt_vars
                    )
                    monthly_line.append(fig)
            # do not print warning if missing multiple soil moisture recordings

        #### 
        # radiation time series plots
        #### 
        plt_vars = ['sw_in', 'lw_in', 'sw_out', 'lw_out']
        colors = ['red', 'darkred', 'blue', 'navy']
        title = 'Daily Radiation Components'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='radiation_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Radiation components time series grapths missing all variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Radiation Components'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='radiation_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)


        #### 
        # temperature time series plot
        #### 
        plt_vars = ['t_max','t_avg','t_min','t_dew']
        colors = ['red','black','blue','green']
        title = 'Daily Average Air Temperature'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='temp_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Average air temperature time series grapths missing all '
                'variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Average Air Temperature'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label,title=title,
                width=plot_width, height=plot_height, name='temp_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)

        #### 
        # vapor pressure time series plots
        #### 
        plt_vars = ['vp', 'vpd']
        colors = ['black', 'darkred']
        title = 'Daily Average Vapor Pressure and Deficit'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='vap_press_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print('Vapor pressure time series grapths missing all variables')
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Average Vapor Pressure'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='vap_press_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)

        #### 
        # windpseed time series plot
        #### 
        plt_vars = ['ws']
        colors = ['black']
        title = 'Daily Average Windspeed'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='wind_daily'
        )
        fig = Plot.add_lines(fig, df, plt_vars, colors, x_label, daily_source)
        if fig is not None:
            daily_line.append(fig)
        else:
            print('Windspeed time series grapths missing all variables')
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Average Windspeed'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='wind_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source
            )
            monthly_line.append(fig)

        #### 
        # precipitation time series plots
        #### 
        plt_vars = ['ppt', 'gridMET_prcp']
        labels = ['station', 'gridMET']
        colors = ['black', 'red']
        title = 'Daily Station and gridMET Precipitation'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='precip_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=labels
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print('Precipitation time series grapths missing all variables')
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Station and gridMET Precipitation'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='precip_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=labels
            )
            monthly_line.append(fig)

        #### 
        # latent energy time series plots
        #### 
        plt_vars = ['LE', 'LE_corr', 'LE_user_corr']
        colors = ['black', 'red', 'darkorange']
        title = 'Daily Average Latent Energy Flux'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='LE_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print('Latent energy time series grapths missing all variables')
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Average Latent Energy Flux'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='LE_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)

        #### 
        # ET time series plots
        #### 
        refET = 'ETr' if 'ETrF' in df.columns else 'ETo'
        plt_vars = ['ET', 'ET_corr', 'ET_user_corr', f'gridMET_{refET}']
        labels = plt_vars[0:3] + [refET]
        colors = ['black', 'red', 'darkorange', 'blue']
        title = 'Daily Evapotranspiration'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='ET_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=labels
        )
        if 'ET_fill_val' in df.columns and fig is not None:
            # make gap fill values more visible
            Plot.line_plot(
                fig, 'date', 'ET_fill_val', daily_source, 'green', 
                label='ET_fill_val', line_width=3
            )

        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Evapotranspiration time series grapths missing all variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Evapotranspiration'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='ET_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=labels
            )
            monthly_line.append(fig)

        #### 
        # number gap filled days monthly time series plot
        #### 
        if monthly and 'ET_gap' in monthly_df.columns:
            txt = ''
            if 'ET_corr' in df.columns:
                txt = ' Corrected'
            title = 'Number of Gap Filled Days in{} Monthly ET'.format(txt)
            x_label = 'date'
            y_label = 'number of gap-filled days'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='ET_gaps'
            )
            x = 'date'
            y = 'ET_gap'
            color = 'black'
            Plot.line_plot(fig, x, y, monthly_source, color)
            monthly_line.append(fig)
        elif monthly:
            print('Monthly count of gap filled ET days plot missing variable')

        #### 
        # ETrF time series plots
        ####
        plt_vars = [f'{refET}F', f'{refET}F_filtered']
        colors = ['black', 'red']
        title = f'Daily Fraction of Reference ET ({refET}F)'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name=f'{refET}F_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=plt_vars
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Fraction of reference ET time series grapths missing all '
                'variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = f'Monthly Fraction of Reference ET ({refET}F)'
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name=f'{refET}F_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=plt_vars
            )
            monthly_line.append(fig)

        #### 
        # energy balance ratio time series plots
        #### 
        plt_vars = ['ebr', 'ebr_corr', 'ebr_user_corr']
        colors = ['black', 'red', 'darkorange']
        title = 'Daily Energy Balance Ratio with Long-term Mean'
        x_label = 'date'
        y_label = _get_units(plt_vars, units)
        # add mean EBR for each time series in legend
        labels = []
        for i, v in enumerate(plt_vars):
            if v in df.columns:
                added_text = ': {}'.format(str(round(df[v].mean(),2)))
                labels.append(plt_vars[i] + added_text)
            else:
                labels.append(None)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_height, name='EBR_daily'
        )
        fig = Plot.add_lines(
            fig, df, plt_vars, colors, x_label, daily_source, labels=labels
        )
        if fig is not None:
            daily_line.append(fig)
        else:
            print(
                'Energy balance ratio time series grapths missing all '
                'variables'
            )
        if fig is not None and monthly:
            # same for monthly fig
            title = 'Monthly Energy Balance Ratio with Long-term Mean'
            # add mean for monthly EBRs to legend
            labels = []
            for i, v in enumerate(plt_vars):
                if v in monthly_df.columns:
                    added_text = ': {}'.format(
                        str(round(monthly_df[v].mean(),2))
                    )
                    labels.append(plt_vars[i] + added_text)
                else:
                    labels.append(None)
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                width=plot_width, height=plot_height, name='EBR_monthly'
            )
            fig = Plot.add_lines(
                fig, monthly_df, plt_vars, colors, x_label, monthly_source,
                labels=labels
            )
            monthly_line.append(fig)

        #### 
        # energy balance closure scatter plots
        #### 
        title = 'Daily Energy Balance Closure, Energy Versus Flux with Slope '\
            'Through Origin'
        unit = _get_units(['LE', 'H', 'Rn', 'G'], units)
        y_label = 'LE + H ({})'.format(unit)
        x_label = 'Rn - G ({})'.format(unit)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_width, name='energy_vs_flux_daily'
        )
        y_vars = ['flux', 'flux_corr', 'flux_user_corr']
        colors = ['black', 'red', 'darkorange']
        labels = ['init', 'corr', 'user_corr']
        # add plot pairs to plot if they exist, add 1:1
        mins_maxs = []
        n_vars_fnd = 0
        for i, v in enumerate(y_vars):
            if v in df.columns and not df[v].isna().all():
                n_vars_fnd += 1
                if v == 'flux_corr' and 'energy_corr' in df.columns:
                    x_var = 'energy_corr'
                else:
                    x_var = 'energy'
                min_max = Plot.scatter_plot(
                    fig, x_var, v, daily_source, colors[i], label=labels[i]
                )
                if min_max is not None:
                    mins_maxs.append(min_max)
        if n_vars_fnd > 0:
            # add scaled one to one line
            mins_maxs = np.array(mins_maxs)
            if not pd.isna(mins_maxs).all():
                x_min = min(mins_maxs[:,0])
                x_max = max(mins_maxs[:,1])
                y_min = min(mins_maxs[:,2])
                y_max = max(mins_maxs[:,3])
                ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
                ax_min -= 0.02*abs(ax_max-ax_min)
                ax_max += 0.02*abs(ax_max-ax_min)
                fig.x_range=Range1d(ax_min, ax_max)
                fig.y_range=Range1d(ax_min, ax_max)
                one2one_vals = np.arange(ax_min, ax_max,1)
                fig.line(
                    one2one_vals, one2one_vals, legend_label='1:1 line', 
                    color='black', line_dash='dashed'
                )
                daily_scatter.append(fig)
            if monthly:
                # same for monthly fig
                title = 'Monthly Energy Balance Closure, Energy Versus Flux '\
                    'with Slope Through Origin'
                fig = figure(
                    x_axis_label=x_label, y_axis_label=y_label, title=title,
                    width=plot_width, height=plot_width, 
                    name='energy_vs_flux_monthly'
                )
                mins_maxs = []
                for i, v in enumerate(y_vars):
                    if v in monthly_df.columns:
                        min_max = Plot.scatter_plot(
                            fig, 'energy', v, monthly_source, colors[i], 
                            label=labels[i]
                        )
                        if min_max is not None:
                            mins_maxs.append(min_max)
                mins_maxs = np.array(mins_maxs)
                # check if not all pairs are empty, if not plot 1:1
                if not pd.isna(mins_maxs).all():
                    x_min = min(mins_maxs[:,0])
                    x_max = max(mins_maxs[:,1])
                    y_min = min(mins_maxs[:,2])
                    y_max = max(mins_maxs[:,3])
                    ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
                    ax_min -= 0.02*abs(ax_max-ax_min)
                    ax_max += 0.02*abs(ax_max-ax_min)
                    fig.x_range=Range1d(ax_min, ax_max)
                    fig.y_range=Range1d(ax_min, ax_max)
                    one2one_vals = np.arange(ax_min, ax_max,1)
                    fig.line(
                        one2one_vals, one2one_vals, legend_label='1:1 line', 
                        color='black', line_dash='dashed'
                    )
                    monthly_scatter.append(fig)
        else:
            print('Energy balance scatter grapths missing all variables')


        #### 
        # latent energy scatter plots
        #### 
        title = 'Daily Latent Energy, Initial Versus Corrected'
        unit = _get_units(['LE', 'LE_corr', 'LE_user_corr'], units)
        y_label = 'corrected ({})'.format(unit)
        x_label = 'initial ({})'.format(unit)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_width, name='LE_scatter_daily'
        )
        y_vars = ['LE_corr', 'LE_user_corr']
        colors = ['red', 'darkorange']
        labels = ['corr', 'user_corr']
        # add plot pairs to plot if they exist, add 1:1
        mins_maxs = []
        n_vars_fnd = 0
        for i, v in enumerate(y_vars):
            if v in df.columns and not df[v].isna().all():
                n_vars_fnd += 1
                min_max = Plot.scatter_plot(
                    fig, 'LE', v, daily_source, colors[i], label=labels[i]
                )
                mins_maxs.append(min_max)
        if n_vars_fnd > 0:
            # add scaled one to one line
            mins_maxs = np.array(mins_maxs)
            if not pd.isna(mins_maxs).all():
                x_min = min(mins_maxs[:,0])
                x_max = max(mins_maxs[:,1])
                y_min = min(mins_maxs[:,2])
                y_max = max(mins_maxs[:,3])
                ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
                ax_min -= 0.02*abs(ax_max-ax_min)
                ax_max += 0.02*abs(ax_max-ax_min)
                fig.x_range=Range1d(ax_min, ax_max)
                fig.y_range=Range1d(ax_min, ax_max)
                one2one_vals = np.arange(ax_min, ax_max,1)
                fig.line(
                    one2one_vals, one2one_vals, legend_label='1:1 line', 
                    color='black', line_dash='dashed'
                )
                daily_scatter.append(fig)
            if monthly:
                # same for monthly fig
                title = 'Monthly Latent Energy, Initial Versus Corrected'
                fig = figure(
                    x_axis_label=x_label, y_axis_label=y_label, title=title,
                    width=plot_width, height=plot_width, 
                    name='LE_scatter_monthly'
                )
                mins_maxs = []
                for i, v in enumerate(y_vars):
                    if v in monthly_df.columns:
                        min_max = Plot.scatter_plot(
                            fig, 'LE', v, monthly_source, colors[i], 
                            label=labels[i]
                        )
                        if min_max is not None:
                            mins_maxs.append(min_max)
                mins_maxs = np.array(mins_maxs)
                # check if not all pairs are empty, if not plot 1:1
                if not pd.isna(mins_maxs).all():
                    x_min = min(mins_maxs[:,0])
                    x_max = max(mins_maxs[:,1])
                    y_min = min(mins_maxs[:,2])
                    y_max = max(mins_maxs[:,3])
                    ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
                    ax_min -= 0.02*abs(ax_max-ax_min)
                    ax_max += 0.02*abs(ax_max-ax_min)
                    fig.x_range=Range1d(ax_min, ax_max)
                    fig.y_range=Range1d(ax_min, ax_max)
                    one2one_vals = np.arange(ax_min, ax_max,1)
                    fig.line(
                        one2one_vals, one2one_vals, legend_label='1:1 line', 
                        color='black', line_dash='dashed'
                    )
                    monthly_scatter.append(fig)
        else:
            print('Latent energy scatter grapths missing all variables')

        #### 
        # ET scatter plots
        #### 
        title = 'Daily Evapotranspiration, Initial Versus Corrected'
        unit = _get_units(['ET', 'ET_corr', 'ET_user_corr'], units)
        y_label = 'corrected ({})'.format(unit)
        x_label = 'initial ({})'.format(unit)
        fig = figure(
            x_axis_label=x_label, y_axis_label=y_label, title=title,
            width=plot_width, height=plot_width, name='ET_scatter_daily'
        )
        y_vars = ['ET_corr', 'ET_user_corr']
        colors = ['red', 'darkorange']
        labels = ['corr', 'user_corr']
        # add plot pairs to plot if they exist, add 1:1
        mins_maxs = []
        n_vars_fnd = 0
        for i, v in enumerate(y_vars):
            if v in df.columns and not df[v].isna().all():
                n_vars_fnd += 1
                min_max = Plot.scatter_plot(
                    fig, 'ET', v, daily_source, colors[i], label=labels[i]
                )
                mins_maxs.append(min_max)
        if n_vars_fnd > 0:
            # add scaled one to one line
            mins_maxs = np.array(mins_maxs)
            x_min = min(mins_maxs[:,0])
            x_max = max(mins_maxs[:,1])
            y_min = min(mins_maxs[:,2])
            y_max = max(mins_maxs[:,3])
            ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
            ax_min -= 0.02*abs(ax_max-ax_min)
            ax_max += 0.02*abs(ax_max-ax_min)
            fig.x_range=Range1d(ax_min, ax_max)
            fig.y_range=Range1d(ax_min, ax_max)
            one2one_vals = np.arange(ax_min, ax_max,1)
            fig.line(
                one2one_vals, one2one_vals, legend_label='1:1 line', 
                color='black', line_dash='dashed'
            )
            daily_scatter.append(fig)
            if monthly:
                # same for monthly fig
                title = 'Monthly Evapotranspiration, Initial Versus Corrected'
                fig = figure(
                    x_axis_label=x_label, y_axis_label=y_label, title=title,
                    width=plot_width, height=plot_width, 
                    name='ET_scatter_monthly'
                )
                mins_maxs = []
                for i, v in enumerate(y_vars):
                    if v in monthly_df.columns:
                        min_max = Plot.scatter_plot(
                            fig, 'ET', v, monthly_source, colors[i], 
                            label=labels[i]
                        )
                        mins_maxs.append(min_max)
                mins_maxs = np.array(mins_maxs)
                # check if not all pairs are empty, if not plot 1:1
                if not pd.isna(mins_maxs).all():
                    x_min = min(mins_maxs[:,0])
                    x_max = max(mins_maxs[:,1])
                    y_min = min(mins_maxs[:,2])
                    y_max = max(mins_maxs[:,3])
                    ax_min, ax_max = min([x_min,y_min]), max([x_max,y_max])
                    ax_min -= 0.02*abs(ax_max-ax_min)
                    ax_max += 0.02*abs(ax_max-ax_min)
                    fig.x_range=Range1d(ax_min, ax_max)
                    fig.y_range=Range1d(ax_min, ax_max)
                    one2one_vals = np.arange(ax_min, ax_max,1)
                    fig.line(
                        one2one_vals, one2one_vals, legend_label='1:1 line', 
                        color='black', line_dash='dashed'
                    )
                    monthly_scatter.append(fig)
        else:
            print('Evapotranspiration scatter grapths missing all variables')

        #### 
        # multiple soil moisture time series plots
        #### 
        # keep user names for these in hover 
        theta_re = re.compile('theta_[\d+|mean]')
        theta_vars = [
            v for v in variables if theta_re.match(v) and v in df.columns
        ]
        num_lines = len(theta_vars)
        if num_lines > 0 and not df[theta_vars].isna().all().all():
            rename_dict = {k:variables[k] for k in theta_vars}
            tmp_df = df[theta_vars].rename(columns=rename_dict)
            tmp_source = ColumnDataSource(tmp_df)
            plt_vars = list(rename_dict.values())
            colors = Viridis256[0:-1:int(256/num_lines)]
            title = 'Daily Soil Moisture (Multiple Sensors)'
            x_label = 'date'
            y_label = _get_units(theta_vars, units)
            fig = figure(
                x_axis_label=x_label, y_axis_label=y_label, title=title,
                plot_width=plot_width, plot_height=plot_height, 
                name='theta_daily'
            )
            fig = Plot.add_lines(
                fig, tmp_df, plt_vars, colors, x_label, tmp_source, 
                labels=plt_vars
            )
            if fig is not None:
                daily_line.append(fig)
            theta_vars = [
                v for v in variables if theta_re.match(v) and v in\
                    df.columns
            ]
            if fig is not None and monthly and len(theta_vars) > 0:
                # same for monthly fig
                tmp_df = monthly_df[theta_vars].rename(columns=rename_dict)
                tmp_source = ColumnDataSource(tmp_df)
                title = 'Monthly Soil Moisture (Multiple Sensors)'
                fig = figure(
                    x_axis_label=x_label, y_axis_label=y_label, title=title,
                    plot_width=plot_width, plot_height=plot_height,
                    name='theta_monthly'
                )
                fig = Plot.add_lines(
                    fig, tmp_df, plt_vars, colors, x_label, tmp_source,
                    labels=plt_vars
                )
                monthly_line.append(fig)
            # do not print warning if missing multiple soil moisture recordings


        # Aggregate plots and output depending on options
        # remove None values in different figure groups 
        daily_line = list(filter(None, daily_line))
        daily_scatter = list(filter(None, daily_scatter))
        monthly_line = list(filter(None, monthly_line))
        monthly_scatter = list(filter(None, monthly_scatter))
        # link axes for time series plots
        if link_x:
            for each in daily_line:
                each.x_range = daily_line[0].x_range
            for each in monthly_line:
                each.x_range = monthly_line[0].x_range
        figs = daily_line + daily_scatter + monthly_line + monthly_scatter
        grid = gridplot(
            figs, ncols=ncols, plot_width=None, plot_height=None, 
            sizing_mode=sizing_mode, merge_tools=merge_tools, **kwargs
        )
        if output_type == 'show':
            show(column(Div(text=suptitle),grid))
        elif output_type == 'notebook':
            from bokeh.io import output_notebook
            output_notebook()
            show(column(Div(text=suptitle),grid))
        elif output_type == 'save':
            save(column(Div(text=suptitle),grid))
        elif output_type == 'return_figs':
            return figs
        elif output_type == 'return_grid':
            return grid

        reset_output()
Пример #51
0
import numpy as np

from bokeh.layouts import column, grid
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure, output_file, show

output_file('dashboard.html')

tools = 'pan'


def bollinger():
    # Define Bollinger Bands.
    upperband = np.random.randint(100, 150 + 1, size=100)
    lowerband = upperband - 100
    x_data = np.arange(1, 101)

    # Bollinger shading glyph:
    band_x = np.append(x_data, x_data[::-1])
    band_y = np.append(lowerband, upperband[::-1])

    p = figure(x_axis_type='datetime', tools=tools)
    p.patch(band_x, band_y, color='#7570B3', fill_alpha=0.2)

    p.title.text = 'Bollinger Bands'
    p.title_location = 'left'
    p.title.align = 'left'
    p.width = 800
    p.height = 600
    p.grid.grid_line_alpha = 0.4
    return [p]
Пример #52
0
# plot open-loop
ts_openloop.plot(color='m',
                 style='--',
                 label='Open-loop, RMSE={:.3f} mm/mm'.format(rmse_openloop),
                 legend=True)
# Make plot looks better
plt.xlabel('Time')
plt.ylabel('Soil moiture (mm/mm)')
plt.title('Top-layer soil moisture, {}, {}, N={}'.format(lat, lon, N))
# Save figure
fig.savefig(os.path.join(output_dir, '{}_{}.post.sm1.png'.format(lat, lon)),
            format='png')

# ----- Interactive version ----- #
# Create figure
output_file(os.path.join(output_dir, '{}_{}.post.sm1.html'.format(lat, lon)))

p = figure(title='Top-layer soil moisture, {}, {}, N={}'.format(lat, lon, N),
           x_axis_label="Time",
           y_axis_label="Soil moiture (mm/mm)",
           x_axis_type='datetime',
           width=1000,
           height=500)
# plot each ensemble member
for i in range(N):
    ens_name = 'ens{}'.format(i + 1)
    if i == 0:
        legend = "Post-processed, mean RMSE={:.2f} mm/mm".format(
            rmse_post_mean)
    else:
        legend = False
Пример #53
0
    magblackbody_i = -2.5 * np.log10(luminosityblackbody_i) - 48.6
    magblackbody_V = -2.5 * np.log10(luminosityblackbody_V) - 48.6
    magblackbody_U = -2.5 * np.log10(luminosityblackbody_U) - 48.6
    # Generate the new curve
    L = ((2. * M * f) / (td)) * (np.exp((-t**2) / td**2)) * E * my_int
    magnitude = -2.5 * np.log10(L / 4e33) + 4.3

    source.data = dict(x=t * (1. + redshift) + T_slider.value,
                       y=magblackbody,
                       yB=magblackbody_B,
                       yr=magblackbody_r,
                       yi=magblackbody_i,
                       yV=magblackbody_V,
                       yU=magblackbody_U)


#for w in [M_slider,f_slider,v_slider, k_slider, T_slider]:
#    w.on_change('value', update_data)

# Set up layouts and add to document
inputs = widgetbox(text, M_slider, f_slider, v_slider, k_slider, T_slider)
layout = row(
    plot,
    inputs,
)

output_file("NewBokeh.html")

save(plot)
show(layout)
Пример #54
0
""" The LaTex example was derived from: http://matplotlib.org/users/usetex.html
"""
import numpy as np
from scipy.special import jv

from bokeh.models import Label
from bokeh.palettes import Spectral4
from bokeh.plotting import figure, output_file, show
from bokeh.util.compiler import TypeScript

output_file('latex_extension.html')


class LatexLabel(Label):
    """A subclass of `Label` with all of the same class attributes except
    canvas mode isn't supported and DOM manipulation happens in the TypeScript
    superclass implementation that requires setting `render_mode='css'`).

    Only the render method of LabelView is overwritten to perform the
    text -> latex (via katex) conversion
    """
    __javascript__ = [
        "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.js"
    ]
    __css__ = [
        "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css"
    ]
    __implementation__ = TypeScript("""
import {Label, LabelView} from "models/annotations/label"

declare namespace katex {
Пример #55
0
def main():

    #playlist_folder = "/Users/georgetzanetakis/data/sound/nonglitch/"
    #playlist_folder = "/Users/georgetzanetakis/data/sound/glitch/"
    #playlist_folder = "/Users/georgetzanetakis/data/sound/normal/"
    #playlist_folder = "/tmp/smule_songs1/"
    #playlist_folder = "/Users/georgetzanetakis/data/sound/headphones/"
    #playlist_folder = "/Users/georgetzanetakis/data/sound/2017/"
    #playlist_folder = "/Users/georgetzanetakis/data/sound/2016/"

    positive_folder = sys.argv[1]
    negative_folder = sys.argv[2]
    test_folder = sys.argv[3]

    # process positives
    output_file("positive_histograms.html")
    wav_fnames = get_wavs_from_folder(positive_folder)
    (pos_ratios, pos_names) = process_collection(wav_fnames)
    pfeatures = np.asarray(pos_ratios)
    ptruth = np.ones(len(pos_ratios))

    # process negatives
    output_file("negative_histograms.html")
    wav_fnames = get_wavs_from_folder(negative_folder)
    (neg_ratios, neg_names) = process_collection(wav_fnames)
    nfeatures = np.asarray(neg_ratios)
    ntruth = np.zeros(len(neg_ratios))

    # create feature matrices for training classifiers
    X = np.concatenate([pos_ratios, neg_ratios])
    print(X.shape)
    y = np.concatenate([ptruth, ntruth])
    print(y.shape)

    # hack to get results in order of performances in spreadsheet
    # csv_fname = "glitch_other.csv"
    # with open(csv_fname, 'rb') as f:
    #    reader = csv.reader(f)
    #    i = 0
    #    wav_fnames = []
    #    for row in reader:
    #        wav_fnames.append(test_folder + row[0] + '.wav')
    # print(wav_fnames)

    # load a test folder and compute the features
    wav_fnames = get_wavs_from_folder(test_folder)
    (test_ratios, test_names) = process_collection(wav_fnames)

    # scale test based on training set scale
    Xtest = np.concatenate([test_ratios])
    min_max_scaler = preprocessing.MinMaxScaler()
    X = min_max_scaler.fit_transform(X)
    Xtest = min_max_scaler.transform(Xtest)

    clf = svm.SVC(kernel='linear', C=1)
    #    clf = svm.SVC(kernel='linear', C=0.025)
    #    clf = svm.SVC(gamma = 2, C=1)
    clf.fit(X, y)

    scores = cross_val_score(clf, X, y, cv=30)
    predicted = cross_val_predict(clf, X, y, cv=30)
    cm = metrics.confusion_matrix(y, predicted)
    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
    print(cm)
    print("SUPPORT VECTOR MACHINE")
    print(scores)
    print("Accuracy: %0.2f (+/- %0.2f)" % (scores.mean(), scores.std() * 2))

    # rclf = RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1)
    # rclf.fit(X,y)
    # rscores = cross_val_score(rclf, X, y, cv=30)
    # print("RANDOM FOREST")
    # print(rscores)
    # print("Accuracy: %0.2f (+/- %0.2f)" % (rscores.mean(), rscores.std() * 2))

    # mclf =  MLPClassifier(alpha=1)
    # mclf.fit(X,y)
    # mscores = cross_val_score(rclf, X, y, cv=30)
    # print("Multilayer Perceptron")
    # print(mscores)
    # print("Accuracy: %0.2f (+/- %0.2f)" % (mscores.mean(), mscores.std() * 2))

    # dclf = DummyClassifier(strategy='most_frequent',random_state=0)
    # dclf.fit(X,y)
    # dscores = cross_val_score(dclf, X, y, cv=30)
    # print("ZeroR")
    # print(dscores)
    # print("Accuracy: %0.2f (+/- %0.2f)" % (dscores.mean(), dscores.std() * 2))

    # Run the trained classifier (SVM) to predict the test test
    i = 0
    glitches = 0
    for prediction in clf.predict(Xtest):
        print(str(prediction) + test_names[i])
        # print(prediction)
        if (prediction == 1):
            glitches = glitches + 1
        i = i + 1
    print("Accuracy for test set:" + test_folder)
    print(glitches, i)
    print("Accuracy: %0.2f" % (glitches * 1.0 / i * 100))
Пример #56
0
    df_totals_day.rename_axis('Date', inplace=True)
    df_totals_day[['Vote Total', 'Difference'
                   ]] = df_totals_day[['Vote Total', 'Difference'
                                       ]].applymap('{:,.0f}'.format)
    #     df_totals_day.style.format('{:,.0f}')
    return df_totals_day.to_markdown()


df_totals = get_data(cloned_repo, totals_pkl_file, totals_pkl_file)
df_totals.sort_values('datetime', ascending=False, inplace=True)
df_2016_totals = get_2016_data(vote_2016_dict, offset=4)
mfig = vote2020plt(df_totals['datetime'], df_totals['vote_total'],
                   df_2016_totals['datetime'],
                   df_2016_totals['vote_total_2016'])
p = vote2020_bokeh(df_totals, df_2016_totals)
output_file(netlify_html)
save(p, filename=netlify_html, title=netlify_html)

# rpl_text = {'table_2016':df_2016_totals.groupby(by=[df_2016_totals.datetime.dt.date]).vote_total_2016.max().apply('{:,.0f}'.format).to_markdown(),
#             'table_2020':df_totals.groupby(by=[df_totals.datetime.dt.date]).vote_total.max().apply('{:,.0f}'.format).to_markdown()}

rpl_text = {
    'table_2016': md_tables(get_2016_data(vote_2016_dict)),
    'table_2020': md_tables(df_totals)
}
update_md(rdme_fname, rpl_text)


def update_notebook():
    print('Repo: \'{}\': {}\nTotal commits: {}\n{} commits: {}'.format(
        cloned_repo.remotes.origin.name, cloned_repo.remotes.origin.url,
Пример #57
0
bokeh.plotting

1.basic step for plotting
The basic steps to creating plots with the bokeh.plotting interface are:

1.1 Prepare some data
In this case plain python lists, but could also be NumPy arrays or Pandas series.

1.2 Tell Bokeh where to generate output
In this case using output_file(), with the filename "lines.html".
Another option is output_notebook() for use in Jupyter notebooks.

1.3 Call figure()
This creates a plot with typical default options and easy customization of 
title, tools, and axes labels.


1.4 Add renderers
In this case, we use line() for our data, specifying visual customizations like 
colors, legends and widthss.

1.5 Ask Bokeh to show() or save() the results.
These functions save the plot HTML to a file and 
optionally display it in a browser.



2.
from bokeh.plotting import figure, output_file, show

#prepare some data
Пример #58
0
from bokeh.plotting import figure, show, output_file
from bokeh.tile_providers import CARTODBPOSITRON

output_file("tile.html")

# range bounds supplied in web mercator coordinates
p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000))
p.axis.visible = False
p.add_tile(CARTODBPOSITRON)

show(p)
Пример #59
0
    overall_trends(),
    retail_sales(),
    personal_income(),
    weekly_claims(),
    adp_charts(),
    jobs_report(),
    #bus_pul(),
    miscellaneous(),
    about()
])

logging.info("%s saving file to " + fileloc + 'Economy.html',
             datetime.datetime.now())

print("saving file to " + fileloc + 'Economy.html')
output_file(fileloc + 'Economy.html')
templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = os.path.join(dir_path, "template.html")
with open(TEMPLATE_FILE) as file_:
    template = jinja2.Template(file_.read())
save(page, title='Economic Data', template=template)
logging.info("%s Economic Dashboard Update Complete", datetime.datetime.now())
"""

#Compensation and UI change
compensation_and_ui=['W209RC1','W825RC1']
p=chart(compensation_and_ui,cy,transformation='difference',transform_date=rs)
p.renderers[0].data_source.data['difference']=p.renderers[0].data_source.data['difference']*-1
p.legend[0]._property_values['items'][0]._property_values['label']['value']='Loss in Compensation since Feb 2020'
p.legend[0]._property_values['items'][1]._property_values['label']['value']='Increase in Unemployment Insurance since Feb 2020'
Пример #60
0
import numpy as np

from bokeh.plotting import figure, show, output_file
from bokeh.models import Slope

output_file("slope.html", title="slope.py example")

# linear equation parameters
gradient = 2
y_intercept = 10

# create random data
xpts = np.arange(0, 20)
ypts = gradient * xpts + y_intercept + np.random.normal(0, 4, 20)

p = figure(plot_width=450, plot_height=450, y_range=(0, 1.1 * max(ypts)))

p.circle(xpts, ypts, size=5, color="skyblue")

slope = Slope(gradient=gradient,
              y_intercept=y_intercept,
              line_color='orange',
              line_dash='dashed',
              line_width=3.5)

p.add_layout(slope)

p.yaxis.axis_label = 'y'
p.xaxis.axis_label = 'x'

show(p)