我是一名地质学家,有一堆不同深度的钻孔.
我粗略地设定了子图的数量,宽度和高度,以根据钻孔的数量和这些钻孔中的样本数量而变化.
在每个钻孔中都有一个我想要突出显示的区域,我用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进行此连接.
原文链接:https://www.f2er.com/python/439563.html在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()