[Python Ocean Topic 46] Schematic enlargement of the research area

[Python Ocean Topic 46] Schematic enlargement of the research area












































picture

Recommended in the past

picture
[Python Ocean Topic 1] View the attributes of the data nc file and output the attributes to the txt file

[Python Ocean Topic 2] Read the water depth nc file and read the water depth topographic map
[Python Ocean Topic 3] Image modification canvas and coordinate axes

[Python Ocean Topic 4] Depth Map Image Modification

[Python Ocean Topic 5] Water Depth Topography Map Coastal Filling

[Python Ocean Topic 6] Cartopy draws terrain and water depth maps

[python ocean topic]
Test Data

[Python Ocean Topic 7] Cartopy draws land filling of topographic and bathymetric maps

[Python Ocean Topic 8] Cartopy adjusts the number of contourf filling intervals for drawing topographic and bathymetric maps

[Python Ocean Topic 9] Cartopy draws terrain contour maps

[Python Ocean Topic 10] Cartopy draws terrain contour maps of specific areas

[Python Ocean Topic 11] Colormap Color Adjustment

[Python Ocean Topic 12] Annual average sea surface temperature map of the South China Sea

[Python Ocean Topic 13] Read multiple nc files to draw seasonal changes in temperature

[Python Ocean Topic 14] Read multiple salinity NC data and draw seasonal changes in salinity

[Python Ocean Topic 15] Add units to colorbar

[Python Ocean Topic 16] Proximity interpolation of data around the continent

[Python Ocean Topic Seventeen] Read decades of OHC data and draw four-season charts

[Python Ocean Topic 18] Read the Soda data and draw a subplot of the seasonal changes in sea surface height.

[Python Ocean Topic 19] Advanced version of statement to find range

[Python Ocean Topic 20] subplots_adjust layout adjustment

[Python Ocean Topic 21] subplots share a colorbar

[python ocean topic twenty-two] text on the chart

[Python Ocean Topic 23] Shared coordinate axes

[Python Ocean Topic Twenty-Four] South China Sea Annual Average Current Chart

[Python Ocean Topic Twenty-Five] Give the South China Sea annual average current + scale

[Python Ocean Topic 26] South China Sea Current Velocity Map

[Python Ocean Topic Twenty-Seven] Four Seasons Currents in the South China Sea

[Python Ocean Topic Twenty-Eight] Four Seasons Current Velocity Charts of the South China Sea

[Python Ocean Topic Twenty-Nine] Read CTD file data and draw temperature point profiles

[Python Ocean Topic 30] Draw the temperature profile of the South China Sea at 115°E

[Python Ocean Topic 31] Drawing the topographic temperature profile of 115°E in the South China Sea

[Python Ocean Topic 32] Draw the terrain temperature and velocity profile of the South China Sea at 115°E

[Python Ocean Topic Thirty-three] Draw the wind field distribution on the ocean surface

[Python Ocean Topic Thirty-four] Call your own colormore

[Python Ocean Topic Thirty-five] Encrypted Data – Two-Dimensional Interpolation

[Python Ocean Topic 36] Correlation coefficient of two one-dimensional arrays – preparing for the ocean index

[Python Ocean Topic Thirty-Seven] Ocean Index Drawing Method – Line Chart Style 1

[Python Ocean Topic 38] Ocean Index Drawing Method – Line Chart Style 2

[Python Ocean Topic Thirty-Nine] Ocean Index Drawing Method – Line Chart Style 3 – Lines of Different Colors

[Python Ocean Topic Forty] Ocean Index Drawing Method – Monochrome Fill Chart

[Python Ocean Topic 41] Ocean Index Drawing Method – Gradient Coloring Chart

[Python Ocean Topic 42] Ocean Index Drawing Method – Two-color Bar Chart

[Python Ocean Topic 43] Ocean Index Drawing Method – Monochrome Gradient Histogram

[Python Ocean Topic 44] Ocean Index Drawing Method – Multi-color Gradient Histogram

[Python Ocean Topic 45] Schematic diagram of the ocean research area

[Python Ocean Topic Ocean Index Drawing Method] Summary of Atmosphere and Ocean Index Drawing Methods

[MATLAB Ocean Topic] Historical Summary

[Matlab program] Picture graphic production||Like and share at the end of the article||Poster production, etc.

Could you please recommend some physics and ocean textbooks?

[Matlab Ocean Special Topic] Advanced Rose Chart – Wind Speed and Wind Direction Frequency Rose Chart – This picture has more details

[Thousands of color packages | Available on all platforms] Collected from Matlab, python, R, NCL and other color packages

R language_RColorBrewer package – available on all platforms

Ocean-specific cmocean color pack_22 colors in total – available on all platforms

[matlab tutorial] Peripheral filling of irregular areas in matlab

