[Python Ocean Topic 38] Ocean Index Drawing Method – Line Chart Style 2
Data: AMO_index
Image display:
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 in 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
[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] Geography of the Yellow and Bohai Sea
[Popular Science Knowledge] Ocean Scale Maps and Interpretations
[Ocean Science Popularization] The relationship between ocean circulation and contour rock characteristics
Code sharing:
"""# ----01 Import function package-----""" import matplotlib import codecs import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from matplotlib.colors import ListedColormap, BoundaryNorm '''# ----02----Define function--used to distinguish points above and below y=0----''' def threshold_plot(ax, x, y, threshv, color, overcolor): cmap = ListedColormap([color, overcolor]) norm = BoundaryNorm([np.min(y), threshv, np.max(y)], cmap.N) points = np.array([x, y]).T.reshape(-1, 1, 2) segments = np.concatenate([points[:-1], points[1:]], axis=1) lc = LineCollection(segments, cmap=cmap, norm=norm) lc.set_array(y) ax.add_collection(lc) ax.set_xlim(np.min(x), np.max(x)) ax.set_ylim(np.min(y) * 1.1, np.max(y) * 1.1) return lc '''# ----03----Read index file----''' f = codecs.open("D:\pycharm_work\program\90_read_ocean_index_and_plot\amo_index.txt", mode='r') #Open txt file year = []; amo_moth_1 = [] for line in f.readlines()[28:]: a = line.split() a = [float(i) for i in a] year.append(a[0]) # Add it to year amo_moth_1.append(a[1]) # Add it to the list line = f.readline() f.close() '''# 02-1 Convert list to np, you can draw pictures. Array;''' b = [] for i in range(len(year)): b.append(np.array(year[i])) year = np.array(b) b = [] for i in range(len(amo_moth_1)): b.append(np.array(amo_moth_1[i])) amo_moth_1 = np.array(b) # ----Data processing----Remove missing value---- amo_moth_1[amo_moth_1 < - 999] = 0 '''# Drawing''' # ----01----Read color--Subsequent use-shallow_blue---cornflowerblue filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\deepskyblue.txt' file = open(filename, 'r') lines = file.readlines() file.close() data1 = [] for line in lines: data1.append(float(line.strip())) cornflowerblue = np.array(data1) # ----01-1----shallow_red--- filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\brown1.txt' file = open(filename, 'r') lines = file.readlines() file.close() data2 = [] for line in lines: data2.append(float(line.strip())) brown = np.array(data2) # ----01-2----shallow_black--- filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\lavenderblush4.txt' file = open(filename, 'r') lines = file.readlines() file.close() data2 = [] for line in lines: data2.append(float(line.strip())) black = np.array(data2) # ----01-2----shallow_black--- filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\gray10.txt' file = open(filename, 'r') lines = file.readlines() file.close() data2 = [] for line in lines: data2.append(float(line.strip())) gray70 = np.array(data2) # ----01-4----shallow_black--- filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\gray75.txt' file = open(filename, 'r') lines = file.readlines() file.close() data2 = [] for line in lines: data2.append(float(line.strip())) gray90 = np.array(data2) # ----02----Chinese font setting---- matplotlib.rc("font", family='Microsoft YaHei', weight="bold") # Create graphics and axis objects # Resolution parameter-dpi, canvas size parameter-figsize fig, ax = plt.subplots(dpi=300, figsize=(3.8, 2.3)) # ----03----Draw a line chart of an array--color setting ax.plot(year, amo_moth_1, color=black / 256, marker='.', linestyle='-', linewidth=0.7, markersize=1) plt.axhline(y=0.0, color=gray90 / 256, linestyle='--', lw=0.5, zorder=0) # y=0 # ----04----Draw a scatter plot of an array--color setting--- ax.scatter(year, amo_moth_1, s=0.3, color=gray70 / 256, zorder=2) # ----05----Set the scatter point dispersion--set it in different colors above and below y=0. --- below_threshold = amo_moth_1 < 0 ax.scatter(year[below_threshold], amo_moth_1[below_threshold], s=3, color=cornflowerblue / 256, zorder=1) # ----Add above threshold markers above_threshold = np.logical_not(below_threshold) ax.scatter(year[above_threshold], amo_moth_1[above_threshold], s=3, color=brown / 256, zorder=1) # ----04----Set axis label Label setting font size setting--axis range limit--- plt.xlabel('year', fontsize=5) plt.ylabel('AMO(index)', fontsize=5) plt.title('AMO(index)', fontsize=5) plt.xlim(1900, 2020) plt.ylim(-1, 1) # ----05----Scale setting and scale value font size (set x-axis and y-axis respectively) plt.yticks(np.linspace(-1, 1, 5), fontsize=5, color='#000000') plt.xticks([1900, 1910, 1920, 1930, 1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020], fontsize=5, color='#000000') ax.tick_params("both", which='major', length=2, width=1.0, colors='k', direction='in') # "y", \ 'x', 'both' # ----06----Save image plt.savefig('amo_index_plot_scatter_0.jpg', dpi=600, bbox_inches='tight', pad_inches=0.1) # Output the map and set the border margin to be tight plt.show()