0

I would like to make a 3 panel plot (three panels vertically stacked on top of each other), but with two x-axis labels, e.g. from here

The lower x-axis and top x-axis are applicable to the data in all three panels.

fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex=True,
                           gridspec_kw={'height_ratios': [7,0, 7, 3]},
                           figsize=(14.0, 16.0))

with the top panel being

ax1. and ax2. 

and

ax2 = ax1.twiny()

doesn't seem to work.

Mr. T
  • 11,960
  • 10
  • 32
  • 54
npross
  • 1,756
  • 6
  • 19
  • 38

1 Answers1

2

If you want to create 3 subplots, it would be wise not to create 4.

import matplotlib.pyplot as plt

fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True,
                           gridspec_kw={'height_ratios': [7, 7, 3]},
                           figsize=(8, 8))

ax4 = ax1.twiny()

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712