damyarou

python, GMT などのプログラム

埋設水圧鉄管モデル図

2021.03.08投稿

出力事例

f:id:damyarou:20210308150556j:plain

モデル図作成

import numpy as np
import matplotlib.pyplot as plt


def atext(x1,y1,x2,y2,ss,fsz):
    col='#000000'
    sv=0
    aprop=dict(shrink=sv,width=0.3,headwidth=4,headlength=8,
               connectionstyle='arc3',facecolor=col,edgecolor=col)
    plt.annotate(ss,
        xy=(x1,y1), xycoords='data',
        xytext=(x2,y2), textcoords='data', fontsize=fsz, arrowprops=aprop, ha='center',va='center')

    
def sarrow(x1,y1,x2,y2):
    col='#0000ff'
    arst='->,head_width=3,head_length=10'
    aprop=dict(arrowstyle=arst,connectionstyle='arc3',facecolor=col,edgecolor=col,shrinkA=0,shrinkB=0,lw=2)
    plt.annotate('',
        xy=(x1,y1), xycoords='data',
        xytext=(x2,y2), textcoords='data', fontsize=0, arrowprops=aprop)

    
def crack(d0,tt,dr):
    xx1=(d0+2*tt)/2
    xx2=dr/2
    m=200
    a=0.1
    x=np.arange(xx1,xx2,0.01)
    y=a*np.sin(m*x/2/np.pi)
    angd=np.array([0,72,144,216,288])-18
    for ang in angd:
        ang=np.radians(ang)
        xc=x*np.cos(ang)-y*np.sin(ang)
        yc=x*np.sin(ang)+y*np.cos(ang)
        plt.plot(xc,yc,color='#000000',lw=1.5)

        
def parrow(r1,r2):
    ang=np.linspace(0,2*np.pi,19)
    xx1=r1*np.cos(ang)
    yy1=r1*np.sin(ang)
    xx2=r2*np.cos(ang)
    yy2=r2*np.sin(ang)
    for x1,y1,x2,y2 in zip(xx1,yy1,xx2,yy2):
        sarrow(x1,y1,x2,y2)

    
def main():
    d0=4.0      # internal diameter
    tt=0.1      # plate thickness
    dr=d0+2.0   # excavated diameter
    db=dr+2.0   # outer boundary of bedrock for drawing

    theta=np.linspace(0,2*np.pi,180)
    xb=db/2*np.cos(theta)
    yb=db/2*np.sin(theta)
    xr=dr/2*np.cos(theta)
    yr=dr/2*np.sin(theta)
    xt=(d0+2*tt)/2*np.cos(theta)
    yt=(d0+2*tt)/2*np.sin(theta)
    x0=d0/2*np.cos(theta)
    y0=d0/2*np.sin(theta)

    fsz=16
    xmin=-4; xmax=4
    ymin=-4; ymax=4

    for iii in [1,2]:
        plt.figure(figsize=(8,8),facecolor='w')
        plt.xlim([xmin,xmax])
        plt.ylim([ymin,ymax])
        #plt.grid(color='#999999',linestyle='solid')
        plt.gca().set_aspect('equal',adjustable='box')
        plt.axis('off')
        plt.fill(xb,yb,color='#dddddd',fill=None,hatch='++',lw=0)
        plt.fill(xr,yr,color='#ffc0cb')
        plt.fill(xr,yr,color='#aaaaaa',fill=None,hatch='..')
        plt.fill(xt,yt,color='#000000')
        plt.fill(x0,y0,color='#ffffff')
        crack(d0,tt,dr)

        xs=0; ys=dr/2+0.5; ss='Bedrock'
        plt.text(xs,ys,ss,color='#000000',ha='center',va='center',fontsize=fsz)    
        xs=0; ys=dr/2-0.5; ss='Concrete with\ncracks'
        plt.text(xs,ys,ss,color='#000000',ha='center',va='center',fontsize=fsz)    
        ang=np.radians(90)
        xx1=d0/2*np.cos(ang)
        yy1=d0/2*np.sin(ang)
        xx2=0
        yy2=1.0
        ss='Steel\npipe'
        atext(xx1,yy1,xx2,yy2,ss,fsz)

        al=0.5 # length of arrow for water pressure
        if iii==1:
            fnameF='fig_1.jpg'
            r1=d0/2
            r2=(d0-2*al)/2
            parrow(r1,r2)
            xs=0; ys=0; ss='Under internal\nwater pressure'
            plt.text(xs,ys,ss,color='#0000ff',ha='center',va='center',fontsize=fsz)    
        if iii==2:
            fnameF='fig_2.jpg'
            r1=(d0+2*tt)/2
            r2=(d0+2*tt+2*al)/2
            parrow(r1,r2)
            xs=0; ys=0; ss='Under external\nwater pressure\n(pipe emptied)'
            plt.text(xs,ys,ss,color='#0000ff',ha='center',va='center',fontsize=fsz)    

        plt.savefig(fnameF, dpi=100, bbox_inches="tight", pad_inches=0.1)
        plt.show()

#---------------
# Execute
#---------------
if __name__ == '__main__': main()

画像結合

from PIL import Image
#import os
#import glob


def comb_h(im1, im2):
    dst = Image.new('RGB', (im1.width + im2.width, im1.height))
    dst.paste(im1, (0, 0))
    dst.paste(im2, (im1.width, 0))
    return dst


fig_01='fig_1.jpg'; im_01 = Image.open(fig_01)
fig_02='fig_2.jpg'; im_02 = Image.open(fig_02)

fnameF='fig_3.jpg'
comb_h(im_01, im_02).save(fnameF)

以 上