# Setting height/width of subplot

**URL:** https://community.plotly.com/t/setting-height-width-of-subplot/1861
**Category:** 📊 Plotly Python
**Created:** [August 16, 2016, 5:30pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861 "2016-08-16T17:30:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![siddharthm](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@siddharthm](https://community.plotly.com/u/siddharthm)
#### Post date: [August 16, 2016, 5:30pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/1 "2016-08-16T17:30:46Z")

</div>

I can find how to set the width/height of the figure by changing the ‘layout’ attribute. How can I set height/width of individual subplots? Is this functionality available?

---

<div class="post-metadata">

### Author: ![Adam](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adam/32/23418_2.png) [@Adam](https://community.plotly.com/u/Adam)
#### Post date: [August 16, 2016, 6:31pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/2 "2016-08-16T18:31:35Z")

</div>

Hi there,

For individual heights/widths of subplots, check out this tutorial: [https://plot.ly/python/subplots/#custom-sized-subplot](https://plot.ly/python/subplots/#custom-sized-subplot)

You need to fiddle with the xaxis/yaxis domains to get a proportion that you want.

Hope this helps!

---

<div class="post-metadata">

### Author: ![siddharthm](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@siddharthm](https://community.plotly.com/u/siddharthm)
#### Post date: [August 17, 2016, 2:54am UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/3 "2016-08-17T02:54:05Z")

</div>

Thanks Adam,  
I am able to change the xaxis/yaxis domains as per the tutorial. But it appears to be a relative size (since it normalizes to 1). What I want to be able to do is to set a size in pixels for width and height for individual subplots. this way I can ensure, the plots don’t become tiny when I am plotting 10 rows x 10 cols. I am ok with scrolling the page in my browser to see the plots. Is there a way to do that?

---

<div class="post-metadata">

### Author: ![siddharthm](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@siddharthm](https://community.plotly.com/u/siddharthm)
#### Post date: [August 17, 2016, 3:40am UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/4 "2016-08-17T03:40:19Z")

</div>

Example of what I am referring to…

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/1X/abee40cf2e9a4e4bd54ae86ca3e52db250676746.png)

---

<div class="post-metadata">

### Author: ![siddharthm](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@siddharthm](https://community.plotly.com/u/siddharthm)
#### Post date: [August 18, 2016, 3:14am UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/5 "2016-08-18T03:14:51Z")

</div>

@Adam, just checking back to see if you had any insights. If there is no way around it, it would be helpful to know 🙂

---

<div class="post-metadata">

### Author: ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)
#### Post date: [August 18, 2016, 2:32pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/7 "2016-08-18T14:32:33Z")

</div>

If you want to set width/height of subplots in pixels you first  
set the `layout.height`, `layout.width`, `layout.margin.top`, `layout.margin.bottom`,`layout.margin.left`, `layout.margin.right`, in pixels.

Then the plotting rectangle has the width =layout.width - layout.margin.left - layout.margin.right  
and the height= layout.height - layout.margin.top - layout.margin.bottom.  
In such a rectangle you set the width and height of each subplot, in pixels.

Then you define a scaling map from the rectangle  
[0, layout.width - layout.margin.left - layout.margin.right]x[0, layout.height - layout.margin.top - layout.margin.bottom] to the rectangle [0,1]x [0,1].  
This mapping let you find out the domain for the xaxis, yaxis associated to your subplots.

---

<div class="post-metadata">

### Author: ![siddharthm](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@siddharthm](https://community.plotly.com/u/siddharthm)
#### Post date: [August 18, 2016, 11:12pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/8 "2016-08-18T23:12:07Z")

</div>

Thanks @empet. This does the trick!

---

<div class="post-metadata">

### Author: ![jlbgit](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jlbgit](https://community.plotly.com/u/jlbgit)
#### Post date: [December 21, 2017, 7:35am UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/9 "2017-12-21T07:35:20Z")

</div>

Hi,  
Would anyone mind posting some small code example of how to fix a constant height for each subplot? I’m basically aiming for something as @siddharthm in [Setting height/width of subplot](https://community.plotly.com/t/setting-height-width-of-subplot/1861/3?u=jlbgit) , trying to create new (sub-)plots in [plot.ly](http://plot.ly) Dash on button click. I’ve been experimenting with `layout = go.Layout(...`, `figure.layout.update(...` and `figure['layout'][...` but I cannot get it to work properly.  
Any help would be much appreciated!  
Thanks

---

<div class="post-metadata">

### Author: ![koren88i](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@koren88i](https://community.plotly.com/u/koren88i)
#### Post date: [August 17, 2018, 10:35pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/10 "2018-08-17T22:35:33Z")

</div>

@ [siddharthm](https://community.plotly.com/u/siddharthm) can you post a snippet of your code?  
got lost with all the params here and where to put them  
I want exactly what you did - only 2 columns instead of three

---

<div class="post-metadata">

### Author: ![anil](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@anil](https://community.plotly.com/u/anil)
#### Post date: [September 21, 2018, 1:20pm UTC](https://community.plotly.com/t/setting-height-width-of-subplot/1861/11 "2018-09-21T13:20:59Z")

</div>

Hi Siddharth,

could it be possible for you to share this portion of your code.

thank you very much in advance for your help
