Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matplotlib中的多个子图之间绘制一条关联区域的线_Python_Matplotlib - Fatal编程技术网

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

Python 在matplotlib中的多个子图之间绘制一条关联区域的线,python,matplotlib,Python,Matplotlib,我是一名地质学家,有很多不同深度的钻孔 我粗略地设置了子地块的数量、宽度和高度,以根据钻孔的数量和这些钻孔中的样本数量而变化 在每个钻孔中都有一个我想强调的区域,这是我用axhspan完成的 我想做的是在钻孔(子地块)之间进行关联,画一条线连接所有钻孔中所有分区区域的顶部和底部 我尝试过使用annotate,但进展不大。 我真的不知道如何处理这个问题,如果有任何建议,我将不胜感激 下面是一些示例代码,以及它可能产生的图片 import numpy as np import matplotlib.

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

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

在每个钻孔中都有一个我想强调的区域,这是我用axhspan完成的

我想做的是在钻孔(子地块)之间进行关联,画一条线连接所有钻孔中所有分区区域的顶部和底部

我尝试过使用annotate,但进展不大。 我真的不知道如何处理这个问题,如果有任何建议,我将不胜感激

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

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 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],
               coordsA='data', coordsB='data',
               axesA=fig.axes[i-1], axesB=ax,
               arrowstyle='-')
        ax.add_artist(p)

plt.draw()
plt.show()
for
循环的末尾:

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],
               coordsA='data', coordsB='data',
               axesA=fig.axes[i-1], axesB=ax,
               arrowstyle='-')
        ax.add_artist(p)

plt.draw()
plt.show()

你好。我没有时间给出更完整的答案,但这个例子可能会为您指明正确的方向:请参阅。