57 questions
0
votes
2
answers
127
views
Align yaxis label spanning two axes with yaxis labels of one axes in subplots
I have a plot with 3 subplots: the top plot is larger than the two subsequent plots. They all share the same x- and y-axis. However, the ylabel is rather long, so the ylabels of the two bottom plots ...
1
vote
2
answers
372
views
Matplotlib Gridspec with aspect ratio
I am trying to do a Gridspec with this layout:
Layout looking as it is supposed to
The lower left plot is supposed to be of equal aspect ratio. Sadly, I had to adjust the window size to get this ...
0
votes
0
answers
37
views
How to make a grid of plots that include subplots? [duplicate]
Ηi, I want to create a grid of plots that each plot has a subplot. The reason for this is that one of my columns (area1) has very high values compared to the other (area2, area3), therefore making the ...
1
vote
0
answers
29
views
GridSpec overwrites xlabels with sharex
I want a specific subplot layout and found GridSpec to have this possibility. Here, the upper chart is a bar plot of the counts per date, the left is a bar plot of the counts per variable (over dates) ...
1
vote
1
answer
117
views
How to vary subplot spacing with nested gridspecs and constrained layout?
I'm trying to make 3 pairs of subplots, with more space between the pairs. But I can't independently change the space between the pairs.
I'm using nested GridSpecs following this answer.
from ...
0
votes
1
answer
53
views
More than one color bar on plot
I am trying to plot three plots on one figure. Left two are just regular plots, but the top right one needs to be a correlation matrix with three additional colorbars, but I can't seem to get the ...
0
votes
1
answer
50
views
how to update grid parameters for figure & canvas created with matplotlib.figure & matplotlib.backends.backend_qt5agg
I need to update grid parameters (visible, which, axis, **kwargs) to customize the major and minor grid lines style. i tried using plt.grid(which='minor', linewidth=0.5, linestyle='dotted') but it did ...
2
votes
1
answer
83
views
Sharing x axis and y axis at the same time for images
I have an image that I am displaying with imshow. Then I add all the rows and show maximum values. I do the same for the columns. On the display plot, I would like to make the x and y axis of the ...
0
votes
0
answers
40
views
matplotlib pcolormesh plot with multiple axes on one figure using gridspec
Wondering if someone can help explain why the first code block runs fine, while the second code block throws this error:
> ---------------------------------------------------------------------------...
0
votes
1
answer
314
views
How can I plot a 2D image and align its projection to the axes keeping the plots dimension small compared to the image?
I am struggling finding a way to keep the projection of the image completely aligned to the image (as in the figure below) but at the same time reducing their dimension so that the image take most of ...
0
votes
1
answer
58
views
How to fit arbitrary images into subplots without changing alignment in matplotlib?
I have a code
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
def format_axes(fig):
for i, ax in enumerate(fig.axes):
ax.text(0.5, 0.5, "ax%d" % (i+1), va=&...
1
vote
2
answers
124
views
Gridspec spanning fractional column width
I'd like a plot that has two subplots in the first row, each spanning 1.5 columns, and three plots in the second row, each a column wide. Is that possible with matplotlib and gridspec? From the ...
1
vote
0
answers
63
views
How to adjust colorbar height in Gridspec subplots
How can I produce 1x15 subplots where the first and second columns are filled contour and the third column will have two stacked horizontal line plots in each of the rows?
The code below is an example ...
0
votes
1
answer
103
views
How to create subplots using Gridspec
How can I produce 3x3 subplots where the first and second columns are filled contour and the third column will have two stacked horizontal line plots in each of the rows?
This is the kind of layout (...
1
vote
1
answer
307
views
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 ...
1
vote
0
answers
706
views
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 ...
2
votes
2
answers
103
views
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 ...
0
votes
1
answer
339
views
Why does adding axes to a subgridspec mess with <wspace> 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 ...
0
votes
0
answers
37
views
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 ...
1
vote
1
answer
548
views
How to add the colormap to the matplotlib 3d plot
I want to add the colormap to show the gradient along x axis but unfortunately the whole figure turns black. I might be lacking something kindly help me in this. Here is the code.
import matplotlib....
0
votes
2
answers
319
views
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....
0
votes
1
answer
177
views
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
...
0
votes
1
answer
284
views
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 ...
1
vote
2
answers
509
views
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 ...
1
vote
1
answer
315
views
Issue with colorbar and imshow with gridspec
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....
2
votes
0
answers
217
views
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 ...
2
votes
1
answer
770
views
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 ...
2
votes
1
answer
481
views
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 ...
1
vote
1
answer
5k
views
How to adjust gridspec spacing
I have a matplotlib plot with 3x2 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 ...
1
vote
1
answer
725
views
How do I get subplot and GridSpec to position and size subplots?
I am trying to create a figure with 2x10 subplots. I would like them all to be square with a thin white space in between them, but they are coming out as rectangles (longer in height than width). The ...
2
votes
1
answer
746
views
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 ...
1
vote
1
answer
2k
views
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 ...
2
votes
1
answer
886
views
How to use Cartopy with gridspec
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 ...
1
vote
1
answer
282
views
Retain square layout with GridSpec
How do I align the GridSpec to look like this?
|‾ ‾ ‾ ‾| |‾ ‾| |‾ ‾|
| | |_ _| |_ _|
| | |‾ ‾| |‾ ‾|
|_ _ _ _| |_ _| |_ _|
I have tried the following:
import matplotlib.pyplot as ...
1
vote
2
answers
918
views
Too much space between subplots with gridspec
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 ...
0
votes
1
answer
174
views
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 ...
0
votes
1
answer
878
views
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=...
1
vote
1
answer
205
views
How to format a shared y-axis with gridspec
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:
...
2
votes
1
answer
717
views
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 ...
0
votes
1
answer
792
views
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 ...
4
votes
1
answer
2k
views
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 ...
1
vote
1
answer
355
views
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 ...
2
votes
1
answer
6k
views
How to plot images in subplots
Suppose I have 3 directories of .jpg files: dataset 1, dataset 2, dataset 3.
I would like to make a 5 by 3 subplots using matplotlib. For each row, the subplot shows the data from dataset 1, dataset 2 ...
1
vote
1
answer
566
views
Automatically get the dimensions or indices of gridspec axes
Given a gridspec object in matplotlib, I want to automatically iterate through all its indices so I can add the corresponding Axes automatically, something like:
for i, j in gspec.indices: # whatever ...
3
votes
2
answers
1k
views
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.
...
1
vote
1
answer
295
views
How to create a twin axes with gridspec
I am using two GridSpec objects to generate the following plot:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import figaspect
plt.rcParams.update({'figure.figsize' : (10,...
1
vote
2
answers
722
views
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(...
1
vote
1
answer
207
views
How to specify subplots layout with gridspec
I'm trying to use plt.GridSpec() to set up two subplots such that the left one takes up about 67% of the space and the right one takes up 33%.
I looked at the documentation, but I just can't seem to ...
3
votes
1
answer
3k
views
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, ...
3
votes
2
answers
1k
views
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....