我想在绘图表上显示悬停信息。这是我最好的猜测,但是在 jupyter notebook 中或当图形导出到 html 并在浏览器中查看时,没有显示悬停文本:
import plotly.graph_objects as go
hover_text = [['hover a', 'hover b', 'hover c'],
['hover d', 'hover e', 'hover f']]
fig = go.Figure(data=[go.Table(
cells={'values': [['a', 'b', 'c'],
['d', 'e', 'f']]},
hoverinfo='text',
meta={'text': hover_text}
)])
fig.show()
fig.write_html('test.html')
Run Code Online (Sandbox Code Playgroud)
情节版本 4.5.4
有许多 go.Table() 参数看起来可能是相关的,但我没有找到显示任何内容的组合:
我一直在看的一些参考资料:
我正在尝试实现一个自定义Keras层,该层将仅保留输入的前N个值,并将其余所有值转换为零。我有一个大多数版本都可以使用的版本,但是如果有联系,则可以保留超过N个值。我想使用排序函数始终只保留N个非零值。
有关系时,这是最主要的工作层,留下多个N值:
def top_n_filter_layer(input_data, n=2, tf_dtype=tf_dtype):
#### Works, but returns more than 2 values if there are ties:
values_to_keep = tf.cast(tf.nn.top_k(input_data, k=n, sorted=True).values, tf_dtype)
min_value_to_keep = tf.cast(tf.math.reduce_min(values_to_keep), tf_dtype)
mask = tf.math.greater_equal(tf.cast(input_data, tf_dtype), min_value_to_keep)
zeros = tf.zeros_like(input_data)
output = tf.where(mask, input_data, zeros)
return output
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的排序方法,但是我陷入了tf.scatter_update函数的问题,抱怨排名不匹配:
from keras.layers import Input
import tensorflow as tf
import numpy as np
tf_dtype = 'float32'
def top_n_filter_layer(input_data, n=2, tf_dtype=tf_dtype):
indices_to_keep = tf.argsort(input_data, axis=1, direction='DESCENDING', stable=True)
indices_to_keep = tf.slice(indices_to_keep, [0,0], [-1, n])
values_to_keep = tf.sort(input_data, axis=1, direction='DESCENDING') …
Run Code Online (Sandbox Code Playgroud)