matplotlib 子图的通用 xlabel/ylabel [英] Common xlabel/ylabel for matplotlib subplots
问题描述
我有以下情节:
fig,ax = plt.subplots(5,2,sharex=True,sharey=True,figsize=fig_size)
现在我想给这个图提供通用的 x 轴标签和 y 轴标签.对于common",我的意思是在整个子图网格下方应该有一个大的 x 轴标签,在右侧应该有一个大的 y 轴标签.我在 plt.subplots
的文档中找不到任何关于此的内容,我的谷歌搜索表明我需要制作一个大的 plt.subplot(111)
开始- 但是我如何使用 plt.subplots
将我的 5*2 子图放入其中?
and now I would like to give this plot common x-axis labels and y-axis labels. With "common", I mean that there should be one big x-axis label below the whole grid of subplots, and one big y-axis label to the right. I can't find anything about this in the documentation for plt.subplots
, and my googlings suggest that I need to make a big plt.subplot(111)
to start with - but how do I then put my 5*2 subplots into that using plt.subplots
?
推荐答案
这看起来像您真正想要的.它将此答案的相同方法应用于您的具体情况:
This looks like what you actually want. It applies the same approach of this answer to your specific case:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=3, ncols=3, sharex=True, sharey=True, figsize=(6, 6))
fig.text(0.5, 0.04, 'common X', ha='center')
fig.text(0.04, 0.5, 'common Y', va='center', rotation='vertical')
这篇关于matplotlib 子图的通用 xlabel/ylabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!