How to load plolty js graph with initial zoom in 3d graph


#1

I couldn’t find a way to load a graph with some initial zoom.

I tried using the below code but it didn’t work

layout = { scene:{
xaxis: {
‘title’: ‘PC1’,
‘range’: [-4,4]
},
yaxis:{
‘title’: ‘PC2’,
‘range’: [-4,4]
},
zaxis:{
‘title’: ‘PC3’,
range: [-4,4]
}
}
}


#2

You have to add the eye property to the camera object whitin the scene object:

var layout = {
	scene: {
		xaxis: {
			‘title’: ‘PC1’
		},
		yaxis: {
			‘title’: ‘PC2’
		},
		zaxis: {
			‘title’: ‘PC3’
		},
		camera: {
			eye: {
				x: -0.16652270019457444,
				y: 0.9720157541649203,
				z: 0.6973322149538521
			}
		}
	}
}

You can get the desired eye parameters by logging them and reading the logged object:

// myDiv is the container of your Plotly instance
var myPlot = document.getElementById('myDiv');
myPlot.on('plotly_relayout', function(data){console.log(data)});