<tfoot id='MZ97L'></tfoot>
  • <legend id='MZ97L'><style id='MZ97L'><dir id='MZ97L'><q id='MZ97L'></q></dir></style></legend>

    • <bdo id='MZ97L'></bdo><ul id='MZ97L'></ul>

    <small id='MZ97L'></small><noframes id='MZ97L'>

      1. <i id='MZ97L'><tr id='MZ97L'><dt id='MZ97L'><q id='MZ97L'><span id='MZ97L'><b id='MZ97L'><form id='MZ97L'><ins id='MZ97L'></ins><ul id='MZ97L'></ul><sub id='MZ97L'></sub></form><legend id='MZ97L'></legend><bdo id='MZ97L'><pre id='MZ97L'><center id='MZ97L'></center></pre></bdo></b><th id='MZ97L'></th></span></q></dt></tr></i><div id='MZ97L'><tfoot id='MZ97L'></tfoot><dl id='MZ97L'><fieldset id='MZ97L'></fieldset></dl></div>

      2. 如何在 Plotly for Python 中悬停时突出显示整个跟踪?

        How do I highlight an entire trace upon hover in Plotly for Python?(如何在 Plotly for Python 中悬停时突出显示整个跟踪?)
        <i id='y65Wc'><tr id='y65Wc'><dt id='y65Wc'><q id='y65Wc'><span id='y65Wc'><b id='y65Wc'><form id='y65Wc'><ins id='y65Wc'></ins><ul id='y65Wc'></ul><sub id='y65Wc'></sub></form><legend id='y65Wc'></legend><bdo id='y65Wc'><pre id='y65Wc'><center id='y65Wc'></center></pre></bdo></b><th id='y65Wc'></th></span></q></dt></tr></i><div id='y65Wc'><tfoot id='y65Wc'></tfoot><dl id='y65Wc'><fieldset id='y65Wc'></fieldset></dl></div>
        1. <small id='y65Wc'></small><noframes id='y65Wc'>

                <tbody id='y65Wc'></tbody>
                <legend id='y65Wc'><style id='y65Wc'><dir id='y65Wc'><q id='y65Wc'></q></dir></style></legend>

                  <bdo id='y65Wc'></bdo><ul id='y65Wc'></ul>
                • <tfoot id='y65Wc'></tfoot>

                  本文介绍了如何在 Plotly for Python 中悬停时突出显示整个跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望在鼠标悬停选择时突出显示轨迹(颜色或不透明度变化).我研究了 restyle 功能,但它可能不适合我的用例.

                  看起来

                  解决方案

                  您可以使用 Plotly 的 FigureWidget 功能.

                  导入 plotly.graph_objs随机导入f = go.FigureWidget()f.layout.hovermode = '最近的'f.layout.hoverdistance = -1 #确保没有间隙"用于选择稀疏数据default_linewidth = 2highlight_linewidth_delta = 2# 只是一些带有随机数据点的轨迹num_of_traces = 5随机种子 = 42对于我在范围内(num_of_traces):y = [random.random() + i/2 for _ in range(100)]trace = go.Scatter(y=y, mode='lines', line={ 'width': default_linewidth })f.add_trace(跟踪)# 我们的自定义事件处理程序def update_trace(跟踪,点,选择器):# 这个列表存储了被点击的点# 除了一个痕迹之外,它们都是空的如果 len(points.point_inds) == 0:返回对于 i,_ in enumerate(f.data):f.data[i]['line']['width'] = default_linewidth + highlight_linewidth_delta * (i == points.trace_index)# 我们需要将 on_click 事件分别添加到每个跟踪对于我在范围内(len(f.data)):f.data[i].on_click(update_trace)# 让我们显示图F

                  I want a trace to be highlighted (color or opacity change) when selected with mouse hover. I have looked into restyle functionality, but it may not be appropriate for my use case.

                  It looks like this has been discussed on Github, but I'm not sure if it has been resolved/implemented.

                  Here is an example in Bokeh of what I want to accomplish in Plotly Python:

                  from bokeh.plotting import figure, show, output_notebook
                  from bokeh.models import HoverTool
                  from bokeh.models import ColumnDataSource
                  output_notebook()
                  
                  p = figure(plot_width=400, plot_height=400,y_range=(0.2,0.5))
                  
                  
                  y_vals = [0.22,0.22,0.25,0.25,0.26,0.26,0.27,0.27]
                  y_vals2 = [y*1.4 for y in y_vals]
                  x_vals = [0,1,1,2,2,2,2,3]
                  data_dict = {'x':[x_vals,x_vals],
                               'y':[y_vals,y_vals2],
                               'color':["firebrick", "navy"],
                               'alpha':[0.1, 0.1]}
                  
                  source = ColumnDataSource(data_dict)
                  
                  p.multi_line('x','y',source=source,
                               color='color', alpha='alpha', line_width=4,
                               hover_line_alpha=1.0,hover_line_color='color')
                  
                  p.add_tools(HoverTool(show_arrow=True,
                                        line_policy='nearest',
                                        ))
                  show(p)
                  

                  解决方案

                  You can use Plotly's FigureWidget functionality.

                  import plotly.graph_objs as go
                  import random
                  
                  f = go.FigureWidget()
                  f.layout.hovermode = 'closest'
                  f.layout.hoverdistance = -1 #ensures no "gaps" for selecting sparse data
                  default_linewidth = 2
                  highlighted_linewidth_delta = 2
                  
                  # just some traces with random data points  
                  num_of_traces = 5
                  random.seed = 42
                  for i in range(num_of_traces):
                      y = [random.random() + i / 2 for _ in range(100)]
                      trace = go.Scatter(y=y, mode='lines', line={ 'width': default_linewidth })
                      f.add_trace(trace)
                  
                  # our custom event handler
                  def update_trace(trace, points, selector):
                      # this list stores the points which were clicked on
                      # in all but one trace they are empty
                      if len(points.point_inds) == 0:
                          return
                          
                      for i,_ in enumerate(f.data):
                          f.data[i]['line']['width'] = default_linewidth + highlighted_linewidth_delta * (i == points.trace_index)
                  
                  
                  # we need to add the on_click event to each trace separately       
                  for i in range( len(f.data) ):
                      f.data[i].on_click(update_trace)
                  
                  # let's show the figure 
                  f
                  

                  这篇关于如何在 Plotly for Python 中悬停时突出显示整个跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                  <tfoot id='FZxgO'></tfoot>

                      <tbody id='FZxgO'></tbody>
                      <bdo id='FZxgO'></bdo><ul id='FZxgO'></ul>

                    • <small id='FZxgO'></small><noframes id='FZxgO'>

                      • <i id='FZxgO'><tr id='FZxgO'><dt id='FZxgO'><q id='FZxgO'><span id='FZxgO'><b id='FZxgO'><form id='FZxgO'><ins id='FZxgO'></ins><ul id='FZxgO'></ul><sub id='FZxgO'></sub></form><legend id='FZxgO'></legend><bdo id='FZxgO'><pre id='FZxgO'><center id='FZxgO'></center></pre></bdo></b><th id='FZxgO'></th></span></q></dt></tr></i><div id='FZxgO'><tfoot id='FZxgO'></tfoot><dl id='FZxgO'><fieldset id='FZxgO'></fieldset></dl></div>

                      • <legend id='FZxgO'><style id='FZxgO'><dir id='FZxgO'><q id='FZxgO'></q></dir></style></legend>