在子图之间绘制分隔线或线条 [英] Draw a separator or lines between subplots

查看:43
本文介绍了在子图之间绘制分隔线或线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个图中绘制了四个子图,它们彼此共享 xaxis.

I have plot four subplots in one figure and they shares xaxis with each other.

但是,这些子图之间没有分隔符.我想在它们之间画一条线.或者在这些子图中是否可以采用任何分隔符?

However, there is no separator between those subplots. I want to draw a line between each of them. or is there any separator could be adopted in those subplots?

至少子图的轴之间应该有分隔符.我认为应该如下图所示.

At least there should be separator between the subplots' axis. I think it should be looked as below figure.

\ ------------------------------------

\------------------------------------

  subplot1

\ ------------------------------------

\------------------------------------

  subplot2

\------------------------------------

\------------------------------------

  ...

\------------------------------------

\------------------------------------

推荐答案

我找到了一个解决方案,但不是完美的,但对我有用.

I find a solution but not a perfect one, but works for me.

将以下代码应用于子图的每个对象.

Apply below code to each object of subplot.

其中 [-1, 1.5] 是假设覆盖图中 X 轴所有区域的值.并非都一样.

Where [-1, 1.5] are values suppose to cover all areas of X axis in figure. not all the same.

axes.plot([-1, 1.5], [0, 0], color='black', lw=1, transform=axes.transAxes, clip_on=False)
axes.plot([-1, 1.5], [1, 1], color='black', lw=1, transform=axes.transAxes, clip_on=False)

我尝试了另一种我认为是最完美的方法.如下面的代码所示.

I tried another way which I think is the most perfect way. As the code show below.

    trans = blended_transform_factory(self.figure.transFigure, axes.transAxes)
    line = Line2D([0, 1], [0, 0], color='w', transform=trans)
    self.figure.lines.append(line)

在上面的代码中,该行将从每个图形边缘的开始处开始,并且随着图形大小的变化而变化.

In above code the line would begin at the start of every figure edge, and it will change when the figure size changed.

这篇关于在子图之间绘制分隔线或线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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