您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

5b51 2022/1/14 8:20:44 python 字数 3128 阅读 455 来源 www.jb51.cc/python

我是一名地质学家,有一堆不同深度的钻孔.我粗略地设定了子图的数量,宽度和高度,以根据钻孔的数量和这些钻孔中的样本数量而变化.在每个钻孔中都有一个我想要突出显示的区域,我用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()

xys_bot = []
xys_top = []

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()

总结

以上是编程之家为你收集整理的python – 在matplotlib中绘制一条关联多个子图之间区域的线全部内容,希望文章能够帮你解决python – 在matplotlib中绘制一条关联多个子图之间区域的线所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