plotly / plotly/plotly.js

Wrong layout when adjusting gap between positive-side violin plots.

未关闭
#7,350 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
JavaScript
星标
18.3k
派生
2k
平均合并
2 天 12 小时
30 天内合并 PR
28

描述

When showing two violin plots in the same graph, it is possible to control the size of the gap between them. If changing the plots to show only the positive side, this breaks (the top graph is placed in the wrong location and is clipped).

This works:

<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div id=id-1 class="plotly-graph-div" style="height:100%; width:100%;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script src="https://cdn.plot.ly/plotly-2.3.0.min.js"></script>
<script type="text/javascript">
window.PlotlyConfig = {MathJaxConfig: 'local'};
window.PLOTLYENV = window.PLOTLYENV || {}
if (document.getElementById('id-1')) {
    Plotly.newPlot(
        'id-1',
        [{
                "boxpoints": false,
                "type": "violin",
                "name": "Trace 1",
                "points": false,
                "box": {
                    "visible": false
                },
                "legendgroup": "Trace 1",
                "x": [0.75, 5.25, 5.5, 6.0, 6.2, 6.6, 6.8, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15, 8.15, 8.65, 8.93, 9.2, 9.5, 10.0, 10.25, 11.5, 12.0, 16.0, 20.9, 22.3, 23.25]
            },
            {
                "boxpoints": false,
                "type": "violin",
                "name": "Trace 2",
                "points": false,
                "box": {
                    "visible": false
                },
                "legendgroup": "Trace 2",
                "x": [7.9, 5.4, 7.4, 6.2, 8.5, 5.5, 8.8, 8.5, 5.1, 8.5, 5.4, 8.4, 7.8, 4.7, 8.3, 5.2, 6.2, 8.4, 5.2, 7.9, 5.1, 4.7, 7.8, 6.9, 7.4, 8.3, 5.5, 7.6, 7.8, 7.9, 7.3, 7.7, 6.6, 8.0, 7.4, 5.2, 4.8, 8.0, 5.9, 9.0, 8.0, 5.8, 8.4, 5.8, 7.3, 8.3, 6.4, 5.3, 8.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.3, 8.8, 8.0, 7.1, 8.3, 5.6, 7.9, 7.8, 8.4, 5.8, 8.3, 4.3, 6.0, 7.5, 8.1, 4.6, 9.0, 4.6, 7.4, 14.0, 15.0]
            }
        ], {
            "showlegend": false,
            "xaxis": {
                "showgrid": true,
                "gridcolor": "lightgrey",
                "showticklabels": true,
                "range": [0.75, 23.25]
            },
            "boxgroupgap": 0,
            "violingap": 0.1,
            "template": "simple_white",
            "boxgap": 0.1,
            "legend": {
                "tracegroupgap": 0,
                "itemdoubleclick": false
            },
            "yaxis": {
                "showgrid": false,
                "gridcolor": "lightgrey",
                "showticklabels": false,
                "range": [null, null]
            },
            "violingroupgap": 0,
            "margin": {
                "l": 50,
                "b": 50,
                "r": 50,
                "t": 50
            }
        }, {
            "editable": false,
            "responsive": true,
            "staticPlot": false,
            "scrollZoom": true
        },
    )
}
</script>
</body>
</html>

It shows:

Image

This fails (the only difference is adding "side":"positive", to the traces):

<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<div id=id-1 class="plotly-graph-div" style="height:100%; width:100%;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG"></script>
<script src="https://cdn.plot.ly/plotly-2.3.0.min.js"></script>
<script type="text/javascript">
window.PlotlyConfig = {MathJaxConfig: 'local'};
window.PLOTLYENV = window.PLOTLYENV || {}
if (document.getElementById('id-1')) {
    Plotly.newPlot(
        'id-1',
        [{
                "side":"positive",
                "boxpoints": false,
                "type": "violin",
                "name": "Trace 1",
                "points": false,
                "box": {
                    "visible": false
                },
                "legendgroup": "Trace 1",
                "x": [0.75, 5.25, 5.5, 6.0, 6.2, 6.6, 6.8, 7.0, 7.2, 7.5, 7.5, 7.75, 8.15, 8.15, 8.65, 8.93, 9.2, 9.5, 10.0, 10.25, 11.5, 12.0, 16.0, 20.9, 22.3, 23.25]
            },
            {
                "side":"positive",
                "boxpoints": false,
                "type": "violin",
                "name": "Trace 2",
                "points": false,
                "box": {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.1, 7.8, 6.0, 8.2, 9.1, 5.3, 7.8, 4.6, 7.7, 8.4, 4.9, 8.3, 7.1, 8.0, 4.9, 7.5, 6.4, 7.6, 5.3, 9.4, 5.5, 7.6, 5.0, 8.2, 5.4, 7.5, 7.8, 7.9, 7.8, 7.8, 7.0, 7.9, 7.0, 5.4, 8.6, 5.0, 9.0, 5.4, 5.4, 7.7, 7.9, 6.4, 7.5, 4.7, 8.6, 6.3, 8.5, 8.2, 5.7, 8.2, 6.7, 7.4, 5.4, 8.3, 7.3, 7.3, 8.8, 8.0, 7.1, 8.3, 5.6, 7.9, 7.8, 8.4, 5.8, 8.3, 4.3, 6.0, 7.5, 8.1, 4.6, 9.0, 4.6, 7.4, 14.0, 15.0]
            }
        ], {
            "showlegend": false,
            "xaxis": {
                "showgrid": true,
                "gridcolor": "lightgrey",
                "showticklabels": true,
                "range": [0.75, 23.25]
            },
            "boxgroupgap": 0,
            "violingap": 0.1,
            "template": "simple_white",
            "boxgap": 0.1,
            "legend": {
                "tracegroupgap": 0,
                "itemdoubleclick": false
            },
            "yaxis": {
                "showgrid": false,
                "gridcolor": "lightgrey",
                "showticklabels": false,
                "range": [null, null]
            },
            "violingroupgap": 0,
            "margin": {
                "l": 50,
                "b": 50,
                "r": 50,
                "t": 50
            }
        }, {
            "editable": false,
            "responsive": true,
            "staticPlot": false,
            "scrollZoom": true
        },
    )
}
</script>
</body>
</html>

It shows:

Image

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 Plotly 2.3.0 重现提供的两个 HTML 示例,比较普通小提琴图布局与使用 side="positive" 和非零 violingap 的 traces。跟踪小提琴图的布局路径,以确定上方图形为何位置错误且被裁剪;完成标准是正侧绘图保留所请求的间距,并且两个图形都在正确的位置渲染。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。