Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14301

Is there a way to adjust space between subplots when layout='constrained'?

$
0
0

I'm trying to remove the vertical space between two specific axes; however plt.figure(layout='constrained') prevents matplotlib.pyplot.subplots_adjust(hspace=0).

With layout='constrained'

import matplotlib.pyplot as pltfig = plt.figure(figsize=(10, 8),layout='constrained')# fig = plt.figure(figsize=(10, 8))subfigs = fig.subfigures(2, 1)axsUp = subfigs[0].subplots(1, 3)subfigsnest = subfigs[1].subfigures(1, 2, width_ratios=[1, 2])ax = subfigsnest[0].subplots(1)axsnest = subfigsnest[1].subplots(2, 1, sharex=True)subfigsnest[1].subplots_adjust(hspace=0)plt.show()
  • Generally subplots are in place; but there is a gap between ax5 & ax6

Generally subplots are in place; but there is a gap between ax5 & ax6

Without layout='constrained'

import matplotlib.pyplot as plt# fig = plt.figure(figsize=(10, 8),layout='constrained')fig = plt.figure(figsize=(10, 8))subfigs = fig.subfigures(2, 1)axsUp = subfigs[0].subplots(1, 3)subfigsnest = subfigs[1].subfigures(1, 2, width_ratios=[1, 2])ax = subfigsnest[0].subplots(1)axsnest = subfigsnest[1].subplots(2, 1, sharex=True)subfigsnest[1].subplots_adjust(hspace=0)plt.show()
  • Desired ax5 & ax6

Desired ax5 & ax6

Using subplots_adjust(hspace=0) with layout='constrained' doesn't work and it produces the warning UserWarning: This figure was using a layout engine that is incompatible with subplots_adjust and/or tight_layout; not calling subplots_adjust..


Viewing all articles
Browse latest Browse all 14301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>