zhexian4

非等比例坐标轴折线图主要是指将y轴换为对数坐标轴或是其他格式。对于对数坐标轴来说,matplotlib提供了两种格式可供选择,分别是”symlog”以及”log”,就使用感觉而言,个人认为”symlog”更加方便(主要是坐标刻度ticklabels的设置更加方便)。

下图的绘制没有任何实际物理意义,仅供参考。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import pandas as pd
import matplotlib.ticker as ticker
#读取数据
f = xr.open_dataset('./data.nc')
t = f['air'].loc['2005-07-01',:,45,120]
lev = t.level
#创建Figure
fig = plt.figure(figsize=(15,5))
#log
ax1 = fig.add_subplot(1,3,1)
ax1.plot(t,lev)
ax1.set_ylim(1000,100)
ax1.set_yscale('log')
ax1.set_title('log')
ax1.set_yticks([1000,850,700,500,300,200,100])
ax1.set_yticklabels([1000,850,700,500,300,200,100])
#隐藏掉次刻度,可以尝试注释下边这句代码会有怎样的效果?
ax1.yaxis.set_minor_formatter(ticker.NullFormatter())
#symlog
ax2 = fig.add_subplot(1,3,2)
ax2.plot(t,lev)
ax2.set_ylim(1000,100)
ax2.set_yscale('symlog')
ax2.set_title('symlog')
ax2.set_yticks([1000,850,700,500,300,200,100])
ax2.set_yticklabels([1000,850,700,500,300,200,100])
#linear
ax3 = fig.add_subplot(1,3,3)
ax3.plot(t,lev)
ax3.invert_yaxis()
ax3.set_yscale('linear')
ax3.set_title('linear')
ax3.set_yticks([1000,850,700,500,300,200,100])
ax3.set_yticklabels([1000,850,700,500,300,200,100])

输出图形如下:

image-20200702161610554