Javascript 什么变量可以用在";%{variable}";绘声绘色的语法

Javascript 什么变量可以用在";%{variable}";绘声绘色的语法,javascript,python,dataframe,plotly,Javascript,Python,Dataframe,Plotly,问题是关于下面引用的代码中的'%{variable}'语法,特别是hovertemplate、text和customdatakwargs中的go.Bar()函数 fig = go.Figure( data=[ go.Bar( name=coln, x=df.index, y=df[coln], # coln means columnName hovertemplate =

问题是关于下面引用的代码中的
'%{variable}'
语法,特别是
hovertemplate、text
customdata
kwargs中的
go.Bar()
函数

fig = go.Figure(
    data=[
        go.Bar(
            name=coln, x=df.index, y=df[coln], 
            # coln means columnName
            
            hovertemplate = '%{x}' + '%{y}' # <============= this thing here
            + '%{text}' + '%{customdata} + %{coln}', 
            # can access x,y,text,customdata. ie. all kwargs of this trace ("trace" is a plotly technical term, meaning, this bar plot)
            # can NOT access any other my own variables like df or coln

            customdata = [coln]*len(df.index),
            text = [
                '<b>colname==</b>:'+ another_df.loc[coln] + somefunction(coln)
                # can only do things around df and coln, not x nor y   <============= and this thing here
            ]*len(df.index),

        ) for coln in df.columns
    ],  
)
fig=go.Figure(
资料=[
去吧,酒吧(
name=coln,x=df.index,y=df[coln],
#coln的意思是列名

hovertemplate='{x}'+'{y}'#通常,
texttemplate
hovertemplate
可以访问跟踪级别的任何属性,即在这种情况下
go.Bar()
的属性。因此
x
y
customdata
可以访问:

导入plotly.graph\u对象
go.Figure(go.Bar(
x=[“a”,“b”],y=[1,2],customdata=[[“你好”,“那里”],[“你好”,“那里”],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata[1]}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata[1]}”,
textposition=“自动”
))
customdata
这里可以是列表列表列表(如上所述)或DICT列表,访问方式如下:

导入plotly.graph\u对象
go.Figure(go.Bar(
x=[“a”,“b”],y=[1,2],customdata=[dict(hi=“there”),dict(hi=“here”)],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
textposition=“自动”
))
customdata
格式与Pandas的
to_dict('records')
格式兼容:

导入plotly.graph\u对象
作为pd进口熊猫
df=pd.数据帧(dict(
x=[“a”,“b”],y=[1,2],hi=[“那里”,“这里”]
))
go.Figure(go.Bar(
x=df.x,y=df.y,customdata=df[[“hi”]],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
textposition=“自动”
))

通常,
texttemplate
hovertemplate
可以访问跟踪级别的任何属性,即在这种情况下
go.Bar()
的属性。因此
x
y
customdata
可以访问:

导入plotly.graph\u对象
go.Figure(go.Bar(
x=[“a”,“b”],y=[1,2],customdata=[[“你好”,“那里”],[“你好”,“那里”],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata[1]}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata[1]}”,
textposition=“自动”
))
customdata
这里可以是列表列表列表(如上所述)或DICT列表,访问方式如下:

导入plotly.graph\u对象
go.Figure(go.Bar(
x=[“a”,“b”],y=[1,2],customdata=[dict(hi=“there”),dict(hi=“here”)],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
textposition=“自动”
))
customdata
格式与Pandas的
to_dict('records')
格式兼容:

导入plotly.graph\u对象
作为pd进口熊猫
df=pd.数据帧(dict(
x=[“a”,“b”],y=[1,2],hi=[“那里”,“这里”]
))
go.Figure(go.Bar(
x=df.x,y=df.y,customdata=df[[“hi”]],
hovertemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
texttemplate=“x是%{x},y是%{y},custom1是%{customdata.hi}”,
textposition=“自动”
))

请原谅这里的无聊评论,但我是否得到了Plotly首席开发人员的赏识!?yeeeeeee!顺便说一句,你们做得很好=)很高兴你们喜欢它!我是Plotly的开发人员之一,我是data vis libraries团队的负责人,是的:)很抱歉,我们的文档不太容易理解,以至于您无法自行提供此答案…我将尝试找到一个更好的地方来更好地解释此内容。请原谅此处的轻率评论,但我是否受到Plotly首席开发人员的青睐!?yeeeeeee!顺便说一句,你们正在做的事情很好=)很高兴您喜欢它!我是Plotly的开发人员之一,我是data vis libraries团队的负责人,是的:)很抱歉,我们的文档不太容易理解,您无法自行提供此答案……我将尝试找到一个好地方更好地解释这些内容。