Open
Description
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.2, 5.9, 7.5, 9.0, 5.4, 8.0, 5.4, 8.3, 7.1, 6.4, 7.7, 8.1, 5.9, 8.4, 4.8, 8.2, 6.0, 9.2, 7.8, 7.8, 6.5, 7.3, 8.2, 5.6, 7.9, 7.1, 6.2, 7.6, 6.0, 7.8, 7.6, 8.3, 7.5, 8.2, 7.0,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]
},
"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](https://private-user-images.githubusercontent.com/68190/408010249-1dfb34cb-e17d-4bdd-b392-2fbb7f79746f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMDc5MzksIm5iZiI6MTczOTEwNzYzOSwicGF0aCI6Ii82ODE5MC80MDgwMTAyNDktMWRmYjM0Y2ItZTE3ZC00YmRkLWIzOTItMmZiYjdmNzk3NDZmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDEzMjcxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE0NjhjNjdjMjkyYWJmYjZhNjIwZjRmNGFmNWJiZDQ0YTZkN2FkOTFjMmM4NTYzMzU4M2E3ZDA3MjZkNTIzODYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.gCNau5tQc_HcZXBScA3txgLxF0IWPmmwnEXyA3C-5Us)
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": {
"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.2, 5.9, 7.5, 9.0, 5.4, 8.0, 5.4, 8.3, 7.1, 6.4, 7.7, 8.1, 5.9, 8.4, 4.8, 8.2, 6.0, 9.2, 7.8, 7.8, 6.5, 7.3, 8.2, 5.6, 7.9, 7.1, 6.2, 7.6, 6.0, 7.8, 7.6, 8.3, 7.5, 8.2, 7.0, 6.5, 7.3, 8.8, 7.6, 8.0, 4.8, 8.6, 6.0, 9.0, 5.0, 7.8, 6.3, 7.2, 8.4, 7.5, 5.1, 8.2, 6.2, 8.8, 4.9, 8.3, 8.1, 4.7, 8.4, 5.2, 8.6, 8.1, 7.5, 5.9, 8.9, 7.9, 5.9, 8.1, 5.0, 8.5, 5.9, 8.7, 5.3, 6.9, 7.7, 5.6, 8.8, 8.1, 4.5, 8.2, 5.5, 9.0, 4.5, 8.3, 5.6, 8.9, 4.6, 8.2, 5.1, 8.6, 5.3, 7.9, 8.1, 6.0, 8.2, 7.7, 7.6, 5.9, 8.0, 4.9, 9.6, 5.3, 7.7, 7.7, 6.5, 8.1, 7.1, 7.0, 8.1, 9.3, 5.3, 8.9, 4.5, 8.6, 5.8, 7.8, 6.6, 7.6, 6.3, 8.8, 5.2, 9.3, 4.9, 5.7, 7.7, 6.8, 8.1, 8.1, 7.3, 5.0, 8.5, 7.4, 5.5, 7.7, 8.3, 8.3, 5.1, 7.8, 8.4, 4.6, 8.3, 5.5, 8.1, 5.7, 7.6, 8.4, 7.7, 8.1, 8.7, 7.7, 5.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](https://private-user-images.githubusercontent.com/68190/408010427-c5c0613f-4af1-45ec-b8ba-d2cc4ce1430f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMDc5MzksIm5iZiI6MTczOTEwNzYzOSwicGF0aCI6Ii82ODE5MC80MDgwMTA0MjctYzVjMDYxM2YtNGFmMS00NWVjLWI4YmEtZDJjYzRjZTE0MzBmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDEzMjcxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1NzE4NTY2YTNiMjEzYjliODg2NjNiMjkwZmZiM2UzOTVjY2I3MmRhZWZiNTlkZWQzYjAwYjdiZWU3YmM3NmYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.hwjhZ03mKTeMtzlZuLANmjdMy-Jvs4dityQjpFZRAYE)