如何設定默認縮放級別并將繪圖以原點 (0,0) 為中心?在 react-plotly 中,我不確定布局物件中的哪些選項對此負責。
import React from 'react';
import Plot from 'react-plotly.js';
export default function App() {
var layout = {
shapes: [
{
type: 'circle',
xref: 'x',
yref: 'y',
x0: -2,
y0: -1.56,
x1: 2,
y1: 2.09,
opacity: 0.2,
fillcolor: 'red',
line: {
color: 'red'
}
}
],
height: 400,
width: 480,
showlegend: false,
dragmode: 'pan'
}
return (
<Plot
layout={layout}
/>
);
}
uj5u.com熱心網友回復:
定義 x 和 y 軸并使用constraintoward: "center". range請注意,如果資料不是靜態的,您可能需要從資料中推斷出每個內部的最大值和最小值:
import React from "react";
import Plot from "react-plotly.js";
export default function App() {
var layout = {
shapes: [
{
type: "circle",
xref: "x",
yref: "y",
x0: -2,
y0: -1.56,
x1: 2,
y1: 2.09,
opacity: 0.2,
fillcolor: "red",
line: {
color: "red",
},
},
],
yaxis: {
visible: true,
constraintoward: "center",
showticklabels: false,
range: [-10, 10],
},
xaxis: {
visible: true,
constraintoward: "center",
showticklabels: false,
range: [-10, 10],
},
height: 400,
width: 480,
showlegend: false,
dragmode: "pan",
};
return <Plot layout={layout} />;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/527794.html
