matplotlib-gridspec

Adjusting space between gridspec subplots for better alignment

Adjusting space between gridspec subplots for better alignment Question: 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]}, index=[‘a’, ‘b’, ‘c’]) # Dataset to emulate real data structure df …

Total answers: 2

Issue with colorbar and imshow with gridspec

Issue with colorbar and imshow with gridspec Question: I wanted to plot 2 imshow on a figure, but I only want the sub figure on the right to have the colorbar at the bottom of its plot. import matplotlib.pyplot as plt import numpy as np from matplotlib.gridspec import GridSpec cm = 1/2.54 fig = plt.figure() …

Total answers: 1

Nested gridspec alignment

Nested gridspec alignment Question: 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 square images are displayed next to 4 smaller images …

Total answers: 1

How to adjust gridspec spacing

How to adjust gridspec spacing Question: I have a matplotlib plot with 3×2 subplots. I want no spacing between the columns (achieved), and no spacing between the first (a, b) and the second row (c, d). However, the third row (e, f) should be well separated from the second, as it has different data. Additionally, …

Total answers: 1

How to use Cartopy with gridspec

How to use Cartopy with gridspec Question: I would like to create a plot with a Cartopy plot on the left-hand side and two stacked Matplotlib plots on the right-hand side. If I’d only use Matplotlib plots, the code would be as follows. import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import numpy as np …

Total answers: 1

Too much space between subplots with gridspec

Too much space between subplots with gridspec Question: I am trying to make a figure with a grid of 12 plots on the left and one larger plot on the right. The problem is that matplotlib adds far too much space between the small subplots. How can I get rid of this space? import matplotlib.pyplot …

Total answers: 2

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

Adjust space between two axes while keeping it constant on other axes Question: 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 …

Total answers: 1

How to format a shared y-axis with gridspec

How to format a shared y-axis with gridspec Question: I’m trying to fix the format for this plot: that I’m generating with "Df" data, but I’m having this cumbersome issue in which both plots are too close. The script I’m using to plot this is: #[Df,mdD,teoD,e1f,teoe1,e2f,teoe2] = [[row[i] for row in np.load(‘master_results.npy’,allow_pickle=True)[1][2:]] for i in …

Total answers: 1

Why do these image gridspec subplots have slightly different heights?

Why do these image gridspec subplots have slightly different heights? Question: 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. Here’s a minimal …

Total answers: 1

How to place a single colorbar for two gridspec subplots

How to place a single colorbar for two gridspec subplots Question: 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 …

Total answers: 1