加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 在matplotlib中绘制一条关联多个子图之间区域的线

发布时间:2020-12-16 21:52:18 所属栏目:Python 来源:网络整理
导读:我是一名地质学家,有一堆不同深度的钻孔. 我粗略地设定了子图的数量,宽度和高度,以根据钻孔的数量和这些钻孔中的样本数量而变化. 在每个钻孔中都有一个我想要突出显示的区域,我用axhspan完成了这个区域. 我想做的是在钻孔(子图)之间进行关联,绘制一条连接所

我是一名地质学家,有一堆不同深度的钻孔.

我粗略地设定了子图的数量,宽度和高度,以根据钻孔的数量和这些钻孔中的样本数量而变化.

在每个钻孔中都有一个我想要突出显示的区域,我用axhspan完成了这个区域.

我想做的是在钻孔(子图)之间进行关联,绘制一条连接所有钻孔区域顶部和底部的线.

我尝试过使用注释但没有取得很大进展.
我不确定如何处理这个问题,并且不胜感激.

这是一些示例代码,以及它可能产生的图片

import numpy as np
import matplotlib.pyplot as plt
from random import randint

fig = plt.figure()

Wells=np.arange(0,10,1) #number of wells to plot

for i in Wells:
    samp=randint(50,100) #number of samples in well

    dist=0.02     #space between plots
    left=0.05     #left border
    right=0.05    #right border
    base=0.05     #bottom border
    width=((1.0-(left+right))/len(Wells))     #width of subplot
    height=(1.0-base)/(100.0/samp)            #height of subplot

    #create subplots
    ax = fig.add_axes([left+(i*width)+dist,1.0-(base+height),width-dist,height])    #left,bottom,width,height of subplot

    #random data 
    x=np.random.random_integers(100,size=(samp))
    y=np.arange(0,len(x),1)

    #plot
    ax.plot(x,y,alpha=0.5)    

    #zone area of plot 
    zone=samp/2.5
    ax.axhspan(15,zone,color='k',alpha=0.2) #axis 'h' horizontal span

    #format
    ax.set_ylim(0,max(y))
    ax.set_xlim(0,max(x))
    ax.tick_params(axis='both',label1On=False,label2On=False)

plt.show()

最佳答案
您可以使用matplotlib.patches.ConnectionPatch进行此连接.

在for循环之前添加:

xys_bot = []
xys_top = []

在for循环结束时:

for i in Wells:
    #
    #...
    #
    xys_bot.append( ((x.max() - x.min())/2.,15) )
    xys_top.append( ((x.max() - x.min())/2.,zone) )
    if i > 0:
        # bottom line
        p = ConnectionPatch(xyA = xys_bot[i-1],xyB = xys_bot[i],coordsA='data',coordsB='data',axesA=fig.axes[i-1],axesB=ax,arrowstyle='-')
        ax.add_artist(p)
        # top line
        p = ConnectionPatch(xyA = xys_top[i-1],xyB = xys_top[i],arrowstyle='-')
        ax.add_artist(p)

plt.draw()
plt.show()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读