# PlotlyJS: how to change the aspect ratio of a 3D plot

**URL:** <https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [August 21, 2021, 3:35pm UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779 "2021-08-21T15:35:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [August 21, 2021, 3:35pm UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/1 "2021-08-21T15:35:43Z")

</div>

I have tried to change the aspect ratio of a typical 3D plot using PlotlyJS. I searched but found no helpful answer to my problem.

The MWE below produces a tall and thin cube with the surface in. I want to change the aspect ratio of the x,y,z-axis. I need the x,y-axis to be wider like the PGFPlotsX plot displayed below. I tried many ways but had no success. By the way, in PlotlyJS, how can I get rid of the colorbar if I want to? Thanks.

MWE

```julia
using PlotlyJS
K1 = LinRange(0.0, 10.0, 100);
L1 = LinRange(0.0, 10.0, 100);
	
Quant = 2 .*(K1.^(0.4) .* (L1.^(0.6))')
	
trace3_5 = surface(x = K1, y = L1, z = Quant)
		
layout3_5 = Layout(#font_size = 13, 
		hovermode="x",	
	   	title_text="A standard production function", 
		title_x =0.5,
	   	titlefont_size="18",
		layout_scene = "cube",
		cube=(x=3, y=3, z=1),		
		#width=1000, height=400,
		colorbar = false) 
		
p3_5 = Plot([trace3_5], layout3_5)

```

PGFPlotsX type of plot I need:

 ![a1](https://global.discourse-cdn.com/julialang/original/3X/d/9/d9e864e1a71f88d9ee97f1b0308bda0418b43b4d.jpeg)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 22, 2021, 5:14am UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/2 "2021-08-22T05:14:37Z")

</div>

Have you tried [this post’s solution](https://discourse.julialang.org/t/scale-z-plot3d/58953/3)?

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [August 22, 2021, 7:17am UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/3 "2021-08-22T07:17:19Z")

</div>

@rafael.guerra’s suggestion is the right one, but you have to remove a few layout settings in your code, because they are ineffective

```julia
layout_scene = "cube",
cube=(x=3, y=3, z=1),	

```

To view the surface as in your attached image, it must be rotated:

```julia
using PlotlyJS
K1 = LinRange(0.0, 10.0, 100);
L1 = LinRange(0.0, 10.0, 100);

Quant = 2 .*(K1.^(0.4) .* (L1.^(0.6))')

trace3_5 = surface(x = -L1, 
                    y = K1,  
                    z = Quant,  
                    showscale=false) #The surface is rotated with pi/2 
                                     #about z-axis

layout3_5 = Layout( 
            width=1000, height=800,
            title_text="A standard production function",
            title_x =0.5,
            titlefont_size="18",
            scene_aspectratio=attr(x=1, y=1, z=0.5))
p3_5 = Plot([trace3_5], layout3_5)

```

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [August 22, 2021, 10:19am UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/4 "2021-08-22T10:19:25Z")

</div>

@rafael.guerra , @empet, thank you very much.

The mess I had inside the Layout settings displayed my unfortunate tries to follow the information in the Plotly documentation. It is perfect for my needs.

Thanks to @rafael.guerra for pointing out a link where there was a solution, and thanks to @empet for providing the solution.

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [August 22, 2021, 11:05am UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/5 "2021-08-22T11:05:05Z")

</div>

Hi @empet,

Sorry for bothering you again with this 3D plot thing. I forgot to ask how to change the (x,y,z) axis titles. In the 2D case `yaxis_title = "Capital (K)"`, ` xaxis_title = "Labor (L)"` work, but in the 3D they don’t.

```julia
layout3_5 = Layout( 
                width=800, height=500,
                title_text="A standard production function",
	            yaxis_title = "Capital (K)",
		        xaxis_title = "Labor (L)",
		        zaxis_title = "Output (Q)",		
                title_x =0.5,
                titlefont_size="18",
                scene_aspectratio=attr(x=1, y=1, z=0.5))

```

I looked into the Plotly documentation and found the settings below. However, I tried but had no success adapting it to PlotlyJS. Thanks.

```julia
fig.update_layout(scene = dict(
                    xaxis_title='X AXIS TITLE',
                    yaxis_title='Y AXIS TITLE',
                    zaxis_title='Z AXIS TITLE'),
                    width=700,
                    margin=dict(r=20, b=10, l=10, t=10))

```

---

<div class="post-metadata">

**Author:** ![VivMendes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivmendes/32/16477_2.png) [@VivMendes](https://discourse.julialang.org/u/VivMendes)\
**Post date:** [August 22, 2021, 11:09am UTC](https://discourse.julialang.org/t/plotlyjs-how-to-change-the-aspect-ratio-of-a-3d-plot/66779/6 "2021-08-22T11:09:31Z")

</div>

@empet, I have done it. Thanks.

Edited: In case anyone needs this information, here is how I have done it:

```julia
layout3 = Layout( 
            width=800, height=500,
			scene = attr(
                    xaxis_title="K",
                    yaxis_title="L",
                    zaxis_title="Q"),	
            title_x =0.5,
            titlefont_size="18",
            scene_aspectratio=attr(x=1, y=1, z=0.5))

```
