damyarou

python, GMT などのプログラム

matplotlib 多くの線の描画

記事の最後に行く

概要

多くの線を描画するグラフの事例。横軸は対数としている。

描画結果

f:id:damyarou:20190502005806j:plain

プログラム

import numpy as np
import matplotlib.pyplot as plt


def main():
    rpfs=np.array([2,5,10,25,50,100,200,500])
    qqfs=np.array([ 310, 428, 517, 651, 766, 935,1113,1479]) # FS-report
    rp=np.array([2,5,10,25,50,100,200,500,1000,2000,5000,10000])
    qk06=np.array([ 607, 929,1143,1424,1636,1848,2065,2355,2581,2811,3124,3367]) # HMS 6hr
    qk12=np.array([ 560, 856,1052,1308,1501,1694,1890,2154,2358,2557,2849,3069]) # HMS 12hr
    qq1a=np.array([1545,1986,2267,2625,2890,3154,3418,3772,4043,4319,4692,4981]) # Rational Equation
    qq2a=np.array([1263,1623,1852,2145,2362,2577,2793,3082,3303,3529,3834,4070]) # Nakayasu 12hr
    qq3a=np.array([1793,2304,2630,3045,3353,3659,3965,4376,4690,5011,5444,5779]) # Nakayasu 6hr
    qq1b=0.5*qq1a
    qq2b=0.5*qq2a
    qq3b=0.5*qq3a

    fsz=16
    xmin=1
    xmax=10000
    dx=1
    ymin=0
    ymax=6000
    dy=500

    plt.figure(figsize=(10,8),facecolor='w')
    plt.rcParams['font.size']=fsz
    plt.rcParams['font.family']='sans-serif'

    tstr='Flood Discharge'
    plt.xlim([xmin,xmax])
    plt.ylim([ymin,ymax])
    plt.xscale('log')
    plt.xlabel('Retuen Period (years)')
    plt.ylabel('Flood Discharge (m$^3$/s)')
    #plt.xticks(np.arange(xmin,xmax+dx,dx))
    plt.xticks([1,10,100,1000,10000],[1,10,100,1000,10000])
    plt.yticks(np.arange(ymin,ymax+dy,dy))
    plt.grid(which='both',color='#999999',linestyle='solid')
    plt.title(tstr,loc='left',fontsize=fsz)

    plt.plot(rpfs,qqfs,'d-',color='#ff0000',markersize=10,lw=2,label='FS-report')
    plt.plot(rp,qq1a,'o-',ms=10,color='#000080',markerfacecolor='#ffffff',label='Rational equation (f=0.8)',lw=1,clip_on=False)
    plt.plot(rp,qq2a,'s-',ms=10,color='#000080',markerfacecolor='#ffffff',label='Nakayasu Td=12hr (f=0.8)',lw=1,clip_on=False)
    plt.plot(rp,qq3a,'^-',ms=10,color='#000080',markerfacecolor='#ffffff',label='Nakayasu Td=6hr (f=0.8)',lw=1,clip_on=False)
    plt.plot(rp,qq1b,'o--',ms=10,color='#000080',markerfacecolor='#ffffff',label='Rational equation (f=0.4)',lw=1,clip_on=False)
    plt.plot(rp,qq2b,'s--',ms=10,color='#000080',markerfacecolor='#ffffff',label='Nakayasu Td=12hr (f=0.4)',lw=1,clip_on=False)
    plt.plot(rp,qq3b,'^--',ms=10,color='#000080',markerfacecolor='#ffffff',label='Nakayasu Td=6hr (f=0.4)',lw=1,clip_on=False)
    plt.plot(rp,qk12,'s-',color='#0000ff',markersize=10,lw=2,label='HEC-HMS Td=12hr',clip_on=False)
    plt.plot(rp,qk06,'^-',color='#0000ff',markersize=10,lw=2,label='HEC-HMS Td=6hr',clip_on=False)
    plt.legend(loc='upper left',fontsize=fsz-2)

    plt.tight_layout()
    fnameF='fig_flood_comp.jpg'
    plt.savefig(fnameF, dpi=200, bbox_inches="tight", pad_inches=0.1)
    plt.show()

    
#==============
# Execution
#==============
if __name__ == '__main__': main()

Thank you.

記事の先頭に行く