0

my interrogation is the following :

I have a code that generates a plot using :

fig = plt.figure( figsize=(6.5,10))
ax = fig.gca()

enter image description here

I've used this routine to generate multiple plots. Is there a simple way to make the plot look like : enter image description here

I know there is a command plt.subplots but I dont know how to place each plots in this configuration. Any help would be greatly appreciated

1
  • fig, axes = plt.subplots(1, 5)? Commented Jul 11, 2022 at 13:37

1 Answer 1

1

gridspec is your friend here:

import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec 

fig = plt.figure(figsize=(18,8))

gs = gridspec.GridSpec(1, 5)

ax1 = fig.add_subplot(gs[0])
ax2 = fig.add_subplot(gs[1])
ax3 = fig.add_subplot(gs[2])
ax4 = fig.add_subplot(gs[3])
ax5 = fig.add_subplot(gs[4])

plt.subplots_adjust(wspace=0)
ax2.set_yticks([])
ax3.set_yticks([])
ax4.set_yticks([])
ax5.set_yticks([])
Sign up to request clarification or add additional context in comments.

3 Comments

Hi, i've tried your suggestion. I obtain a plot that looks like the one I've put in the description of the problem, however the leftside of one is not the right side of the other ( there is a gap=, do you see a way to do that ?
plt.subplots_adjust(wspace=0)?
@DavidG is right - edited my answer to add that and removed yticks since that would probably make sense for this type of plot too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.