def make_plot(xname, yname, xax=False, yax=False): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot( x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2+mbl, min_border_right=2, min_border_top=2, min_border_bottom=2+mbb) circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool()) return plot
def make_plot(xname, yname, xax=False, yax=False): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot( x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2+mbl, min_border_right=2, min_border_top=2, min_border_bottom=2+mbb) circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool()) return plot
def make_scatter(source, data, xname, yname, xax=False, yax=False): # sets range and borders for plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = figure(x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # plots points circle = Circle(x=xname, y=yname, fill_color="blue", fill_alpha=0.2, size=4, line_color="blue") plot.add_glyph(source, circle) # calculates and plots regression line a, b, mse = make_regression_line(data, xname, yname) mse_mean = mse.mean() print(xname, yname, mse_mean) x = data[xname] plot.line(x, a * x + b, color='red') plot.axis.visible = False # makes axis according to place in matrix xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) return plot
def make_dist(data, xname, xax=False, yax=False): # sets ranges and borders for plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 TOOLS = "hover, save, reset" plot = figure(x_range=xdr, y_range=ydr, tools=TOOLS, x_axis_label="", y_axis_label="", background_fill_color="#E8DDCB", plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # makes histogram measured = data[xname] hist, edges = np.histogram(measured, density=True, bins=50) # plots histogram plot.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649") # makes axis according to place in matrix plot.axis.visible = False xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = xname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.legend.location = "center_right" plot.legend.background_fill_color = "darkgrey" return plot
def metrix_plot(xname, yname, xax=False, yax=False, xdr=None, ydr=None, source=None): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot(x_range=xdr, y_range=ydr, plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=1 + mbl, min_border_right=1, min_border_top=1, min_border_bottom=1 + mbb) circle = Circle(x=xname, y=yname, fill_color="color", size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool(), BoxZoomTool(), SaveTool(), ResetTool()) return plot
def show_coeff(data, xname, yname, xax=False, yax=False): # sets ranges and borders of plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = figure(x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # calculates and plots correlation coefficient measured1 = data[xname] measured2 = data[yname] coeff = np.corrcoef(measured1, measured2) coeff = round(coeff[0][1], 3) plot.text(text_align='center', text_baseline='middle', text=[coeff], text_font_size='35pt', x=0, y=-5) # adjust axes according to place in matrix plot.axis.visible = False xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) plot.add_layout(Grid(dimension=1, ticker=yticker)) return plot
def init_mention_plot(): cprint('%s: init @ mentios barcharts...' % TAG, 'yellow', attrs=['bold']) global mention_count global mention_barplot mention_count = count_mentions() y = [] mentions = [] for (mention, freq) in mention_count: y.append(freq) mentions.append(mention) x = np.arange(len(mentions)) source = ColumnDataSource(dict( x=x, top=y, )) glyph = VBar(x='x', top='top', bottom=0, width=0.85, fill_color='#ff7f0e') mention_barplot.add_glyph(source, glyph) xaxis = LinearAxis() xaxis.ticker = x xaxis.major_label_overrides = { i: mention for i, mention in enumerate(mentions) } mention_barplot.add_layout(xaxis, 'below') mention_barplot.xaxis.major_label_orientation = +np.pi / 2 yaxis = LinearAxis() yaxis.axis_label = 'Overall number of @ mentions' yaxis.axis_label_text_font_size = '14pt' yaxis.ticker = np.linspace(0, max(y), 11, dtype=np.int)[1:] mention_barplot.add_layout(yaxis, 'left') mention_barplot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) mention_barplot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
def add_axes(self, plot, label): xaxis = LinearAxis() yaxis = LinearAxis() yaxis.axis_label = label plot.add_layout(xaxis, 'below') plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) return plot
def add_axes(self, plot, label): xaxis = LinearAxis() yaxis = LinearAxis() yaxis.axis_label = label plot.add_layout(xaxis, 'below') plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) return plot
def init_user_plot(): cprint('%s: init @ users barcharts...' % TAG, 'yellow', attrs=['bold']) global user_count global user_barplot user_count = count_users() y = [] users = [] for (user, freq) in user_count.items(): y.append(freq) users.append(user) x = np.arange(len(users)) wlist = [] for user in users: prefixes = ['@' + user] for prefix, freq in sorted(user_tweet_freq[user].items(), key=lambda kv: kv[1], reverse=True)[:10]: prefixes.append(' %s:%d' % (prefix, freq)) wlist.append(list(prefixes)) source = ColumnDataSource(dict(x=x, top=y, wlist=wlist)) glyph = VBar(x='x', top='top', bottom=0, width=0.85, fill_color='#1f77b4') user_barplot.add_glyph(source, glyph) xaxis = LinearAxis() xaxis.ticker = x xaxis.major_label_overrides = { i: '@' + user for i, user in enumerate(users) } #xaxis.major_label_standoff = -35 user_barplot.add_layout(xaxis, 'below') user_barplot.xaxis.major_label_orientation = +np.pi / 2 yaxis = LinearAxis() yaxis.axis_label = 'Overall number of tweets per @' yaxis.axis_label_text_font_size = '14pt' yaxis.ticker = np.linspace(0, max(y), 11, dtype=np.int)[1:] user_barplot.add_layout(yaxis, 'left') user_barplot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) user_barplot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
def generate_seir_chart(options, series): # output to static HTML file # output_file(series.location_name + ".html") # create a new plot with a title and axis labels p = figure(title=series.location_name, x_axis_label='Days', y_axis_label='Population') p.y_range = Range1d(0, 1.1) plot_seir_series(options, series, p, 'solid', None) if options.er or options.sr or options.ir0: p.extra_y_ranges = {"r_range": Range1d(start=0, end=np.max(series.er) * 1.1)} extra_axis = LinearAxis(y_range_name="r_range") extra_axis.axis_label = "R" p.add_layout(extra_axis, 'right') # Remove initial values for er and ir0 index = 0 for index in range(len(series.i)): if series.i[index] != 0: log("Breaking from i at index=", index) log("Previous values of er: ", series.er[:index]) log("Next values of er: ", series.er[index:index+10]) break index = index + 1 if options.er: p.line(range(index, len(series.er)), series.er[index:], legend_label="Effective r", line_width=2, line_color="grey", y_range_name="r_range") if options.sr: p.line(range(len(series.sr)), series.sr, legend_label="Standard r", line_width=2, line_color="red", line_dash='dashed', y_range_name="r_range") if options.ir0: p.line(range(index, len(series.ir0)), series.ir0[index:], legend_label="Implicit r0", line_width=2, line_color="grey", line_dash='dashed', y_range_name="r_range") p.legend.location = "top_right" p.legend.click_policy = "hide" return p
x_axis_label='wavelength(nm)', y_axis_label= 'polarizability', # x_axis_type='linear', # y_axis_type='linear', x_axis_type = None, y_axis_type = None, tools = "pan,wheel_zoom,box_zoom,zoom_in,zoom_out,save,hover,crosshair" ) p.x_range=Range1d(500, 1800) p.y_range=Range1d(-5000, 5000) ticker = SingleIntervalTicker(interval=100, num_minor_ticks=1100) xaxis = LinearAxis(ticker=ticker) # p.xaxis.visible = True xaxis.axis_label = "wavelength (nm)" xaxis.axis_line_width = 1 xaxis.axis_label_text_font_style = "italic" p.add_layout(xaxis, 'below') tickery = SingleIntervalTicker(interval=1000, num_minor_ticks=-5000) yaxis = LinearAxis(ticker=tickery) # Disable scientific notation on yaxis yaxis.formatter.use_scientific = False yaxis.axis_label = "polarizability (a.u.)" yaxis.axis_line_width = 1 yaxis.axis_label_text_font_style = "italic" p.add_layout(yaxis, 'left') x_slider = RangeSlider(start=500, end=1800, value=(500,1800), step=.1, title="Wavelength(nm)",width=250 ) y_slider = RangeSlider(start=-5000, end=5000, value=(-5000,5000), step=.1, title="polarizability (a.u.)",width=250 )
def visualize(data, columnName='Mean'): output_file("%s_trends.html" % columnName) f = lambda x: str(x)[:10] data["datetime_s"] = map(f, data.index.date) cds = ColumnDataSource(data) print(cds.data.keys()) TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,previewsave" p = figure(plot_width=800, plot_height=400, title="BTC %s vs BTC Trend" % columnName, x_axis_type="datetime", tools=TOOLS) r = p.line('Date', columnName, line_width=2, legend="BTC Prices" if columnName == 'Mean' else "BTC %s" % columnName, source=cds) p.extra_y_ranges = { 'Trend': Range1d(data['Trend'].min(), data['Trend'].max()) } p.line('Date', 'Trend', color="red", y_range_name="Trend", line_width=2, legend="BTC Trends", source=cds) yaxis2 = LinearAxis(y_range_name="Trend") yaxis2.axis_label = "BTC Trend" p.add_layout(yaxis2, 'right') p.xaxis.axis_label = 'Date' p.yaxis[0].axis_label = 'BTC %s' % columnName if columnName == "Mean": p.yaxis[0].formatter = NumeralTickFormatter(format="$0.00") else: p.yaxis[0].formatter = NumeralTickFormatter(format="0,0") if columnName == "Mean": tool_tip_col = 'Price' tool_tip_val = '$@Mean{0,0}' tool_tip_fmt = 'printf' else: tool_tip_col = columnName tool_tip_val = '@%s{0,0}' % columnName tool_tip_fmt = 'numeral' p.add_tools( HoverTool(tooltips=[ ("Date", '@datetime_s'), (tool_tip_col, tool_tip_val), ('Trend', '@Trend'), ], formatters={ "Date": "datetime", tool_tip_col: tool_tip_fmt, "Trend": "numeral" }, renderers=[r], mode='vline')) p.legend.location = "top_left" show(p)
# Create a new plot and add a renderer top = Figure(tools=tools, title=None, x_range=day_range, **figure_style_kws) top.line('day', 'S', source=source, line_color=colors[0], line_width=3, line_cap='round') top.y_range = Range1d(0., 40.) top.yaxis.axis_label = "Salinity (g/kg)" top.xaxis.axis_label_text_font_size = label_fontsize top.yaxis.axis_label_text_font_size = label_fontsize # overlay volume level chart to salinity tc = "MediumBlue" # tide color tide_range = Range1d(start=0, end=15) tide_axis = LinearAxis(y_range_name="Z") tide_axis.axis_label = "Tidal Height (m)" tide_axis.axis_label_text_color = tc tide_axis.axis_label_text_font_size = label_fontsize tide_axis.major_tick_line_color = tc tide_axis.major_label_text_color = tc tide_axis.minor_tick_line_alpha = 0. top.extra_y_ranges = {"Z": tide_range} # top.line('day', 'Z', source=source, # line_color=tc, line_width=2, line_cap='round') top.add_layout(tide_axis, "right") top.line('day', 'Z', source=source, line_color=tc, line_width=2, line_cap='round', y_range_name="Z") mid = Figure(title=None, x_range=top.x_range,