def get_states_plot():
source = AjaxDataSource(
data={'STATE': [], 'STNAME': [], 'STUSAB': [], 'TOT_POP': [], 'TOT_MALE': [], 'TOT_FEMALE': []},
data_url='/api/states/', mode='replace', method='GET')
hover = HoverTool(
tooltips=[
("State", "@STNAME"),
("Population", "@TOT_POP"),
("Female Population", "@TOT_FEMALE"),
("Male Population", "@TOT_MALE"),
]
)
plot = figure(title='Population by State', plot_width=1200, plot_height=500,
x_range=FactorRange(factors=get_state_abbreviations()), y_range=(0, 40000000),
tools=[hover, 'tap','box_zoom','wheel_zoom','save','reset'])
plot.toolbar.active_tap = 'auto'
plot.xaxis.axis_label = 'State'
plot.yaxis.axis_label = 'Population'
plot.yaxis.formatter = NumeralTickFormatter(format="0a")
plot.sizing_mode = 'scale_width'
plot.vbar(bottom=0, top='TOT_POP', x='STUSAB', legend=None, width=0.5, source=source)
url = "/counties/@STATE/"
taptool = plot.select(type=TapTool)
taptool.callback = OpenURL(url=url)
return plot
评论列表
文章目录