[Popular Marine Science] Sediments are divided into cohesive sediments and non-cohesive sediments

[Marine Science Popularization] Introduction to the Geography of the Yellow and Bohai Seas

[Popular Science Knowledge] Ocean Scale Maps and Interpretations

[Ocean Science Popularization] The relationship between ocean circulation and contour rock characteristics

Code sharing:

# -*- coding: utf-8 -*-

"""# Importing related function packages"""
import codecs

import cartopy.crs as ccrs
import matplotlib.ticker as mticker
import cartopy.feature as feature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from matplotlib.colors import ListedColormap
from matplotlib.patches import PathPatch
from matplotlib.path import Path
from matplotlib.transforms import TransformedBbox
from mpl_toolkits.axes_grid1.inset_locator import BboxConnector, BboxPatch
from netCDF4 import Dataset
from pylab import *
from palettable.colorbrewer.sequential import GnBu_9
import matplotlib.pyplot as plt


#Inversion of colormap colors
def reverse_colourmap(cmap, name='my_cmap_r'):
    reverse = []
    k = []
    for key in cmap._segmentdata:
        k.append(key)
        channel = cmap._segmentdata[key]
        data = []
        for t in channel:
            data.append((1 - t[0], t[2], t[1]))
        reverse.append(sorted(data))
    LinearL = dict(zip(k, reverse))
    my_cmap_r = mpl.colors.LinearSegmentedColormap(name, LinearL)
    return my_cmap_r


# Subgraph connection function
def mark_inset(parent_axes, inset_axes, loc1a, loc1b, loc2a, loc2b, **kwargs):
    rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
    pp = BboxPatch(rect, fill=False, **kwargs)
    parent_axes.add_patch(pp)
    p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1a, loc2=loc1b, **kwargs)
    inset_axes.add_patch(p1)
    p1.set_clip_on(False)
    p2 = BboxConnector(inset_axes.bbox, rect, loc1=loc2a, loc2=loc2b, **kwargs)
    inset_axes.add_patch(p2)
    p2.set_clip_on(False)
    return pp, p1, p2


"""read--my_color"""
# ----01----Read color--Subsequent use-high light red
filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\red1.txt'
file = open(filename, 'r')
lines = file.readlines()
file.close()
data1 = []
for line in lines:
    data1.append(float(line.strip()))
red = np.array(data1)
# ---01--01----shallow ----gray----
filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\gray40.txt'
file = open(filename, 'r')
lines = file.readlines()
file.close()
data1 = []
for line in lines:
    data1.append(float(line.strip()))
gray = np.array(data1)
# ---01--02----shallow ----gray----
filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\gray90.txt'
file = open(filename, 'r')
lines = file.readlines()
file.close()
data1 = []
for line in lines:
    data1.append(float(line.strip()))
gray90 = np.array(data1)
# ---01--02----shallow ----gray----
filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\gray0.txt'
file = open(filename, 'r')
lines = file.readlines()
file.close()
data1 = []
for line in lines:
    data1.append(float(line.strip()))
gray0 = np.array(data1)
# ---02---Comes with --colormap
cmap1 = GnBu_9.mpl_colormap
cmap1_r1 = reverse_colourmap(cmap1)
# ----03--My own----
# ---rear_my_color 65-53-56-49-55-
f = codecs.open("D:\matlab_work\Creation of color index table with function name colormore\colormore_txt\colormore_68.txt", mode='r') # Open the txt file
color_1, color_2, color_3 = [], [], []
for line in f.readlines()[0:]:
    a = line.split()
    a = [float(i) for i in a]
    color_1.append(a[0])
    color_2.append(a[1])
    color_3.append(a[2])
line = f.readline()
f.close()
colo = np.stack((color_1, color_2, color_3), 0)
color = np.transpose(colo)
color=np.flip(color, axis=0)
# Map rgb information to colormap
colormap1 = ListedColormap(color)
#----cmocean--topo---
# ---rear_my_color
f = codecs.open("D:\matlab_work\Creation of color index table with function name colormore\cmocean_txt\\topo.txt", mode='r') # Open the txt file
color_1, color_2, color_3 = [], [], []
for line in f.readlines()[0:]:
    a = line.split()
    a = [float(i) for i in a]
    color_1.append(a[0])
    color_2.append(a[1])
    color_3.append(a[2])
