Python 波基:圆环图,更改默认大小

Python 波基:圆环图,更改默认大小,python,visualization,bokeh,Python,Visualization,Bokeh,如果我没弄错的话,甜甜圈图表是唯一已经设置了默认大小400的图表。因此,如果我将绘图的大小设置为小于400,则甜甜圈会切断绘图的顶部和底部。我如何改变甜甜圈的大小呢 代码: bokeh.charts API(包括甜甜圈)在2017年被弃用并完全删除。相反,请使用稳定且受支持的bokeh.plotting API。在0.13.0版本中,您可以执行以下操作: from collections import Counter from math import pi import pandas as p

如果我没弄错的话,甜甜圈图表是唯一已经设置了默认大小400的图表。因此,如果我将绘图的大小设置为小于400,则甜甜圈会切断绘图的顶部和底部。我如何改变甜甜圈的大小呢

代码:

bokeh.charts API(包括甜甜圈)在2017年被弃用并完全删除。相反,请使用稳定且受支持的bokeh.plotting API。在0.13.0版本中,您可以执行以下操作:

from collections import Counter
from math import pi

import pandas as pd

from bokeh.palettes import Category20c
from bokeh.plotting import figure, show
from bokeh.transform import cumsum

# Data

x = Counter({
    '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)]

# Plotting code

p = figure(plot_height=350, title="Donut Chart", toolbar_location=None,
           tools="hover", tooltips=[("Country", "@country"),("Value", "@value")])

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="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)

我已经尝试过调整大小工具,虽然它可以工作,但我不希望用户每次都使用该工具
from collections import Counter
from math import pi

import pandas as pd

from bokeh.palettes import Category20c
from bokeh.plotting import figure, show
from bokeh.transform import cumsum

# Data

x = Counter({
    '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)]

# Plotting code

p = figure(plot_height=350, title="Donut Chart", toolbar_location=None,
           tools="hover", tooltips=[("Country", "@country"),("Value", "@value")])

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="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)