<bdo id='LSpIQ'></bdo><ul id='LSpIQ'></ul>
<tfoot id='LSpIQ'></tfoot>

  • <legend id='LSpIQ'><style id='LSpIQ'><dir id='LSpIQ'><q id='LSpIQ'></q></dir></style></legend>
  • <small id='LSpIQ'></small><noframes id='LSpIQ'>

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

        如何隐藏绘图中的数据空白?

        时间:2023-09-30
        <legend id='risCw'><style id='risCw'><dir id='risCw'><q id='risCw'></q></dir></style></legend>
          <bdo id='risCw'></bdo><ul id='risCw'></ul>
            <tbody id='risCw'></tbody>

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

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

          • <tfoot id='risCw'></tfoot>

                1. 本文介绍了如何隐藏绘图中的数据空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的数据集可能包含较大的数据空白,我想绘制数据图表,而不是自动用空白空间填充空白.

                  I have datasets that may include large gaps in data, and I want to chart the data without plotly automatically filling in the gaps with blank space.

                  我的应用中的示例图表:

                  数据:

                  +------------+-----------+------------+
                  |    date    | responses | percentage |
                  +------------+-----------+------------+
                  | 2017-02-13 |         4 |     0.6296 |
                  | 2017-02-14 |         1 |     0.7963 |
                  | 2017-02-15 |         4 |     0.7315 |
                  | 2017-02-16 |         2 |     0.4213 |
                  | 2017-03-02 |         1 |     0.8611 |
                  | 2017-03-03 |         1 |     0.8148 |
                  | 2017-03-04 |         2 |     0.4444 |
                  +------------+-----------+------------+
                  

                  JSFiddle 替代示例: https://jsfiddle.net/4h922ca9/

                  Plotly Graph Maker 示例:https://plot.ly/create/?fid=douglas.gaskell:3

                  我怎样才能做到这一点?

                  How can I achieve this?

                  澄清一下,我并不是想用线条或条形来填补空白.我根本不希望差距存在.

                  To clarify, I am not trying to fill in the gap with a line or bar. I don't want the gap to exist at all.

                  推荐答案

                  在你的配置中使用它.

                  connectgaps: true
                  

                  我实际上是通过查看这个库的 python 版本来尝试的.

                  I actually tried this out by viewing the python version of this library.

                  Plotly :: Python Docs :: 折线图 :: Connect Data Gaps

                  var rawData = [
                    {date: new Date(2017, 01, 10), value: 5},
                    {date: new Date(2017, 01, 11), value: 6},
                    {date: new Date(2017, 01, 12), value: 8},
                    {date: new Date(2017, 01, 13), value: 13},
                    {date: new Date(2017, 01, 14), value: null}, //Null to avoid plotting the line over the gap
                    {date: new Date(2017, 01, 20), value: 12},
                    {date: new Date(2017, 01, 21), value: 14},
                    {date: new Date(2017, 01, 22), value: 8},
                    {date: new Date(2017, 01, 23), value: 9},
                    {date: new Date(2017, 01, 24), value: 11},
                    {date: new Date(2017, 01, 25), value: 8},
                    {date: new Date(2017, 01, 26), value: 6},
                    {date: new Date(2017, 01, 27), value: 7}
                  ];
                  
                  let trace1 = {
                    name: 'values',
                    type: 'scatter',
                    mode: 'lines+markers',
                    x: getData(rawData, 'date'),
                    y: getData(rawData, 'value'),
                    connectgaps: true             // <-- HERE
                  }
                  
                  Plotly.newPlot('myChart', [trace1]);
                  
                  function getData(input, propName) {
                    let output = [];
                  
                    for (let i = 0; i < input.length; i++) {
                      output.push(input[i][propName]);
                    }
                    return output;
                  }

                  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
                  <div id="myChart"></div>

                  我想解决这个问题的最佳方法是将 x 轴视为类别轴.

                  I guess the best way to approach this it to treat the x-axis like a category axis.

                  var rawData = [
                    { date: '2017-02-10', value:  5 },
                    { date: '2017-02-11', value:  6 },
                    { date: '2017-02-12', value:  8 },
                    { date: '2017-02-13', value: 13 },
                    { date: '2017-02-20', value: 12 },
                    { date: '2017-02-21', value: 14 },
                    { date: '2017-02-22', value:  8 },
                    { date: '2017-02-23', value:  9 },
                    { date: '2017-02-24', value: 11 },
                    { date: '2017-02-25', value:  8 },
                    { date: '2017-02-26', value:  6 },
                    { date: '2017-02-27', value:  7 }
                  ];
                  
                  let trace1 = {
                    name: 'values',
                    type: 'scatter',
                    mode: 'lines+markers',
                    x: getData(rawData, 'date').map((d, i) => i),
                    y: getData(rawData, 'value'),
                  }
                  
                  let layout = {
                    xaxis: {
                      title: 'Date',
                      tickvals: getData(rawData, 'date').map((d, i) => i).filter(filterEven),
                      ticktext: getData(rawData, 'date').map(d => moment(d).format('MMM DD')).filter(filterEven)
                    }
                  }
                  
                  Plotly.newPlot('myChart', [trace1], layout);
                  
                  function filterEven(v, i) { return i % 2 === 0; }
                  function getData(input, prop) { return input.map(v => v[prop]); }

                  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
                  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
                  <div id="myChart"></div>

                  这篇关于如何隐藏绘图中的数据空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:烧瓶插座 |使用 Flask Executor 或 ThreadPoolExecutor 创建的后台任务更新和绘制图表 下一篇:plotly js:如何仅在加载绘图图像后运行我的 javascript

                  相关文章

                      <bdo id='UDYR0'></bdo><ul id='UDYR0'></ul>
                  1. <tfoot id='UDYR0'></tfoot>
                  2. <legend id='UDYR0'><style id='UDYR0'><dir id='UDYR0'><q id='UDYR0'></q></dir></style></legend>
                  3. <small id='UDYR0'></small><noframes id='UDYR0'>

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