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
394
votes
6 answers

Matplotlib different size subplots

I need to add two subplots to a figure. One subplot needs to be about three times as wide as the second (same height). I accomplished this using GridSpec and the colspan argument but I would like to do this using figure so I can save to PDF. I can…
Jason Strimpel
  • 14,670
  • 21
  • 76
  • 106
12
votes
1 answer

Adjust hspace for some subplots

I have a plot in which I want to have one panel separate from other four panels. I want the rest of the four panels to share the x axis. The figure is shown below. I want the bottom four panels to have shared x-axis. I tried f =…
toylas
  • 437
  • 2
  • 6
  • 19
4
votes
2 answers

How to specify gridspec location by numbers?

I read the instruction in Customizing Location of Subplot Using GridSpec and try out the following codes and got the plot layout: import matplotlib.gridspec as gridspec gs = gridspec.GridSpec(3, 3) ax1 = plt.subplot(gs[0, :]) ax2 =…
statistics_learning
  • 427
  • 1
  • 4
  • 14
3
votes
2 answers

How to make the size of subplot equally

I am using matplotlib and GridSpec to plot 9 images in 3x3 subplots. fig = plt.figure(figsize=(30,40)) fig.patch.set_facecolor('white') gs1 = gridspec.GridSpec(3,3) gs1.update(wspace=0.05, hspace=0.05) ax1 = plt.subplot(gs1[0]) …
Jame
  • 3,746
  • 6
  • 52
  • 101
2
votes
2 answers

How can I recreate a gridspec subplot?

I need to creat a single figure with some subplots. The figure must look exactly like below: I'm having a problem to plot the second graph, I don't know how to get a "zoom" from the other graph, I was using tricks but if I use this to generate the…
Maria_
  • 31
  • 3
2
votes
0 answers

Problems with constrained_layout and suptitle with subfigures

I am trying to create a figure in pyplot with specific gridspec, but I got into a dead end. When using subfigures it is needed to use constrained_layout = True option in the figure definition, but it disables the hspace = 0 option in the GridSpec…
Galedon
  • 21
  • 3
2
votes
1 answer

Nested gridspec alignment

When using gridspecs, I find it difficult to align different nested gridspecs. I often use gridspecs for figures where most or all subplots have a fixed aspect ratio (e.g., to display images). A minimal example would be the following plot, where two…
delio
  • 23
  • 4
2
votes
1 answer

Aligning a table with title in a GridSpec

I have the following page layout with two charts up top, a map, and a table. As you can see in the result, the table title is not aligned with the Map title, and there is way too much space between bottom of Fig 1 and top of Map 1. Ideally I want…
Ilya Voytov
  • 329
  • 1
  • 9
2
votes
1 answer

How to group gridspec with nrows and ncols using a for-loop

I would like to use a for loop to iterate through to plot graphs of individual groups of gridspec plots. I define a gridspec to give me this plot: I wanted to do a for loop to repeat these plots in a given nrows, ncols. That is, I can specify to…
Joe
  • 357
  • 2
  • 10
  • 32
2
votes
1 answer

Why do these image gridspec subplots have slightly different heights?

I want to plot several images side-by-side. These images all have the same height, but different widths. I want them all to line up neatly, so the figure looks professional. Instead, the narrower image is taking up slightly less vertical space.…
2
votes
1 answer

How to place a single colorbar for two gridspec subplots

I am trying to plot 6 plots in the form of a grid using gridspec. I want one color bar placed at the bottom between the 2nd and 3rd columns. My code is as follows, but it generates 6 colorbars. How can I change this code so that it places one…
Dushi Fdz
  • 161
  • 3
  • 22
2
votes
1 answer

Plots and images on A4 with gridspec

I would like to create a summary A4 page for the results of some computations I have done. These include both images and plot in a layout like the one the code below produces. Unfortunately, matplotlib makes the images very small and the plots very…
AlexNe
  • 926
  • 6
  • 22
2
votes
2 answers

How to fully customize subplot size

I want to have two subplots in a matplotlib figure that are sized and positioned relative to each other like the example below (for stylistic reasons). All the examples I've seen for customizing subplot placement and sizes still tile and fill the…
NeutronStar
  • 2,057
  • 7
  • 31
  • 49
2
votes
2 answers

How to add a title and suptitle to each gridspec group

I know I can use update to adjust the parameters of a GridSpec instance in a matplotlib figure, allowing to arrange multiple gridspec's in a single figure. Much as in this example taken from the matplotlib doc gs1 = gridspec.GridSpec(3,…
1
vote
1 answer

How to align the left and right spines of subplots in a single column

I am trying to plot two subplots. One of them is a heatmap from seaborn library and other one is line plot from matplotlib. Line plot is showing gasoline prices through the 2022 and heatmap shows the metro line passengers through the months of the…
milikest
  • 61
  • 1
  • 9
1
2 3