如何在matplotlib绘图中向子图添加X和Y组标签?

huangapple go评论91阅读模式
英文:

How to add X and Y group labels to subplots in a matplotlib plot?

问题

在Matplotlib中,我正在使用子图制作一个具有共享x和y轴的图表矩阵。我想要做的是类似于默认的JMP图表制作工具中对x和y组进行标注。

在下面的图片中,所有蓝色项目是我已经有的,红色项目是我想要添加到图表中的内容。

英文:

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.

如何在matplotlib绘图中向子图添加X和Y组标签?

答案1

得分: 0

利用标题和轴标签,以避免与现有轴冲突,twin 它们:

  1. import matplotlib.pyplot as plt
  2. fig, axes = plt.subplots(nrows=3, ncols=3,
  3. sharex=True, sharey=True)
  4. cols = [1, 2, 3]
  5. rows = ['A', 'B', 'C']
  6. for c, ax in zip(cols, axes[0]):
  7. ax.set_title(c)
  8. for r, ax in zip(rows, axes[:, -1]):
  9. ax2 = ax.twinx()
  10. ax2.set_ylabel(r)
  11. ax2.set_yticks([])

如何在matplotlib绘图中向子图添加X和Y组标签?

英文:

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

  1. import matplotlib.pyplot as plt
  2. fig, axes = plt.subplots(nrows=3, ncols=3,
  3. sharex=True, sharey=True)
  4. cols = [1, 2, 3]
  5. rows = ['A', 'B', 'C']
  6. for c, ax in zip(cols, axes[0]):
  7. ax.set_title(c)
  8. for r, ax in zip(rows, axes[:, -1]):
  9. ax2 = ax.twinx()
  10. ax2.set_ylabel(r)
  11. ax2.set_yticks([])

如何在matplotlib绘图中向子图添加X和Y组标签?

huangapple
  • 本文由 发表于 2023年7月14日 04:12:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定