در چهارشنبه 21 نوامبر 2018، ساعت 18:06:24 (UTC+3:30)، Raha Asadimehr نوشته:
···
سلام ،
من سعی می کنم از این مثال استفاده کنم:
اما من نمیتوانستم برای اضافه کردن یک ابزار شناور برای هر نقطه اضافه کنم.
آیا می توانید لطفا به من کمک کنید؟
from bokeh.layouts import row, widgetbox
from bokeh.models import Select
from bokeh.palettes import Spectral5
from bokeh.plotting import curdoc, figure
from bokeh.sampledata.autompg import autompg_clean as df3
from bokeh.models import LinearInterpolator, HoverTool,ColumnDataSource
import numpy as np
df = df1.copy()
df=df.rename( columns={“sum”: “n”})
df[‘l1’]= pd.Categorical(df[‘l’], categories=df[‘l’].unique()).codes
df[‘aa_type’]= pd.Categorical(df[‘aa’], categories=df[‘aa’].unique()).codes
df[‘uu_type’]= pd.Categorical(df[‘uu’], categories=df[‘uu’].unique()).codes
df[‘n_range’]= df.n_code.values*5
SIZES = list(set(df.n_range.values))
N_SIZES = len(SIZES)
COLORS =Spectral5
N_COLORS = len(COLORS)
aa= list(set(df.aa.values))
N_aa = len(aa)
uu = list(set(df.uu.values))
N_uu= len(uu)
columns = sorted(df.columns)
discrete = [x for x in columns if df.dtype == object]
continuous = [x for x in columns if x not in discrete]
def create_figure():
xs = df[x.value].values
ys = df[y.value].values
x_title = x.value.title()
y_title = y.value.title()
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)
source= ColumnDataSource(data=dict(xs=, ys=,RName=, PName=, n=, A=))
new_data = dict(
x=xs,
y=ys,
R=df[‘RName’],
P=df[‘PName’],
N=df[‘n’],
A=df[‘A’],
)
source.data=new_data
hover = HoverTool(tooltips=[ (“R”, “@RName”), (“P”, “@PName”), (“N”, “@n”) , (“A”, “@A”) ])
p = figure(plot_height=800, plot_width=800, tools=‘pan,box_zoom,reset’, **kw)
p.add_tools(hover)
p.xaxis.axis_label = x_title
p.yaxis.axis_label = y_title
if x.value in discrete:
p.xaxis.major_label_orientation = pd.np.pi / 4
sz = 20
if size.value != ‘None’:
if len(set(df[size.value])) > N_SIZES:
groups = pd.qcut(df[size.value].values, N_SIZES, duplicates=‘drop’)
else:
groups = pd.Categorical(df[size.value])
sz = [SIZES[xx] for xx in groups.codes]
c = “#31AADE”
if color.value != ‘None’:
if len(set(df[color.value])) > N_SIZES:
groups = pd.qcut(df[color.value].values, N_COLORS, duplicates=‘drop’)
else:
groups = pd.Categorical(df[color.value])
c = [COLORS[xx] for xx in groups.codes]
a = “I”
if aa.value != ‘All’:
if len(set(df[aa.value])) > N_ASSET:
groups = pd.qcut(df[aa.value].values,N_aa, duplicates=‘drop’)
else:
groups = pd.Categorical(df[aa.value])
a = [aa[xx] for xx in groups.codes]
u = “InterestRate:CrossCurrency:Basis”
if uu.value != ‘All’:
if len(set(df[uu.value])) > N_uu:
groups = pd.qcut(df[uu.value].values,N_uu, duplicates=‘drop’)
else:
groups = pd.Categorical(df[uu.value])
u= [uu[xx] for xx in groups.codes]
p.circle(x=xs, y=ys, color=c, size=sz, line_color=“white”, alpha=0.6, hover_color=‘white’, hover_alpha=0.5)
#,source=source
return p
def update(attr, old, new):
layout.children[1] = create_figure()
x = Select(title=‘X-Axis’, value=‘uu_type’, options=columns)
x.on_change(‘value’, update)
y = Select(title=‘Y-Axis’, value=‘location’, options=columns)
y.on_change(‘value’, update)
asset= Select(title=“aa”, value=“All”, options=list(set(df1.aa.values)))
asset.on_change(‘value’, update)
upi= Select(title=“uu”, value=“All”, options=list(set(df1.uu.values)))
upi.on_change(‘value’, update)
size = Select(title=‘Size’, value=‘n_range’, options=[‘None’] + continuous)
size.on_change(‘value’, update)
color = Select(title=‘Color’, value=‘aa_type’, options=[‘None’] + continuous)
color.on_change(‘value’, update)
controls = widgetbox([x, y, color, size,aa,uu], width=550)
layout = row(controls, create_figure())
curdoc().add_root(layout)
curdoc().title = …
``