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)
-但是我该如何使用
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屋!