line = f.readline()
f.close()
colo = np.stack((color_1, color_2, color_3), 0)
color = np.transpose(colo)
# Map rgb information to colormap
colormap2 = ListedColormap(color)
"""ax1 frame"""
vertices = []
codes = []
codes = [Path.MOVETO] + [Path.LINETO] * 3 + [Path.CLOSEPOLY]
vertices = [(100, 0), (100, 45), (135, 45), (135, 0), (100, 0)]
# vertices = [(-80, 0), (-80, 45), (-45, 45), (-45, 0), (-80, 0)]
vertices = np.array(vertices, float)
path = Path(vertices, codes)
pathpatch = PathPatch(path, facecolor='none', edgecolor=red / 256, lw=1)
"""Read terrain data"""
a = Dataset('D:\pycharm_work\data\etopo2.nc')
lon = a.variables['lon'][:]
lat = a.variables['lat'][:]
ele = a.variables['topo'][:]
# scs and east sea of China range is lon from 100 to 130;lat from 0 to 45;
ln1 = np.where(lon >= 100)[0][0]
ln2 = np.where(lon >= 135)[0][0]
la1 = np.where(lat >= 0)[0][0]
la2 = np.where(lat >= 45)[0][0]
# # # Drawing grid
lon1 = lon[ln1:ln2]
lat1 = lat[la1:la2]
X, Y = np.meshgrid(lon1, lat1)
ele_aim = ele[la1:la2, ln1:ln2]
"""# Set map global properties"""
plt.rcParams['font.sans-serif'] = ['Times New Roman'] # Set the overall font to Times New Roman
fig = plt.figure(dpi=300, figsize=(3.5, 2), facecolor='w', edgecolor='w') # Set up a drawing board and return it to fig
"""Left picture--big area"""
ax = fig.add_axes([0.05, 0.05, 0.4, 0.95], projection=ccrs.PlateCarree())
ax.set_extent([0, 180, -90, 90], crs=ccrs.PlateCarree()) # Set the display range
ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.05, edgecolor=gray90/256) # Add coastline: keyword lw sets line width; lifestyle sets line type
ax.add_feature(feature.OCEAN)
ax.stock_img() # Add earth background
# ---tick set--
ax.set_xticks(np.arange(0, 181, 30), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90, 91, 30), crs=ccrs.PlateCarree())
ax.xaxis.set_major_formatter(LongitudeFormatter())
ax.yaxis.set_major_formatter(LatitudeFormatter())
ax.set_xticks(np.arange(0, 181, 30), crs=ccrs.PlateCarree(), minor=True)
ax.set_yticks(np.arange(-90, 91, 30), crs=ccrs.PlateCarree(), minor=True)
ax.tick_params(labelcolor=gray0/256, length=2, tickdir='in', labelsize=3)
ax.add_patch(pathpatch)
"""Right image - enlarged image"""
ax2 = fig.add_axes([0.5, 0.05, 0.4, 0.9], projection=ccrs.PlateCarree())
ax2.set_extent([100, 135, 0, 45], crs=ccrs.PlateCarree()) #Set the display range
cs = ax2.contourf(X, Y, ele_aim, levels=np.arange(-5000, 5000, 33), extend='both', cmap=colormap1,
                  transform=ccrs.PlateCarree())
cf = ax2.contour(lon, lat, ele[:, :], levels=[-3000, -1000], colors='k', linestyles='-',
                 linewidths=0.2, transform=ccrs.PlateCarree())
ax2.add_feature(feature.COASTLINE.with_scale('10m'), lw=0.5, edgecolor=gray0/256) # Add coastline: keyword lw sets line width; lifestyle sets line type
# ---tick set--
ax2.set_xticks(np.arange(100, 136, 5), crs=ccrs.PlateCarree())
ax2.set_yticks(np.arange(0, 46, 5), crs=ccrs.PlateCarree())
ax2.xaxis.set_major_formatter(LongitudeFormatter())
ax2.yaxis.set_major_formatter(LatitudeFormatter())
ax2.set_xticks(np.arange(100, 136, 5), crs=ccrs.PlateCarree(), minor=True)
ax2.set_yticks(np.arange(0, 46, 5), crs=ccrs.PlateCarree(), minor=True)
ax2.tick_params(labelcolor=gray0/256, length=2, tickdir='in', labelsize=3)
# Connect the left and right word pictures Source: https://mp.weixin.qq.com/s/2HE0pYIui96rp5wpgzGC8w
mark_inset(ax, ax2, loc1a=2, loc1b=1, loc2a=3, loc2b=4, fc='none', ec=red / 256, lw=0.5)
# ------colorbar settings
norm = mpl.colors.Normalize(vmin=-5000, vmax=5000)
position = plt.axes([0.91, 0.05, 0.03, 0.9])
cbar = fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=colormap1), cax=position, extend='both', shrink=0.2,
                    label='depth(m)',
                    ticks=np.linspace(-5000, 5000, 11), orientation='vertical')
# cbar.minorticks_on()#Minor ticks
cbar.ax.tick_params(length=2, labelsize='4', direction='in')
plt.savefig('study_area_sketch_map_046.jpg', dpi=600, bbox_inches='tight', pad_inches=0.1) # Output the map and set the border margin to be tight
plt.show()