1

I am making a plot matrix using subplots in matplotlib with a shared x and y axis. What I am looking to do is label the x and y groups similar to how they are labeled in the default JMP graph maker.

In the below image, all of the blue items are what I already have, and the red items are what I am looking to add to the plot.

Example

jared
  • 4,165
  • 1
  • 8
  • 31
  • 2
    Does this answer your question? [Row and column headers in matplotlib's subplots](https://stackoverflow.com/questions/25812255/row-and-column-headers-in-matplotlibs-subplots) – Scott Boston Jul 13 '23 at 20:17
  • This is close but I was looking to get them on the right side and top. Thank you! – Kevin Daugherty Jul 14 '23 at 12:52

1 Answers1

0

Take advantage of the titles and axes labels, to avoid conflict with the existing axes, twin them:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=3, ncols=3,
                         sharex=True, sharey=True)

cols = [1, 2, 3]
rows = ['A', 'B', 'C']

for c, ax in zip(cols, axes[0]):
    ax.set_title(c)

for r, ax in zip(rows, axes[:, -1]):
    ax2 = ax.twinx()
    ax2.set_ylabel(r)
    ax2.set_yticks([])

enter image description here

mozway
  • 194,879
  • 13
  • 39
  • 75