def pieChart(df): bokeh.io.output_file('static/graphics/pie.html') labels = list(df['source'].unique()) cant = list(df['source'].value_counts()) x = {labels[i]: cant[i] for i in range(len(labels))} data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = viridis(len(x)) p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='country', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None # output_file('static/graphics/pie.html') return p
def generate_chart(self): """ Generation of the pie chart bokeh.plotting.figure and different display settings :return: Pie chart bokeh.plotting.figure """ self.data['angle'] = self.data['value'] / self.data['value'].sum( ) * 2 * pi self.chart = figure(plot_height=400, title=self.title, toolbar_location=None, tools="hover", tooltips="@{}: @value".format(self.index_name), x_range=(-0.5, 1.0)) self.chart.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend=self.index_name, source=self.data) self.chart.axis.axis_label = None self.chart.axis.visible = False self.chart.grid.grid_line_color = None self.chart.title.align = "center" self.chart.title.text_font_style = "bold" self.chart.title.text_color = "olive"
def _create_varexp_pie_plt(comptable_cds, n_comps): fig = plotting.figure(plot_width=400, plot_height=400, title='Variance Explained View', tools=['hover,tap,save'], tooltips=[('Component ID', ' @component'), ('Kappa', '@kappa{0.00}'), ('Rho', '@rho{0.00}'), ('Var. Exp.', '@varexp{0.00}%')]) fig.wedge(x=0, y=1, radius=.9, start_angle=transform.cumsum('angle', include_zero=True), end_angle=transform.cumsum('angle'), line_color="white", fill_color='color', source=comptable_cds, fill_alpha=0.7) fig.axis.visible = False fig.grid.visible = False fig.toolbar.logo = None circle = models.Circle(x=0, y=1, size=150, fill_color='white', line_color='white') fig.add_glyph(circle) return fig
def create_price_grade_chart(): group_by_grade = housing[['price', 'grade']].groupby(['grade']).mean() group_by_grade['angle'] = group_by_grade['price'] / group_by_grade[ 'price'].sum() * 2 * math.pi group_by_grade['color'] = color.Category20c[len(group_by_grade.index)] group_by_grade['index'] = group_by_grade.index p1 = figure(title="Average price of houses depending on grade", toolbar_location=None, tools='hover', sizing_mode="scale_width") p1.ygrid.grid_line_color = None p1.xaxis.visible = False p1.yaxis.visible = False p1.toolbar.logo = None p1.toolbar_location = None p1.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="black", fill_color='color', legend='grade', source=group_by_grade) hover = p1.select(dict(type=HoverTool)) hover.tooltips = [('Average price', '@price{0,0}$'), ('Grade', '@grade')] tab1 = Panel(child=p1, title='Grade') return tab1
def pie_plot(str1): x = count_items(str1) data = pd.DataFrame.from_dict( dict(x), orient='index').reset_index().rename(index=str, columns={ 0: 'value', 'index': str1 }) data['angle'] = data['value'] / sum(x.values()) * 2 * pi if len(x) < 3: colours = ['#3182bd', '#6baed6', '#9ecae1'] data['color'] = colours[:len(x)] else: data['color'] = Category20c[len(x)] p = figure(plot_height=350, title=str1.capitalize(), toolbar_location=None, tools="hover", tooltips="@{}: @value".format(str1)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend=str1, source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return p
def drawPieChart(x, paletteType='Set1'): ''' Input: x --- Dictionary of names and values (e.g. x = {'United States': 157, 'United Kingdom': 93} ''' data = pd.Series(x).reset_index(name='value').rename(columns={'index':'country'}) data['angle'] = data['value']/data['value'].sum() * 2*pi colors = brewer[paletteType][8] data['color'] = colors[:len(x)] ## p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, ## tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p = figure(plot_height=350, toolbar_location=None, tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='country', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None p.outline_line_color = None p.sizing_mode = 'scale_width' script, div = components(p) return script, div
def show(): output_file("html_table_data.html") x = { 'Passed': 157, 'Failed': 93, 'Skipped': 89, } data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None show(p)
def generate(self, args): data = self.get_data_dict(args) source = { "empl_name": [], "hours": [], } for empl, hours in data.items(): source["empl_name"].append( self.get_display_name_for_key_entity(empl)) source["hours"].append(float(hours)) hour_sum = sum(source["hours"]) source["angle"] = [ hours / hour_sum * 2 * math.pi for hours in source["hours"] ] source["color"] = util.repeat_maxlen(ColorPalette, len(source["hours"])) self.figure.wedge( x=0, y=1, radius=0.4, start_angle=cumsum("angle", include_zero=True), end_angle=cumsum("angle"), line_color="black", fill_color="color", legend="empl_name", source=source, )
def generate_pie_chart(df, title, driver, index, output_file_dir): df["angle"] = df["value"] / df["value"].sum() * 2 * pi colors = ["#f44336", "#2196f3"] df["color"] = colors[:len(df)] legend = [] for row in df.iterrows(): _, remain = row legend.append(f"{remain.answer} - {remain.percent} ({remain.value})") df["legend"] = legend p = figure( plot_height=350, title=title[index], toolbar_location=None, tools="hover", tooltips="@answer: @value", x_range=(-0.5, 1.0), output_backend="svg", ) # p.wedge( x=0, y=1, radius=0.4, start_angle=cumsum("angle", include_zero=True), end_angle=cumsum("angle"), line_color="white", fill_color="color", legend_field="legend", source=df, ) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None write_chart(output_file_dir, title[index], p, driver)
def piechart(src, heads, val, acci, title=''): title = title + accisev[acci] + " casualties, " + val + " by " + heads src.columns = src.columns.get_level_values(0) src['angle'] = src[val] / src[val].sum() * 2 * pi src['percent'] = src[val] / src[val].sum() * 100.00 src['color'] = viridis(len(src.index)) p = figure(plot_height=350, title=title, toolbar_location=None, tools="hover", tooltips="@" + heads + ": @" + val + ", @percent", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend=heads, source=src) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None show(p)
def get_plot(x): data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / 100 * 2 * pi data['color'] = get_color(x) source = ColumnDataSource(data) p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', source=source) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return p
def plot_gender(): x = {'男性 Male': 150, '女性 Female': 129, '答えたくない Prefer not to say': 7} data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'gender'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, plot_width=550, title="Gender", toolbar_location=None, tools="hover", tooltips="@gender: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='gender', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None script, div = components(p) return script, div
def diagram(a): x = { 'Организованные мероприятия': a[0], 'Гость мероприятий': a[1], } print(type(x)) data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = ['#feeaf5', '#ced2ff'] p = figure(plot_height=350, title="Мероприятия", toolbar_location=None, tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return p
def graph_pie_sport_origin(title, origin): # Manage data with Pandas # Based on code found in https://bokeh.pydata.org/en/latest/docs/gallery/pie_chart.html data = pd.Series(origin).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * 3.14159 data['color'] = ['#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59'] graph = figure(plot_height=350, title=title, toolbar_location=None, tools="hover", tooltips="@country: @value") # Graph the pie pieces graph.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) # Hide background grid and axis graph.axis.visible = False graph.xgrid.visible = False graph.ygrid.visible = False # Automatically adjust graph size graph.sizing_mode = default_sizing return components(graph)
def plot_bokeh_sex_pie(queryset: QuerySet) -> Figure: values = list(queryset.values("sex")) data = (pd.DataFrame(values).replace({ "sex": SEX_VALUES }).value_counts().reset_index(name="value").rename(columns={ "index": "sex" }).merge(SEX_COLORS, left_on="sex", right_index=True)) data["angle"] = data["value"] / data["value"].sum() * 2 * pi p = figure( plot_height=250, plot_width=350, title="Sex", toolbar_location=None, tools="hover", tooltips="@sex: @value", x_range=(-0.5, 1.0), ) p.wedge( x=0, y=1, radius=0.3, start_angle=cumsum("angle", include_zero=True), end_angle=cumsum("angle"), line_color="white", fill_color="color", legend_field="sex", source=data, ) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return p
def print_pie_chart(data_, filename="outputPie.html", title_="default", top=19): for k, v in data_.items(): data_[k] = round(v, 1) output_file(filename) data_sorted = sorted(data_.items(), key=lambda x:x[1], reverse=True) if len(data_) > top+1 : misc = 0 while len(data_sorted) > top: misc += float(data_sorted.pop()[1]) data_sorted.append(("misc", round(misc,1))) print(" cut len down to: " + str(len(data_))) print (data_sorted) data_ = Counter(data_sorted) data = pd.DataFrame.from_dict(dict(data_), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'country'}) data['angle'] = data['value']/sum(data_.values()) * 2*pi data['color'] = Category20c[len(data_)] p = figure(plot_height=520, plot_width = 1000, title=title_, toolbar_location="left", tools="hover", tooltips="@country: @value") p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None show(p)
def sentiment_tab(df): sentiment_count = df["Sentiment"].value_counts() x = { 'Positive': sentiment_count.iloc[0], 'Negative': sentiment_count.iloc[1] } chart_colors = ['#DAF7A6', '#FF5733'] data = pd.Series(x).reset_index(name='value').rename(columns={'index':'sentiment'}) data['angle'] = data['value']/data['value'].sum() * 2*pi data['color'] = chart_colors[:len(x)] p = figure(plot_height=350, title="Sentiment Chart", toolbar_location=None, tools="hover", tooltips="@sentiment: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='sentiment', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None tab = Panel(child=p, title='Sentiment Chart') return tab
def draw_piechart(collection, colum, count, asc): mycollection = mydb[collection] rs = mycollection.find().limit(count).sort([(colum, asc)]) #data_lastday = get_data_sort('moneyflow_lastday','net_mf_amount',-1,100) #按照industry分类 #将查询结果转换为Df data = pd.DataFrame(list(rs)) grouped = data.groupby('industry') groupcount = grouped.size() pie_data = pd.DataFrame() pie_data['value'] = groupcount #data拼装 industry angle color pie_data['angle'] = pie_data['value'] / count * 2 * pi pie_data['color'] = Category20c[len(pie_data)] p = figure(plot_height=400, plot_width=400, toolbar_location=None, tools="hover", tooltips="@industry: @value") p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='industry', source=pie_data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None # 网格线颜色 return p
def get_per_app_usage(): total_time_spent = df.duration.sum() per_app_df = df.groupby('app_name')['duration'].sum().sort_values( ascending=False).to_frame().reset_index() per_app_df['angle'] = np.nan per_app_df['color'] = np.nan per_app_df.angle = per_app_df.duration.apply( lambda x: x.seconds / total_time_spent.seconds * 2 * pi) per_app_df['color'] = per_app_df.app_name.apply(lambda x: color_map[x]) per_app_df['duration_min'] = per_app_df['duration'].apply( lambda x: x.seconds // 60) p = figure(plot_height=400, plot_width=400, toolbar_location=None, tools="hover", tooltips="@app_name: @duration_min min") p.wedge(x=0, y=1, radius=0.9, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', source=per_app_df) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return json.dumps(json_item(p, "per_app_usage"))
def pie_chart(df): ccounts = df.Country.value_counts() df.loc[df['Country'].isin(ccounts[ccounts.values < 500].index), 'Country'] = 'Others' rf = pd.DataFrame(df['Country'].value_counts()) rf['angle'] = rf['Country'] / rf['Country'].sum() * 2 * pi rf['color'] = Category20c[rf.shape[0]] p = figure(plot_height=500, title="Country wise Sales", toolbar_location=None, tools="hover", tooltips="@index: @Country", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.5, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='index', source=rf) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None return p
def plot_meals(): x = { '3食 3 meals': 175, '3食未満 Less than 3 meals': 88, '3食以上 More than 3 meals': 23 } data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'meals'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, plot_width=550, title="Number of meals", toolbar_location=None, tools="hover", tooltips="@diet: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='meals', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None script, div = components(p) return script, div
def plot_mental_diseases(): x = {'いいえ No': 182, '多分 Maybe': 43, 'はい Yes': 39} data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'mental_diseases'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, plot_width=550, title="Have you experienced any disorder?", toolbar_location=None, tools="hover", tooltips="@mental_diseases: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='mental_diseases', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None script, div = components(p) return script, div
def plot_diet(): x = { '同じくらい Balanced': 155, '肉中心 Meat focused': 98, '野菜中心 Vegetable focused': 33 } data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'diet'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, plot_width=550, title="Diet", toolbar_location=None, tools="hover", tooltips="@diet: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='diet', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None script, div = components(p) return script, div
def get_question_pie(hotel_id, question): """ this function gets hotel_id and question as input and returns pie chart for that questions answers for that hotel """ x = dict(pd.DataFrame({'col1': get_question_answers(hotel_id,question)}).col1.value_counts()) # print(x) data = pd.Series(x).reset_index(name='value').rename(columns={'index':'answer'}) data['angle'] = data['value']/data['value'].sum() * 2*pi data['color'] = viridis(len(x)) p = figure(plot_height=250, plot_width = 375, title= question, toolbar_location=None, tools="hover", tooltips="@answer: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1,radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="black", fill_color='color', legend='answer', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None script,div = components(p) return [script,div]
def first_graph(): df = read_mongo() df_corona = df[df.corona == 'Ja'] df_new = df_corona['province'].value_counts() data = pd.Series(df_new).reset_index(name='corona').rename( columns={'index': 'province'}) data['angle'] = data['corona'] / data['corona'].sum() * 2 * pi p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@province : @corona") p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='red', legend='province', source=data) return p
def getPieChart(d): import copy x = copy.deepcopy(d) del x['timestamp'] for k in x.keys(): tmp = x[k] x[k] = sum(tmp, 0.0) / len(tmp) data = pd.Series(x).reset_index(name='value').rename( columns={'index': 'country'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@country: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None output_file("html/시간별 평균 활동(pie).html") show(p)
def pie(list): data = pd.Series(list).reset_index(name='value').rename( columns={'index': 'candidat'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = Category20c[len(list)] p = figure(plot_height=500, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@candidat: @value", x_range=(-0.5, 1.0)) p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='candidat', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None show(p)
def get_total_score_doughnut(hotel_id): """ this function will get hotel id as an input and return doughnut graph (script and div) for total score """ score = get_total_review_score(hotel_id) x = { # pass the id of selected hotel here to get the doughnut graph 'Score': score, 'Rest' : (5-score) } data = pd.Series(x).reset_index(name='value').rename(columns={'index':'scoring'}) data['angle'] = data['value']/5 * 2*pi data['color'] = ['blue', 'white'] p = figure(plot_height=250, plot_width = 375, title="Overall Score", toolbar_location=None, tools="hover", tooltips="@scoring: @value", x_range=(-0.5, 1.0)) p.annular_wedge(x=0, y=1,inner_radius = 0.2, outer_radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="black", fill_color='color', legend='scoring', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None script,div = components(p) return [script,div]
def create_pie_chart(self): data = pd.Series(self._pie_chart_data).reset_index( name='value').rename(columns={'index': 'category'}) data['angle'] = data['value'] / data['value'].sum() * 2 * pi data['color'] = self.get_category20c_color() p = figure(plot_height=self.pie_chart_conf['plot_height'], title=self.chart_title, toolbar_location=None, tools="hover", tooltips="@category: @value", x_range=self.pie_chart_conf['xrange']) p.wedge(x=self.pie_chart_conf['x'], y=self.pie_chart_conf['y'], radius=self.pie_chart_conf['radius'], start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend_field='category', source=data) p.axis.axis_label = None p.axis.visible = False p.grid.grid_line_color = None plot_html = file_html(p, CDN) return plot_html
def make_ajax_plot(): test = AjaxDataSource(data_url=request.url_root + 'data/', polling_interval=2000, mode='replace') test.data = dict(angle=[], country=[], value=[], color=[]) print(test.data) plot = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@country: @value") plot.annular_wedge(x=0, y=1, inner_radius=0.2, outer_radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color=None, fill_color='color', legend='country', source=test) plot.axis.axis_label = None plot.axis.visible = False plot.grid.grid_line_color = None script, div = components(plot) return script, div
def test_include_zero(object): s = bt.cumsum("foo", include_zero=True) assert isinstance(s, dict) assert list(s.keys()) == ["expr"] assert isinstance(s['expr'], CumSum) assert s['expr'].field == 'foo' assert s['expr'].include_zero == True
'United States': 157, 'United Kingdom': 93, 'Japan': 89, 'China': 63, 'Germany': 44, 'India': 42, 'Italy': 40, 'Australia': 35, 'Brazil': 32, 'France': 31, 'Taiwan': 31, 'Spain': 29 }) data = pd.DataFrame.from_dict(dict(x), orient='index').reset_index().rename(index=str, columns={0:'value', 'index':'country'}) data['angle'] = data['value']/sum(x.values()) * 2*pi data['color'] = Category20c[len(x)] p = figure(plot_height=350, title="Pie Chart", toolbar_location=None, tools="hover", tooltips="@country: @value") p.wedge(x=0, y=1, radius=0.4, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend='country', source=data) p.axis.axis_label=None p.axis.visible=False p.grid.grid_line_color = None show(p)