def create_figure(df,x,y,discrete,quantileable,continuous,size,color,controls):
xs = df[x.value].values
ys = df[y.value].values
# x_title = x.value.title()
# y_title = y.value.title()
x_title = "Marginal Effective Tax Rate"
y_title = "Asset Category"
source = ColumnDataSource(ColumnDataSource.from_df(df))
kw = dict()
if x.value in discrete:
kw['x_range'] = sorted(set(xs))
if y.value in discrete:
kw['y_range'] = sorted(set(ys))
# kw['title'] = "%s vs %s" % (x_title, y_title)
#kw['title'] = "Marginal Effective Tax Rates on Typically Financed Corporate Investments, 2016 Law"
# kw['title'] = "Marginal Effective Tax Rates on Corporate Investments, 2016 Law"
kw['title'] = "METRs on Corporate Investments, 2016 Law"
p = figure(plot_height=400, plot_width=600, tools='pan,box_zoom,reset,hover', **kw)
p.xaxis.axis_label = x_title
p.yaxis.axis_label = y_title
hover = p.select(dict(type=HoverTool))
hover.tooltips = [('Asset', '@Asset')]
if x.value in discrete:
p.xaxis.major_label_orientation = pd.np.pi / 4
sz = 9
if size.value != 'None':
groups = pd.qcut(df[size.value].values, len(SIZES))
sz = [SIZES[xx] for xx in groups.codes]
c = "#73000A"
if color.value != 'None':
groups = pd.qcut(df[color.value].values, len(COLORS))
c = [COLORS[xx] for xx in groups.codes]
p.circle(x=xs, y=ys, source=source, color=c, size=sz, line_color="white", alpha=0.6, hover_color='white', hover_alpha=0.5)
# p.title.text_color = "black"
# p.title.text_font = "Georgia"
return p
评论列表
文章目录