英文:
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.
答案1
得分: 0
利用标题和轴标签,以避免与现有轴冲突,twin 它们:
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([])
英文:
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([])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论