如何在matplotlib中制作空白子图? [英] How can I make a blank subplot in matplotlib?

查看:317
本文介绍了如何在matplotlib中制作空白子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matplotlib中制作了一组子图(例如3 x 2),但我的数据集少于6个.如何将其余子图留空?

I am making a group of subplot (say, 3 x 2) in matplotlib, but I have fewer than 6 datasets. How can I make the remaining subplot blank?

安排如下:

+----+----+
| 0,0| 0,1|
+----+----+
| 1,0| 1,1|
+----+----+
| 2,0| 2,1|
+----+----+

这可能会持续几页,但是在最后一页上,例如,有5个数据集,而2,1框将为空.但是,我将数字声明为:

This may go on for several pages, but on the final page, there are, for example, 5 datasets to the 2,1 box will be empty. However, I have declared the figure as:

cfig,ax = plt.subplots(3,2)

因此,在子图2,1的空间中,存在一组带有刻度和标签的默认轴.如何以编程方式使该空间空白且没有轴?

So in the space for subplot 2,1 there is a default set of axes with ticks and labels. How can I programatically render that space blank and devoid of axes?

推荐答案

您始终可以隐藏不需要的轴.例如,以下代码完全旋转第6轴:

You could always hide the axes which you do not need. For example, the following code turns of the 6-th axes completely:

import matplotlib.pyplot as plt

hf, ha = plt.subplots(3,2)
ha[-1, -1].axis('off')

plt.show()

,结果如下图:

或者,查看对问题在matplotlib图中隐藏轴文本的可接受答案一种用于保留轴但隐藏所有轴装饰(例如刻度线和标签)的方式.

Alternatively, see the accepted answer to the question Hiding axis text in matplotlib plots for a way of keeping the axes but hiding all the axes decorations (e.g. the tick marks and labels).

这篇关于如何在matplotlib中制作空白子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