1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Python】世界地図・その右と下にグラフを描く

Last updated at Posted at 2019-05-24

論文用の画像を作るためのテンプレートのメモ.
真ん中:世界地図,右と下:緯度・経度ごとの陸地面積.

キャプチャ.PNG

若干枠線がズレるのはなぜ?

map_right_bottom.py
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec
from   mpl_toolkits.basemap import Basemap

north, south, dlat = 90.0, -60.0, 30.0
east , west , dlon = 180.0, -180.0, 60.0

def gen_axes(figWidth=10.0, rightWidth=4.0, bottomHeight=2.5):
    '''
    center|right
    ------
    bottom
    '''
    centerWidth  = figWidth - rightWidth
    centerHeight = centerWidth * (north - south) / (east - west)
    figHeight    = centerHeight + bottomHeight
    fig = plt.figure(figsize=(figWidth, figHeight))
    gs = GridSpec(2, 2,
                  width_ratios=(centerWidth,rightWidth), height_ratios=(centerHeight,bottomHeight),
                  wspace=0.0, hspace=0.0)
    return [plt.subplot(gs[0,0]), plt.subplot(gs[0,1]), plt.subplot(gs[1,0])] # center, right, bottom

def center_map(ax):
    m = Basemap(llcrnrlon=west, llcrnrlat=south, urcrnrlon=east, urcrnrlat=north, ax=ax)
    m.drawcoastlines(linewidth=.4)
    m.fillcontinents(color='0.7')
    m.drawparallels(np.arange(south+dlat,north,dlat), labels=[1,0,0,0])
    m.drawmeridians(np.arange(west +dlon,east ,dlon), labels=[0,0,1,0])
    return

def right_plot(ax, data):
    ax.plot(data, np.arange(len(data))[::-1])
    left, right = ax.get_xlim()
    left        = 0
    ax.set_xlim(left=left, right=right)
    ax.hlines(y=range(120, 720, 120), xmin=left, xmax=right, linestyles=':', linewidth=1.0)
    ax.set_ylim(0, len(data))
    ax.tick_params(left=False, right=False)
    ax.tick_params(labelleft=False, labelright=False)
    return

def bottom_plot(ax, data):
    ax.plot(data)
    ax.set_xlim(0, len(data))
    bottom, top = ax.get_ylim()
    bottom      = 0
    ax.set_ylim(top=top, bottom=bottom)
    ax.vlines(x=range(240, 1440, 240), ymin=bottom, ymax=top, linestyles=':', linewidth=1.0)
    ax.tick_params(top=False, bottom=False)
    ax.tick_params(labeltop=False, labelbottom=False)
    ax.set_facecolor((0.0, 0.0, 0.0, 0.0))


def main(*args):
    landMap = # グリッドごとの陸地面積マップ
    landMap = np.ma.masked_less_equal(landMap, 0.0)
    landLat = landMap.sum(axis=1)
    landLon = landMap.sum(axis=0)

    axs = gen_axes()

    center_map (axs[0])
    right_plot (axs[1], landLat)
    bottom_plot(axs[2], landLon)

    plt.show()

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?