Questions tagged [matplotlib-gridspec]

For questions related to matplotlib gridspec. Gridspec specifies the geometry of the grid that a subplot will be placed. The number of rows and number of columns of the grid need to be set. Optionally, the subplot layout parameters (e.g., left, right, etc.) can be tuned.

45 questions
0
votes
0 answers

Why does applying layout="constrained" with gridspec trigger an AttributeError that doesn't occur without constrained layout?

I'm using gridspec to make a rather complicated figure layout. It works mostly fine without spacing adjustments, but some labels still overlap in the 4 subplots at top right: import matplotlib.pyplot as plt import matplotlib as mpl import…
dax
  • 45
  • 5
0
votes
1 answer

Why does adding axes to a subgridspec mess with parameter?

I have a grid with 4 subplots and 2 overlaying subplots to create common xlabels between the first two and last two subplots (see code below). I get a slightly different spacing between the 2 subplots on the left compared to the two subplots on the…
Stef M
  • 1
  • 1
0
votes
0 answers

Figure created using axes of another figure not dynamically updating axes

If you run the below code in ipython, you will find that the first window that pops up can be resized and the plots all adjust as usual. The second figure is created by trying to copy over the axis objects from the first figure. It seems to work,…
MaanDoabeDa
  • 121
  • 6
0
votes
0 answers

How to remove auto scaling in matplotlib 3D plot

There is small doubt, when I try to extend the following graph to some bigger value of x lets say x=1000 keeping all other parameter same. The graph gets shrunk in x direction but I want it to get extended along x without auto scaling so that i can…
0
votes
2 answers

Adjusting space between gridspec subplots for better alignment

I'm using matplotlib.gridspec to create a grid for 3 axes. My current code looks like: from matplotlib import pyplot as plt from matplotlib.gridspec import GridSpec import pandas as pd df = pd.DataFrame({'d1': [20,30,40], 'd2': [10,20,30]},…
Loxx
  • 111
  • 9
0
votes
1 answer

Spacing adjustment for gridspec subfigures

I wanted to change the size of hspace on my figure without using constrained_layout=True. Here is my code: import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import numpy as np fig = plt.figure() # fig =…
Mo0nKizz
  • 149
  • 7
0
votes
1 answer

Remove empty spacing between gridspec subplots

I am trying to create a plot in matplotlib with three subplots in the first column and two in the second. Using gridspec, I have managed to tweak it, but somehow there are large spacing between the different subplots in the first and second column.…
Jes
  • 130
  • 4
0
votes
2 answers

Colored background for gridspec subplots

I wanted to have a background for each subplot of my figure. In my example, I want the left side to be red and the right side to be blue. import matplotlib.pyplot as plt import numpy as np from matplotlib.gridspec import GridSpec fig =…
Mo0nKizz
  • 149
  • 7
0
votes
1 answer

Using gridspec with constrained_layout

I would like to create the following plot with Python in PyCharm: I am using the following code: import matplotlib.pyplot as plt from matplotlib.gridspec import GridSpec def format_axes(fig): for i, ax in enumerate(fig.axes): …
ab3001
  • 3
  • 2
0
votes
1 answer

Adjust space between two axes while keeping it constant on other axes

For some reason I couldn't find information on this (I'm pretty sure it exists somewhere), but in the following generic example, I would like to reduce the hspace between ax1 and ax2 while keeping the same hspace between ax2-ax3 and ax3-ax4. I'd…
0
votes
1 answer

How to add gridlines between each GridSpec subplot

I have a matplotlib gridspec plot as below: import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec fig2 = plt.figure(figsize=[8,8]) spec2 = gridspec.GridSpec(ncols=2, nrows=2, figure=fig2) f2_ax1 = fig2.add_subplot(spec2[0,…
Ailurophile
  • 2,552
  • 7
  • 21
  • 46
0
votes
1 answer

Maintain plot size of uneven subplots

I've been creating uneven subplots in matplotlib based on this question. The gridspec solution (third answer) worked a little better for me as it gives a bit more flexibility for the exact sizes of the subplots. When I add a plot of a 2D array with…
0
votes
1 answer

Copy an axis into a gridspec

I have a function that returns a fig, ax pair. However I want to put that result inside a subplot of my gridspec. fig, ax = draw_football_field(dimensions, size) # this is the output that I want to copy to another subplot fig =…
vftw
  • 1,547
  • 3
  • 22
  • 51
0
votes
1 answer

Changing the GridSpec properties after generating the subplots

Suppose something comes up in my plot that mandates that I change the height ratio between two subplots that I've generated within my plot. I've tried changing GridSpec's height ratio to no avail. import matplotlib.pyplot as plt from…
Forklift17
  • 2,245
  • 3
  • 20
  • 32
0
votes
2 answers

How can I have subplots without using axes.grid?

I am trying to attain a set of subplots that looks like the result for this code: import matplotlib.pyplot as plt import numpy as np import matplotlib.gridspec as gridspec fig = plt.figure(tight_layout=True) gs = gridspec.GridSpec(2, 2) ax =…
AoJol
  • 7
  • 1
  • 4
1 2
3