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

[Python Ocean Topic Thirty-Seven] Ocean Index Drawing Method – Line Chart Style 1
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 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

[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:

'''# ----01 Import function package-----'''
import matplotlib
import numpy as np
from matplotlib import pyplot as plt
import codecs

'''# ----02----Read index file----'''
f = codecs.open("D:\pycharm_work\program\40_read_ocean_index_and_plot\amo_index.txt",
                mode='r') #Open txt file
year = []
amo_moth_1, amo_moth_2, amo_moth_3, amo_moth_4, amo_moth_5, amo_moth_6 = ([], [], [], [], [], [])
amo_moth_7, amo_moth_8, amo_moth_9, amo_moth_10, amo_moth_11, amo_moth_12 = ([], [], [], [], [], [])
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()
# ----read_end----
'''# 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] = np.nan
'''# Drawing'''
# ----01----Read color--Subsequent use-shallow_blue---
filename = 'D:\matlab_work\Creation of color index table with function name colormore\R_color_txt\R_color_single\cornflowerblue.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)
# ----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=cornflowerblue / 256, marker='.', linestyle='-', linewidth=1, markersize=1)
plt.axhline(y=0.0, color=brown / 256, linestyle='--', lw=0.5) # y=0
# ----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.jpg', dpi=600, bbox_inches='tight', pad_inches=0.1) # Output the map and set the border margin to be tight
plt.show()