def weekday_builder(): dow = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] xdr = FactorRange(factors=dow) ydr = DataRange1d(sources=[source_dow.columns("data_range")]) plot = Plot(title="Weekday of Job Posting", data_sources=[source_dow], x_range=xdr, y_range=ydr, plot_width=760, plot_height=500) xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi / 4.0) yaxis = LinearAxis(plot=plot, dimension=1) yaxis.major_tick_in = 0 ygrid = Grid(plot=plot, dimension=1, axis=yaxis) quad = Rect(x="weekday", y="weekday_half", height="count", width=0.9, fill_color="#D9301A") bars = Glyph(data_source=source_dow, xdata_range=xdr, ydata_range=ydr, glyph=quad) plot.renderers.append(bars) plot.background_fill = '#686975' return plot
def population(): xdr = FactorRange(factors=years) ydr = DataRange1d( sources=[source_known.columns("y"), source_predicted.columns("y")]) plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=200) plot.add_layout(CategoricalAxis(major_label_orientation=pi / 4), 'below') line_known = Line(x="x", y="y", line_color="violet", line_width=2) line_known_glyph = plot.add_glyph(source_known, line_known) line_predicted = Line(x="x", y="y", line_color="violet", line_width=2, line_dash="dashed") line_predicted_glyph = plot.add_glyph(source_predicted, line_predicted) plot.add_layout( Legend(orientation="bottom_right", legends=dict(known=[line_known_glyph], predicted=[line_predicted_glyph]))) return plot
def job_loc_plot_builder(): xdr = FactorRange(factors=countries) ydr = DataRange1d(sources=[source_country.columns("data_range")]) plot = Plot(title="Postings by Job Location (Country)", data_sources=[source_country], x_range=xdr, y_range=ydr, plot_width=760, plot_height=500) xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi / 4.0) yaxis = LinearAxis(plot=plot, dimension=1) yaxis.major_tick_in = 0 ygrid = Grid(plot=plot, dimension=1, axis=yaxis) quad = Rect(x="country", y="count_half", height="count", width=0.9, fill_color="#483D8B") bars = Glyph(data_source=source_country, xdata_range=xdr, ydata_range=ydr, glyph=quad) plot.renderers.append(bars) plot.background_fill = '#333333' return plot
def make_box_violin_plot(data, maxwidth=0.9): """ data: dict[Str -> List[Number]] maxwidth: float Maximum width of tornado plot within each factor/facet Returns the plot object """ print("Plotting box violin graph") plot_width = 500 plot_height = 350 df = pd.DataFrame(columns=["group", "width", "height", "texts", "cats"]) bar_height = 50 bins = [0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e10] # Compute histograms, while keeping track of max Y values and max counts for i, (group, vals) in enumerate(data.iteritems()): hist, edges = np.histogram(vals, bins) df = df.append(pd.DataFrame(dict( group = group, width = np.log2(hist[1:]), height = np.ones(len(hist) - 1), texts = ["%d Nodes" % i for i in hist[1:-1]] + ["%d" % hist[-1]], cats = [">10^%d" % np.log10(bin) for bin in bins[1:-1]], ))) df.replace(-np.inf, 0) # Normalize the widths df["width"] *= (maxwidth / df["width"].max()) ds = ColumnDataSource(df) xdr = FactorRange(factors=sorted(df["group"].unique())) ydr = FactorRange(factors=list(df["cats"])) plot = Plot(data_sources=[ds], x_range=xdr, y_range=ydr, title="Degree Distribution (log scale)", plot_width=plot_width, plot_height=plot_height, tools=[]) yaxis = CategoricalAxis(plot=plot, location="left", axis_label="degree") plot.left.append(yaxis) glyph = Rect(x="group", y="cats", width="width", height="height", fill_color="#3366ff") text_glyph = Text(x="group", y="cats", text="texts", text_baseline="middle", text_align="center", angle=0) plot.renderers.append(Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=glyph)) plot.renderers.append(Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=text_glyph)) return plot
def population(): xdr = FactorRange(factors=years) ydr = DataRange1d(sources=[source_known.columns("y"), source_predicted.columns("y")]) plot = Plot(title=None, data_sources=[source_known, source_predicted], x_range=xdr, y_range=ydr, plot_width=800, plot_height=200) xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4) # yaxis = LinearAxis(plot=plot, dimension=1, ...) line_known = Line(x="x", y="y", line_color="violet", line_width=2) line_known_glyph = Glyph(data_source=source_known, xdata_range=xdr, ydata_range=ydr, glyph=line_known) plot.renderers.append(line_known_glyph) line_predicted = Line(x="x", y="y", line_color="violet", line_width=2, line_dash="dashed") line_predicted_glyph = Glyph(data_source=source_predicted, xdata_range=xdr, ydata_range=ydr, glyph=line_predicted) plot.renderers.append(line_predicted_glyph) legend = Legend(plot=plot, orientation="bottom_right", legends=dict(known=[line_known_glyph], predicted=[line_predicted_glyph])) plot.renderers.append(legend) return plot
source = ColumnDataSource(dict( names = list(css3_colors.Name), groups = list(css3_colors.Group), colors = list(css3_colors.Color), )) xdr = FactorRange(factors=list(css3_colors.Group.unique())) ydr = FactorRange(factors=list(reversed(css3_colors.Name))) plot = Plot(title="CSS3 Color Names", x_range=xdr, y_range=ydr, plot_width=600, plot_height=2000) rect = Rect(x="groups", y="names", width=1, height=1, fill_color="colors", line_color=None) plot.add_glyph(source, rect) xaxis_above = CategoricalAxis(major_label_orientation=pi/4) plot.add_layout(xaxis_above, 'above') xaxis_below = CategoricalAxis(major_label_orientation=pi/4) plot.add_layout(xaxis_below, 'below') plot.add_layout(CategoricalAxis(), 'left') doc = Document() doc.add(plot) if __name__ == "__main__": filename = "colors.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "CSS3 Color Names")) print("Wrote %s" % filename)
groups=list(css3_colors.Group), colors=list(css3_colors.Color), )) xdr = FactorRange(factors=list(css3_colors.Group.unique())) ydr = FactorRange(factors=list(reversed(css3_colors.Name))) plot = Plot(title="CSS3 Color Names", data_sources=[source], x_range=xdr, y_range=ydr, plot_width=600, plot_height=2000) xaxis_top = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi / 4, location="top") xaxis_bottom = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi / 4, location="bottom") yaxis = CategoricalAxis(plot=plot, dimension=1) # XXX: Wrong radius. Doesn't respect 'radius'. 'line_color' on 'rect' affects 'circle'. # circle = Circle(x="groups", y="names", radius=1, fill_color="colors") # plot.renderers.append(Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=circle)) rect = Rect(x="groups", y="names", width=1, height=1,
def make_box_violin_plot(data, num_bins, maxwidth=0.9): """ data: dict[Str -> List[Number]] maxwidth: float Maximum width of tornado plot within each factor/facet Returns the plot object """ df = pd.DataFrame(columns=["group", "centers", "width", "height", "texts"]) bar_height = 50 bins = [0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6] # Compute histograms, while keeping track of max Y values and max counts for i, (group, vals) in enumerate(data.iteritems()): hist, edges = np.histogram(vals, bins) df = df.append( pd.DataFrame( dict( group=group, centers=np.arange(len(hist)) * bar_height, width=np.log10(hist), height=np.ones(hist.shape) * bar_height, texts=map(str, hist), ))) df.replace(-np.inf, 0) # Normalize the widths df["width"] *= (maxwidth / df["width"].max()) ds = ColumnDataSource(df) xdr = FactorRange(factors=sorted(df["group"].unique())) ydr = DataRange1d(sources=[ds.columns("centers")]) plot = Plot(data_sources=[ds], x_range=xdr, y_range=ydr, title="Degree Distribution", plot_width=750, plot_height=600, tools=[]) xaxis = CategoricalAxis(plot=plot, location="bottom", axis_label="number of nodes") #yaxis = LogAxis(plot=plot, location="left", axis_label="degree") plot.below.append(xaxis) #plot.above.append(yaxis) #xgrid = Grid(plot=plot, dimension=0, axis=xaxis) #ygrid = Grid(plot=plot, dimension=1, axis=yaxis) glyph = Rect(x="group", y="centers", width="width", height="height") text_glyph = Text(x="group", y="centers", text="texts", text_baseline="middle", text_align="center") plot.renderers.append( Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=glyph)) plot.renderers.append( Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=text_glyph)) return plot