admin管理员组文章数量:1334825
How can you show from 0,0 (or the lowest negative point) to 8,8 (or the highest data point) on the chart x,y while also showing the full chart?
var data = [
{
x: [3, 4, 5, 6, 7, 8],
y: [3, 4, 5, 6, 7, 8],
type: 'scatter'
}
];
var layout = {
// autosize: true,
// rangemode: "tozero",
width: 500,
height: 500,
autoscale: false,
xaxis: { autorange: false },
yaxis: { autorange: false },
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
If you enable autorange it shows the data, but not 0,0.
If you disable autorange it shows 0,0 but not the data.
Here is a working demo:
How can you show from 0,0 (or the lowest negative point) to 8,8 (or the highest data point) on the chart x,y while also showing the full chart?
var data = [
{
x: [3, 4, 5, 6, 7, 8],
y: [3, 4, 5, 6, 7, 8],
type: 'scatter'
}
];
var layout = {
// autosize: true,
// rangemode: "tozero",
width: 500,
height: 500,
autoscale: false,
xaxis: { autorange: false },
yaxis: { autorange: false },
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
If you enable autorange it shows the data, but not 0,0.
If you disable autorange it shows 0,0 but not the data.
Here is a working demo: https://codepen.io/Xeoncross/pen/MRREXq
Share Improve this question asked Apr 29, 2019 at 17:14 XeoncrossXeoncross 57.3k83 gold badges271 silver badges371 bronze badges2 Answers
Reset to default 4Your data is all there and showing it is just "hidden" because of the default zoom level. If you want all of the data points to show at once by default you can set a range in your x and y axis.
Also, setting a range will not affect your zooming in future uses.
Basically you can set the range min and max to be 0 and your highest value.
xaxis: { autorange: false, range:[0, 10]},
yaxis: { autorange: false, range:[0, 10]},
In the following snippet I made two variables to track the x and y max and add 2. This will ensure there is a buffer of 2 on the top to show all of the data points.
var data = [
{
x: [3, 4, 5, 6, 7, 8],
y: [3, 4, 5, 6, 7, 8],
type: 'scatter'
}
];
var xMax = data[0].x[data[0].x.length - 1] + 2;
var yMax = data[0].y[data[0].y.length - 1] + 2;
var layout = {
// autosize: true,
// rangemode: "tozero",
width: 500,
height: 500,
autoscale: false,
xaxis: { autorange: false, range:[0, xMax]},
yaxis: { autorange: false, range:[0, yMax]},
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- jquery -->
<script src="//cdnjs.cloudflare./ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv"></div>
</body>
You can just set the rangemode
to 'tozero'
and enable autorange
for each axis:
var data = [
{
x: [3, 4, 5, 6, 7, 8],
y: [3, 4, 5, 6, 7, 8],
type: 'scatter'
}
];
var layout = {
width: 500,
height: 500,
autoscale: false,
xaxis: { rangemode:'tozero', autorange:true},
yaxis: { rangemode:'tozero', autorange:true}
};
Plotly.newPlot('myDiv', data, layout, {showSendToCloud: true});
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<!-- jquery -->
<script src="//cdnjs.cloudflare./ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv"></div>
</body>
See the official Plotly examples.
本文标签: javascriptShow full axis range for Plotly chartStack Overflow
版权声明:本文标题:javascript - Show full axis range for Plotly chart? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742346273a2457583.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论