0

This ia a mwe, with 3 subplots. My goal is to sharex for axes[0] and axes[1] only. axes[2] should have different xlim and wspace. How I can do that?

#!/usr/bin/env python
import math
import random

import matplotlib.pyplot as plt

_, axes = plt.subplots(3, 1, figsize=(20, 6), sharex=True)
plt.subplots_adjust(wspace=0.05)

x = [random.triangular() for i in range(20)]
y = [random.gauss(0.5, 0.25) for i in range(20)]
axes[0].plot(x, y, "o")
axes[1].set_xlabel("Hello")
axes[1].plot(x, y, "o")
axes[2].set_xlim([0, .5])
axes[2].plot(x, y, "o")
plt.show()
BaRud
  • 3,055
  • 7
  • 41
  • 89
  • 1
    Instead of removing the share, the usual approach is to create them without `sharex` and afterwards share specific sets of axes. See [How to share x axes of two subplots after they have been created?](https://stackoverflow.com/questions/42973223/how-to-share-x-axes-of-two-subplots-after-they-have-been-created) – JohanC Aug 07 '21 at 10:19
  • @JohanC: Thanks for your reply. This allows me to set different `xlim` on the third plot(axes[2]). But I still cant find how to set the `hspace` for `axes[2]`. (I want more space between 2nd athd 3rd row) – BaRud Aug 07 '21 at 10:39
  • See e.g. [Adjust hspace for some of the subplots](https://stackoverflow.com/questions/28820618/pylab-adjust-hspace-for-some-of-the-subplots), [How to adjust different margins between subplots](https://stackoverflow.com/questions/44734259/how-to-adjust-different-margins-between-subplots) and [Spacing between some subplots but not all](https://stackoverflow.com/questions/31484273/spacing-between-some-subplots-but-not-all) – JohanC Aug 07 '21 at 10:57

0 Answers0