Skip to content
Advertisement

Is it possible to reduce the width of a single subplot in gridspec/Matplotlib?

I have a grid of subplots created using gridspec. I know how to create subplots that span rows and columns in gridspec. Is it possible to reduce the width of a single sub-plot just by a small amount? For example, can we set the width ratio for a single subplot? The way I want it is marked in red in the image.

enter image description here

My code looks like this:

JavaScript

What I tried:

I tried setting the width ratio as width_ratios = [1,1,1,1,0.5], but that reduces the width of the whole column (last column).

Advertisement

Answer

Thank you @JodyKlymak for mentioning about ax.set_postion method. @mozway provided a working solution, but adding these few lines in my code gave me the desired output:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement