โบเก้: แผนภูมิโดนัท เปลี่ยนขนาดเริ่มต้น

หากฉันจำไม่ผิด แผนภูมิโดนัทเป็นเพียงแผนภูมิเดียวที่มีขนาดเริ่มต้นที่กำหนดไว้ที่ 400 ดังนั้นหากฉันกำหนดขนาดของพล็อตของฉันให้น้อยกว่า 400 โดนัทจะตัดด้านบนและด้านล่างของพล็อตออก ฉันจะเปลี่ยนขนาดของโดนัทได้อย่างไร

รหัส:

arr = [1,3,2,4]
data = pd.Series(arr, index=list('abcd'))
plot = Donut(data, plot_height=300)
show(plot)

ภาพหน้าจอ


person Austin    schedule 04.05.2017    source แหล่งที่มา
comment
ฉันได้ลองใช้เครื่องมือปรับขนาดแล้ว และแม้ว่าจะใช้งานได้ แต่ฉันไม่อยากให้ผู้ใช้ใช้เครื่องมือนี้ทุกครั้ง   -  person Austin    schedule 04.05.2017


คำตอบ (1)


bokeh.charts API รวมถึง Donut เลิกใช้แล้วและถูกลบออกทั้งหมดในปี 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)

ป้อนคำอธิบายรูปภาพที่นี่

person bigreddot    schedule 07.06.2018