便捷绘图
<p>[TOC]</p>
<pre><code class="language-python">%matplotlib inline
%load_ext autoreload
%autoreload 2
import meteva.base as meb
import numpy as np
import matplotlib.pyplot as plt
from meteva.base.tool.plot_tools import add_china_map_2basemap</code></pre>
<p><strong>在检验或诊断分析的时候,经常需要绘制或输出一些图片以对数据的内容进行浏览。基于matplotlib绘制简单样式的图片并不困难,但也并非一两行代码就能完成,为此本程序库提供了一些绘制图像的工具类函数,据此可以一两行代码内实现比较完整的绘图功能。</strong> </p>
<pre><code class="language-python">grid0 = meb.grid([70,140,1],[15,55,1])
grd = meb.io.read_griddata_from_nc(r&quot;H:\test_data\input\meb\test.nc&quot;,grid = grid0) #读取网格数据,用于测试
meb.set_griddata_coords(grd,name = &quot;Temper_2m&quot;,dtime_list = [24],member_list = [&quot;ECMWF&quot;]) #设置数据的时空属性和要素名称
print(grd)</code></pre>
<pre><code>&lt;xarray.DataArray 'Temper_2m' (member: 1, level: 1, time: 1, dtime: 1, lat: 41, lon: 71)&gt;
array([[[[[[25.937511, ..., 28.250004],
...,
[-2.374992, ..., -3.187485]]]]]])
Coordinates:
* member (member) &lt;U5 'ECMWF'
* level (level) int32 -2147483647
* time (time) datetime64[ns] 2001-03-01
* dtime (dtime) int32 24
* lat (lat) int32 15 16 17 18 19 20 21 22 23 ... 48 49 50 51 52 53 54 55
* lon (lon) int32 70 71 72 73 74 75 76 77 ... 134 135 136 137 138 139 140</code></pre>
<pre><code class="language-python">plt.contourf(np.squeeze(grd.values)) #采用默认的绘图设置
plt.show()</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/da7decaa46aedd20a3fbc4976b736c0b?showdoc=.jpg" alt="" /></p>
<p>如上所示,虽然基于matploblib绘制一个平面场只需要调用plt.contourf()函数就可以完成,但是要对图像的横坐标,纵坐标,标题进行基本的设置,并添加地图和colorbar等元素,另外可能还需将图片保存到指定的路径中,等等这些操作加起来涉及到的代码就不少了。示例代码如下:</p>
<pre><code class="language-python">from mpl_toolkits.basemap import Basemap
fig = plt.figure()
ax = plt.axes()
plt.title(&quot;填色图&quot;)
grid0 = meb.get_grid_of_data(grd)
mp = Basemap(llcrnrlon=grid0.slon, urcrnrlon=grid0.elon, llcrnrlat=grid0.slat, urcrnrlat=grid0.elat)
add_china_map_2basemap(ax, name='province', edgecolor='k', lw=0.3,encoding = 'gbk') #添加底图
x = grd['lon'].values
y = grd['lat'].values
im = ax.contourf(x, y, np.squeeze(grd.values))
colorbar_position = fig.add_axes([0.95, 0.11, 0.03, 0.77])
plt.colorbar(im,cax= colorbar_position)
xticks = np.arange(70,150,10)
xticks_label = []
for x in range(len(xticks)):
xticks_label.append(str(xticks[x]))
xticks_label[-1] += &quot;°E&quot;
ax.set_xticks(xticks)
ax.set_xticklabels(xticks_label)
yticks = np.arange(20,60,10)
yticks_label = []
for y in range(len(yticks)):
yticks_label.append(str(yticks[y]))
yticks_label[-1] += &quot;°N&quot;
ax.set_yticks(yticks)
ax.set_yticklabels(yticks_label)
plt.show()</code></pre>
<p><img src="https://www.showdoc.cc/server/api/common/visitfile/sign/9749a264096b16db599ecb49eca5fd69?showdoc=.jpg" alt="" /></p>
<p>如上所示,要绘制一个信息稍微完整的平面图涉及到的代码能达到二十多行,而且其中的设置参数都是针对性的,并不具备通用性。为提高效率,本程序将绘制平面图的功能封装成一个函数,在函数内部集成了自动设置坐标标记、标题、colorbar等属性的方法,达到传达基本信息和简洁清晰的需求。其函数模块如下:</p>
<p>如上所示,要绘制一个信息稍微完整的平面图涉及到的代码能达到二十多行,而且其中的设置参数都是针对性的,并不具备通用性。为提高效率,本程序将绘制平面图的功能封装成一个函数,在函数内部集成了自动设置坐标标记、标题、colorbar等属性的方法,达到传达基本信息和简洁清晰的需求。其函数模块如下:</p>
<h1>绘制水平填色图</h1>
<p><font face="黑体" color=blue size = 5><strong>contourf_xy(grd,save_path = None,title = None,clevs= None,cmap = None,add_county_line = False,add_worldmap =False,show = False,dpi = 300,sup_fontsize = 10,height = None,width = None,subplot = None,ncol = None,sup_title = None,clip= None,add_minmap= None,extend = None,save_dir = None)</strong></font> </p>
<p>将网格数据绘制成填色图。该函数等价于contourf_2d_grid,且contourf_2d_grid 仍然可用</p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>grd</font></strong></td>
<td style="text-align: left;">网格数据</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">图片输出路径,如果grd中数据超过3维,则会以多张png格式图片输出,如果要为每张图片设置路径则以字符串列表的形式输入</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_dir</strong></td>
<td style="text-align: left;">图片输出的文件夹,如果grd中数据超过3维,则会以多张png格式图片输出到该文件夹,文件名则自动采用和sup_title一致的方式命名</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">图片标题,缺省时自动提取grd中信息生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">填色的等级设置,取值为列表或一维nump数值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">字符或者matplotlib 的cm对象。 缺省值"rainbow"对应彩虹色方案。 当cmap为字符时支持两种情况,一种是matplotlib 能够识别的字符串,例如"rainbow","bwr"等等,具体可以参考https://matplotlib.org/tutorials/colors/colormaps.html, 另外则是meteva定义的一些和预报检验有关的一些配色方案,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数说明</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_county_line</strong></td>
<td style="text-align: left;">是否在地图中增加县界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_worldmap</strong></td>
<td style="text-align: left;">是否在其它国家的国界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片,如果没有通过save_path或save_dir参数指定任何输出路径,则show取值自动为True</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">图片的分辨率,效果同matplotlib的dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sub_plot</strong></td>
<td style="text-align: left;">当sta0包含了多个level,time,dtime或member的数据时,例如当sub_plot = level 时,则一张图中会包含多个层次数据的子图,而其它维度如果size!=1 则会以不同文件的形式依次生成。</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">子图的列数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">sub_plot 不为None图片中包含多个子图时起作用,sup_title可以时None,字符串或字符串列表,当取值为字符时,所有批量制作的图片会有相同的sup_title,当其为列表时,会逐一为每张图片设置sup_title</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clip</strong></td>
<td style="text-align: left;">白化的参数,可以是"china",或省份名称的拼音,,山西的拼音采用"shanxi", 陕西的拼音采用"shaanxi",可以是用于记录闭合线的三层嵌套列表(见下文示例)</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_minmap</strong></td>
<td style="text-align: left;">是否添加南海小地图,默认情况下不添加,add_minmap="left"时添加在图形的左下角,add_minmap ="right"时添加在右下角</td>
</tr>
<tr>
<td style="text-align: left;"><strong>extend</strong></td>
<td style="text-align: left;">extend 参数用于控制 colorbar 的扩展端口的外观,用法和matplotlib中一致,默认值为"neither" ,即colorbar两端都是方的。extend = "both"时,colorbar 的两端都是尖的。extend = "min"时,colorbar 的最小值一端是尖的。extend = "max"时,colorbar 的最大值一端是尖的</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">双层嵌套的列表,外层列表的size 和顺序和sta_to一致, 内层嵌套的size并不固定,顺序按离sta_to中站点的距离有近到远排列</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">meb.tool.plot_tools.contourf_xy(grd) # 可选参数全部缺省时的绘图效果</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/b3f13fd8ad34471efa5a17323ed443f5" alt="" /></p>
<pre><code class="language-python">meb.tool.plot_tools.contourf_xy(grd,title = &quot;EC 2001年3月1日0时24小时温度预报&quot;,
cmap =meb.cmaps.temp_2m,extend = &quot;both&quot;) #带cmap参数的绘图效果</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=809c56d6f9c18052fcceff18ce8de312&amp;file=file.png" alt="" /></p>
<p>如上所示,contourf_2d_grid 函数可以根据图形的范围自动调整横坐标的间隔。同时对比上面两张图片可以知道,在使用相同的填色设置时,该函数可以在网格范围有变化情况下保持填色的方式不变,而colorbar自动调整。本程序库另外也提供了</p>
<pre><code class="language-python">#生成一个6维的网格数据,通过contourf_xy将所有数据内容绘制成图形,
#其中每种图形包含member,lon,lat三个维度,其它维度则以不同图片文件形式依次生成
grid0 = meb.grid([100,110,1],[20,25,1],
gtime = [&quot;2020010108&quot;,&quot;2020010208&quot;,&quot;24h&quot;],dtime_list = [0,24],
level_list = [500,700],member_list = [&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;SCMOC&quot;])
grd_6d = meb.grid_data(grid0,10 * np.random.randn(3,2,2,2,11,6))
meb.tool.plot_tools.contourf_xy(grd_6d,subplot = &quot;member&quot;,ncol = 3,save_dir = r&quot;H:\test_data\output\meb&quot;,show = True)</code></pre>
<p>图片已保存至H:\test_data\output\meb/ Level500_2020年01月01日08时0H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/a55876e469086d1bfef13a9929e87a1a" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level500_2020年01月01日08时24H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/c6b6b0756327cf4cdf7d637cfffa9911" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level500_2020年01月02日08时0H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/f2fc78789e4761c28861eb52247fb7e0" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level500_2020年01月02日08时24H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/40d46d04d684020ccbc2cfa8b831f349" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level700_2020年01月01日08时0H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/fbbe23ff94542f00ec331da2530d0d0b" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level700_2020年01月01日08时24H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/f6c69373e345bf9de7d547cc7dd319f2" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level700_2020年01月02日08时0H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/6ba2ee6f98136abfceaa1de219a8ad41" alt="" /></p>
<p>图片已保存至H:\test_data\output\meb/ Level700_2020年01月02日08时24H时效.png</p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/fe19fc678a6c50d8610414299fda2988" alt="" /></p>
<pre><code class="language-python">grid1 = meb.grid([102,122,1],[20,33,1]) #定义一个范围小一些的网格,以此读取相应的数据
grd = meb.io.read_griddata_from_nc(r&quot;H:\test_data\input\meb\test.nc&quot;,grid = grid1)
meb.set_griddata_coords(grd,name = &quot;Temper_2m&quot;,member_list = [&quot;ECMWF&quot;])</code></pre>
<pre><code class="language-python">#根据自定义的区域范围,将区域外的数据图形白化。
clip_line_list =[[[105,24],[110,24],[110,30],[105,30]],
[[115,24],[120,24],[120,30],[115,30]]]
meb.tool.plot_tools.contourf_xy(grd,cmap = meb.cmaps.temp_2m,clip =clip_line_list) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/244876268099ece5777f6ef1e8f5e69b" alt="" /></p>
<pre><code class="language-python"># 绘制多省的白化效果
meb.tool.plot_tools.contourf_xy(grd,cmap = meb.cmaps.temp_2m,clip =[&quot;hunan&quot;,&quot;jiangxi&quot;]) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/dd714c7853358e5be45d5f59707d4cda" alt="" /></p>
<h1>绘制水平马赛克图</h1>
<p><font face="黑体" color=blue size = 5><strong>mesh_xy(grd,save_path = None,title = None,clevs= None,cmap = None,add_county_line = False,add_worldmap =False,show = False,dpi = 300,sup_fontsize = 10,height = None,width = None)</strong></font> </p>
<p>将网格数据绘制成马赛克形式的填色图。 该函数等价于此前的pcolormesh_2d_grid,并且pcolormesh_2d_grid还可以使用。</p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>grd</font></strong></td>
<td style="text-align: left;">网格数据</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">图片输出路径,缺省时以plt.show()方式交互显示</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">图片标题,缺省时自动提取grd中信息生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">填色的等级设置,取值为列表或一维nump数值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">字符或者matplotlib 的cm对象。 缺省值"rainbow"对应彩虹色方案。 当cmap为字符时支持两种情况,一种是matplotlib 能够识别的字符串,例如"rainbow","bwr"等等,具体可以参考https://matplotlib.org/tutorials/colors/colormaps.html, 另外则是meteva定义的一些和预报检验有关的一些配色方案,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数说明</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_county_line</strong></td>
<td style="text-align: left;">是否在地图中增加县界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_worldmap</strong></td>
<td style="text-align: left;">是否在其它国家的国界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">图片的分辨率,效果同matplotlib的dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">双层嵌套的列表,外层列表的size 和顺序和sta_to一致, 内层嵌套的size并不固定,顺序按离sta_to中站点的距离有近到远排列</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">meb.tool.plot_tools.mesh_xy(grd,cmap = meb.cmaps.temp_2m) # 绘制不同范围的填色图</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/df4367553225903fd7aefcae079b0d6a?showdoc=.jpg" alt="" /></p>
<h1>绘制纬向剖面填色图</h1>
<p><font face="黑体" color=blue size = 5><strong>contourf_xz(grd,subplot = "member",sup_title = None,title = None,save_path = None,
clevs = None,cmap = None,show = False,dpi =300,sup_fontsize = 12,width = None,height = None,
ncol = None,extend = None)</strong></font> </p>
<p>将网格数据绘制成填色图</p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>grd</font></strong></td>
<td style="text-align: left;">网格数据</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sub_plot</strong></td>
<td style="text-align: left;">当sta0包含了多个level,time,dtime或member的数据时,例如当sub_plot = level 时,则一张图中会包含多个层次数据的子图,而其它维度如果size!=1 则会以不同文件的形式依次生成。</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">sub_plot 不为None图片中包含多个子图时起作用,sup_title可以时None,字符串或字符串列表,当取值为字符时,所有批量制作的图片会有相同的sup_title,当其为列表时,会逐一为每张图片设置sup_title</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">子图标题,以列表形式输入,缺省时自动提取grd中信息生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">图片输出路径,如果grd中数据超过3维,则会以多张png格式图片输出,如果要为每张图片设置路径则以字符串列表的形式输入</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_dir</strong></td>
<td style="text-align: left;">图片输出的文件夹,如果grd中数据超过3维,则会以多张png格式图片输出到该文件夹,文件名则自动采用和sup_title一致的方式命名</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">填色的等级设置,取值为列表或一维nump数值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">字符或者matplotlib 的cm对象。 缺省值"rainbow"对应彩虹色方案。 当cmap为字符时支持两种情况,一种是matplotlib 能够识别的字符串,例如"rainbow","bwr"等等,具体可以参考https://matplotlib.org/tutorials/colors/colormaps.html, 另外则是meteva定义的一些和预报检验有关的一些配色方案,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数说明</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片,如果没有通过save_path或save_dir参数指定任何输出路径,则show取值自动为True</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">图片的分辨率,效果同matplotlib的dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">子图的列数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>extend</strong></td>
<td style="text-align: left;">extend 参数用于控制 colorbar 的扩展端口的外观,用法和matplotlib中一致,默认值为"neither" ,即colorbar两端都是方的。extend = "both"时,colorbar 的两端都是尖的。extend = "min"时,colorbar 的最小值一端是尖的。extend = "max"时,colorbar 的最大值一端是尖的</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">双层嵌套的列表,外层列表的size 和顺序和sta_to一致, 内层嵌套的size并不固定,顺序按离sta_to中站点的距离有近到远排列</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">#生成一个6维的网格数据,通过contourf_xy将所有数据内容绘制成图形,
#其中每种图形包含member,lon,level三个维度,其它维度则以不同图片文件形式依次生成
grid0 = meb.grid([100,110,1],[20,20,1],
gtime = [&quot;2020010108&quot;],dtime_list = [24,48],
level_list = [1000,925,850,700,500,300,100,50],member_list = [&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;SCMOC&quot;])
grd_6d = meb.grid_data(grid0,10 * np.random.randn(3,8,1,2,1,11))
meb.tool.plot_tools.contourf_xz(grd_6d,subplot = &quot;member&quot;,ncol = 3,save_dir = r&quot;H:\test_data\output\meb&quot;,show = True) </code></pre>
<pre><code>检验结果已以图片形式保存至H:\test_data\output\meb/2020年01月01日08时_24H时效.png</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=145d629838ab245dd216bbe57ab50894&amp;file=file.png" alt="" /></p>
<pre><code>检验结果已以图片形式保存至H:\test_data\output\meb/2020年01月01日08时_48H时效.png</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=a4513ca0788b0f97859d857075128ab2&amp;file=file.png" alt="" /></p>
<h1>绘制纬向剖面填色图</h1>
<p><font face="黑体" color=blue size = 5><strong>contourf_yz(grd,subplot = "member",sup_title = None,title = None,save_path = None,
clevs = None,cmap = None,show = False,dpi =300,sup_fontsize = 12,width = None,height = None,
ncol = None,extend = None)</strong></font> </p>
<p>将网格数据绘制成填色图</p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>grd</font></strong></td>
<td style="text-align: left;">网格数据</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sub_plot</strong></td>
<td style="text-align: left;">当sta0包含了多个level,time,dtime或member的数据时,例如当sub_plot = level 时,则一张图中会包含多个层次数据的子图,而其它维度如果size!=1 则会以不同文件的形式依次生成。</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">sub_plot 不为None图片中包含多个子图时起作用,sup_title可以时None,字符串或字符串列表,当取值为字符时,所有批量制作的图片会有相同的sup_title,当其为列表时,会逐一为每张图片设置sup_title</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">子图标题,以列表形式输入,缺省时自动提取grd中信息生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">图片输出路径,如果grd中数据超过3维,则会以多张png格式图片输出,如果要为每张图片设置路径则以字符串列表的形式输入</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_dir</strong></td>
<td style="text-align: left;">图片输出的文件夹,如果grd中数据超过3维,则会以多张png格式图片输出到该文件夹,文件名则自动采用和sup_title一致的方式命名</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">填色的等级设置,取值为列表或一维nump数值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">字符或者matplotlib 的cm对象。 缺省值"rainbow"对应彩虹色方案。 当cmap为字符时支持两种情况,一种是matplotlib 能够识别的字符串,例如"rainbow","bwr"等等,具体可以参考https://matplotlib.org/tutorials/colors/colormaps.html, 另外则是meteva定义的一些和预报检验有关的一些配色方案,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数说明</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片,如果没有通过save_path或save_dir参数指定任何输出路径,则show取值自动为True</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">图片的分辨率,效果同matplotlib的dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">子图的列数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>extend</strong></td>
<td style="text-align: left;">extend 参数用于控制 colorbar 的扩展端口的外观,用法和matplotlib中一致,默认值为"neither" ,即colorbar两端都是方的。extend = "both"时,colorbar 的两端都是尖的。extend = "min"时,colorbar 的最小值一端是尖的。extend = "max"时,colorbar 的最大值一端是尖的</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">双层嵌套的列表,外层列表的size 和顺序和sta_to一致, 内层嵌套的size并不固定,顺序按离sta_to中站点的距离有近到远排列</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">#生成一个6维的网格数据,通过contourf_xy将所有数据内容绘制成图形,
#其中每种图形包含member,lat,level三个维度,其它维度则以不同图片文件形式依次生成
grid0 = meb.grid([100,100,1],[20,30,1],
gtime = [&quot;2020010108&quot;],dtime_list = [24],
level_list = [1000,925,850,700,500,300,100,50],member_list = [&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;SCMOC&quot;])
grd_6d = meb.grid_data(grid0,10 * np.random.randn(3,8,1,1,11,1))
meb.tool.plot_tools.contourf_yz(grd_6d,subplot = &quot;member&quot;,ncol = 3,width = 10) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c1a6d573c371e013dbc0ee0b2f4d6640&amp;file=file.png" alt="" /></p>
<h1>绘制站点填图</h1>
<p><font face="黑体" color=blue size = 3><strong>scatter_sta(sta0,value_column=None,map_extend = None,add_county_line = False,add_worldmap = False,clevs=None, cmap="rainbow",fix_size = True,threshold = None,mean_value = None,print_max = 0,print_min = 0,save_dir = None,save_path=None,show = False,dpi = 300,title=None,sup_fontsize = 10,height = None,width = None,min_spot_value = 0,grid = False,subplot = None,ncol = None,point_size = None,sup_title = None)</strong></font> </p>
<p>将站点数据绘制成散点填色图。</p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>sta0</font></strong></td>
<td style="text-align: left;">站点数据</td>
</tr>
<tr>
<td style="text-align: left;"><strong>value_column</strong></td>
<td style="text-align: left;">当sta0中包含N列数据时,value_column可设置为0 到N-1的整数,用于指定绘制其中一列数据,该参数缺省时,会将所有的数据分布绘制在不同的图片中</td>
</tr>
<tr>
<td style="text-align: left;"><strong>map_extend</strong></td>
<td style="text-align: left;">底图的范围,缺省时自动根据站点数据的范围确定底图范围,不缺省时采用[slon,elon,slat,elat] 列表作为参数,也可也接受<a href="https://www.showdoc.cc/meteva?page_id=3975600815874861">网格信息类变量</a>作为地图范围的参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_county_line</strong></td>
<td style="text-align: left;">是否在图中添加县界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_worldmap</strong></td>
<td style="text-align: left;">是否在其它国家的国界</td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">填色的等级设置,取值为列表或一维nump数值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">字符或者matplotlib 的cm对象。 缺省值"rainbow"对应彩虹色方案。 当cmap为字符时支持两种情况,一种是matplotlib 能够识别的字符串,例如"rainbow","bwr"等等,具体可以参考https://matplotlib.org/tutorials/colors/colormaps.html, 另外则是meteva定义的一些和预报检验有关的一些配色方案,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数说明</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>fix_size</strong></td>
<td style="text-align: left;">是否需要根据站点值来确定站点填色的半径</td>
</tr>
<tr>
<td style="text-align: left;"><strong>threshold</strong></td>
<td style="text-align: left;">是否突出显示取值大于threshold的站点</td>
</tr>
<tr>
<td style="text-align: left;"><strong>mean_value</strong></td>
<td style="text-align: left;">由于可能需要根据站点值来设置站点填色的半径,而不同站点数据填色半径的基准值会存在差异, 为了在批量调用该绘图模块绘制图片时采用统一的基准,可以通过设置统一的mean_value 来保持该基准。mean_value 可大概设置为批量站点数据的平均值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>print_max</strong></td>
<td style="text-align: left;">在屏幕上打印评分指标最大的print_max的站点的信息</td>
</tr>
<tr>
<td style="text-align: left;"><strong>print_min</strong></td>
<td style="text-align: left;">在屏幕上打印评分指标最小的print_min的站点的信息</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_dir</strong></td>
<td style="text-align: left;">图片输出文件夹,文件的路径将据此自动生成</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">指定图片输出的文件路径,当批量生成多张图片时save_path为包含所有图片的输出路径的列表</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">绘图的dpi参数,用法同matplotlib中dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">图片标题的确定分为1、全自动,2、半自动,3手动三种方式。<br>1、全自动:不设置title参数,系统自动采用title的缺省值+自动补齐的其它信息来确定每一幅图的标题; <br>2、半自动:title 为字符串类型,系统会采用title + 自动补齐的其它信息来确定每一幅图的标题;<br>3、手动:title为一个包含多个字符串的列表,且列表的长度必须和要绘制的图的数量一致,每一幅图会依次采用列表中的字符串作为标题,如果sub_plot 不为None,则title的size 要=图片的数据每幅图子图的数量</td>
</tr>
<tr>
<td style="text-align: left;"><strong>min_spot_value</strong></td>
<td style="text-align: left;">当fix_size = False时,站点填色的半径由站点值-min_spot_value 来确定。缺省值为0,即采用站点值的绝对值确定</td>
</tr>
<tr>
<td style="text-align: left;"><strong>subplot</strong></td>
<td style="text-align: left;">当sta0包含了多个level,time,dtime或member的数据时,当subplot = level 时,则一张图中会包含多个层次数据的子图,而其它维度如果size!=1 则会以不同文件的形式依次生成。</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">子图的列数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>point_size</strong></td>
<td style="text-align: left;">站点填色半径的平均半径,缺省情况下程序会自动计算,保证不出现明显重叠</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">sub_plot 不为None图片中包含多个子图时起作用,sup_title可以时None,字符串或字符串列表,当取值为字符时,所有批量制作的图片会有相同的sup_title,当其为列表时,会逐一为每张图片设置sup_title</td>
</tr>
<tr>
<td style="text-align: left;"><strong>add_minmap</strong></td>
<td style="text-align: left;">是否添加南海小地图,默认情况下不添加,add_minmap="left"时添加在图形的左下角,add_minmap ="right"时添加在右下角</td>
</tr>
<tr>
<td style="text-align: left;"><strong>extend</strong></td>
<td style="text-align: left;">extend 参数用于控制 colorbar 的扩展端口的外观,用法和matplotlib中一致,默认值为"neither" ,即colorbar两端都是方的。extend = "both"时,colorbar 的两端都是尖的。extend = "min"时,colorbar 的最小值一端是尖的。extend = "max"时,colorbar 的最大值一端是尖的</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title_in_ax</strong></td>
<td style="text-align: left;">是否将子图的标题画在图框内部</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">rain = meb.read_stadata_from_micaps3(r&quot;H:\test_data\input\meb\m3.txt&quot;)
rain[&quot;data0&quot;] = rain[&quot;data0&quot;] * 10
rain[&quot;data1&quot;] = rain[&quot;data0&quot;] * np.random.rand(len(rain.index))
meb.set_stadata_names(rain,[&quot;rain24&quot;,&quot;rain12&quot;])
print(rain)</code></pre>
<pre><code> level time dtime id lon lat rain24 rain12
0 0 2020-01-03 20:00:00 0 57671 112.37 28.85 13.0 3.433410
1 0 2020-01-03 20:00:00 0 57845 109.78 26.17 54.0 7.800301
2 0 2020-01-03 20:00:00 0 57466 111.75 30.46 1.0 0.086850
3 0 2020-01-03 20:00:00 0 57842 109.72 26.88 8.0 5.365058
4 0 2020-01-03 20:00:00 0 57584 113.09 29.38 13.0 5.704016
.. ... ... ... ... ... ... ... ...
561 0 2020-01-03 20:00:00 0 57589 113.88 29.27 22.0 4.638843
562 0 2020-01-03 20:00:00 0 57583 113.97 29.92 42.0 31.387810
563 0 2020-01-03 20:00:00 0 55690 91.95 27.98 23.0 2.974778
564 0 2020-01-03 20:00:00 0 55597 91.68 29.03 0.0 0.000000
565 0 2020-01-03 20:00:00 0 56434 97.47 28.67 2.0 0.306240
[566 rows x 8 columns]</code></pre>
<pre><code class="language-python">meb.tool.plot_tools.scatter_sta(rain)</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/e4623eacc79ce0b37f6c98328478ba94" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/4d86f389eadfc6ecd3813b7070e5cbee" alt="" /></p>
<pre><code class="language-python">meb.tool.plot_tools.scatter_sta(rain,value_column=0,map_extend = [110,123,28,34],
cmap = meb.cmaps.rain_24h)</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/f2792bc97f34d5131220cbbf4c5361f5" alt="" /></p>
<pre><code class="language-python">meb.tool.plot_tools.scatter_sta(rain,value_column=0,map_extend = [110,123,28,34],
cmap = meb.cmaps.rain_24h,
fix_size=False,print_max = 1,print_min = 1)</code></pre>
<pre><code>取值最大的1个站点:
id:55437 lon:81.25 lat:30.28 value:87.0
取值最小的1个站点:
id:51232 lon:82.55 lat:45.18 value:0.0</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/0a798d1c0d67883c5546a93016026d87" alt="" /></p>
<pre><code class="language-python">meb.tool.plot_tools.scatter_sta(rain,value_column=0,map_extend = [110,123,28,34],
cmap = meb.cmaps.rain_24h,
fix_size=False,print_max = 1,print_min = 1,add_county_line=True,dpi = 100)</code></pre>
<pre><code>取值最大的1个站点:
id:55437 lon:81.25 lat:30.28 value:87.0
取值最小的1个站点:
id:51232 lon:82.55 lat:45.18 value:0.0</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/dfc66c8cb827e73b296b881f8d04063d" alt="" /></p>
<pre><code class="language-python">meb.tool.plot_tools.scatter_sta(rain,value_column=0,map_extend = [110,123,28,34],
cmap = meb.cmaps.rain_24h,
fix_size=True,print_max = 1,print_min = 1,add_county_line=True,dpi = 100)</code></pre>
<pre><code>取值最大的1个站点:
id:55437 lon:81.25 lat:30.28 value:87.0
取值最小的1个站点:
id:51232 lon:82.55 lat:45.18 value:0.0</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/4144b6fa931d5bcc82729e3a029ee1b1" alt="" /></p>
<pre><code class="language-python">import datetime
rain = meb.read_stadata_from_micaps3(r&quot;H:\test_data\input\meb\m3.txt&quot;,data_name = &quot;ob&quot;)
rain[&quot;ob&quot;] = rain[&quot;ob&quot;] * 10
rain[&quot;ecmwf&quot;] = rain[&quot;ob&quot;] * np.random.rand(len(rain.index))
rain_d48 = rain.copy()
rain_d72 = rain.copy()
rain_d96 = rain.copy()
rain[&quot;dtime&quot;] = 24
rain_d48[&quot;dtime&quot;] = 48
rain_d72[&quot;dtime&quot;] = 72
rain_d96[&quot;dtime&quot;] = 96
sta_ob = pd.concat([rain,rain_d48,rain_d72,rain_d96],axis = 0)
print(sta_ob)</code></pre>
<pre><code> level time dtime id lon lat ob ecmwf
0 0 2020-01-03 20:00:00 24 57671 112.37 28.85 13.0 1.092646
1 0 2020-01-03 20:00:00 24 57845 109.78 26.17 54.0 13.825346
2 0 2020-01-03 20:00:00 24 57466 111.75 30.46 1.0 0.382333
3 0 2020-01-03 20:00:00 24 57842 109.72 26.88 8.0 2.463864
4 0 2020-01-03 20:00:00 24 57584 113.09 29.38 13.0 0.694839
.. ... ... ... ... ... ... ... ...
561 0 2020-01-03 20:00:00 96 57589 113.88 29.27 22.0 10.464676
562 0 2020-01-03 20:00:00 96 57583 113.97 29.92 42.0 34.049522
563 0 2020-01-03 20:00:00 96 55690 91.95 27.98 23.0 4.158791
564 0 2020-01-03 20:00:00 96 55597 91.68 29.03 0.0 0.000000
565 0 2020-01-03 20:00:00 96 56434 97.47 28.67 2.0 1.194378
[2264 rows x 8 columns]</code></pre>
<pre><code class="language-python">meb.scatter_sta(sta_ob,map_extend = [100,120,25,35],subplot = &quot;dtime&quot;,cmap = meb.cmaps.rain_24h,sup_fontsize = 7
,ncol = 2, sup_title = [&quot;观测降水&quot;,&quot;模式降水&quot;],extend = &quot;max&quot;)
#下面的结果中生成了2张图片,分别是ob 和 ecmwf两个成员的结果。 另外每幅图包含4个子图,分别对应不同时效。</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=c69c41e70dfc2359866a34e1688fc076&amp;file=file.png" alt="" /></p>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=f737c39ea28b7baf093f33f9ffdd2fb9&amp;file=file.png" alt="" /></p>
<h1>设置自定义地图</h1>
<p><font face="黑体" color=blue size = 5><strong>set_customized_shpfile_list(shpfile_list = None)</strong></font> </p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong>shpfile_list</strong></td>
<td style="text-align: left;">自定义的地图shp文件的路径列表。 以世界地图为例,一套完整的地图shp文件包括 .shp、 .shx 和.dbf结尾的3个同名文件,shpfile_list列表中的元素是只包含除了文件后缀之外的文件绝对路径的共同部分。另外meteva已经内置了一部分地图数据,在列表中添加"worldmap","NationalBorder","Province","BOUNT_poly","hyd1_4p"等字符串就可以分别添加世界地图、中国地图、省界、县界和河流。为了方便编辑器自动弹出,系统还集成了<a href="https://www.showdoc.com.cn/meteva?page_id=3975601025884078">meb.shpfile.world, meb.shpfile.china,meb.shpfile.province,meb.shpfile.county和meb.shpfile.river</a>分别代表上述地图,也可以被添加在列表中。</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值,当shpfile_list 不为空时运行后完成自定义地图设置,之后的绘图都会采用该设置,若不带任何参数执行该函数,则重置成系统默认的自动地图</td>
</tr>
</tbody>
</table>
<p><strong>调用示例:</strong></p>
<pre><code class="language-python">grd = meb.io.read_griddata_from_nc(r&quot;H:\test_data\input\meb\test.nc&quot;)
meb.tool.plot_tools.contourf_2d_grid(grd) # 缺省时自动设置的地图</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/45a7739b994babb3cf6990434b3ccb3e?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">meb.set_customized_shpfile_list([
r&quot;H:\task\develop\python\git\meteva\meteva\resources\maps\NationalBorder&quot;, # 文件路径方式添加国界
&quot;Province&quot;, #字符形式添加省界
meb.shpfile.river #meteva模块形式添加河流
])
meb.tool.plot_tools.contourf_2d_grid(grd) # 缺省时自动设置的地图</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/e3273de6986101ee191949942d78e169?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">meb.set_customized_shpfile_list() #不带参数执行
meb.tool.plot_tools.contourf_2d_grid(grd) # 重新回归自动设置</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/65ba746582188149ece618bdf2f96111?showdoc=.jpg" alt="" /></p>
<h1>矩阵数据绘制_bar</h1>
<p><font face="黑体" color=blue size = 5><strong>bar(array,name_list_dict = None,legend = None,axis = None,ylabel = "Value",vmin = None,vmax = None,ncol = None,grid = None,tag = -1,save_path = None,show = False
,dpi = 300,bar_width = None,title = "",spasify_xticks = None,sup_fontsize = 10,width = None,height = None,log_y = False
,sup_title = None,xlabel = None, legend_col = None,color_list = None)</strong></font> </p>
<h1>矩阵数据绘制_plot</h1>
<p><font face="黑体" color=blue size = 5><strong>plot(array,name_list_dict = None,legend = None,axis = None,ylabel = "Value",vmin = None,vmax = None,ncol = None,grid = None,tag = -1,save_path = None,show = False,dpi = 300,
,title ="",spasify_xticks = None,sup_fontsize = 10,width = None,height = None,log_y = False,sup_title = None,xlabel = None
,legend_col = None,color_list = None)</strong></font> </p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>array</font></strong></td>
<td style="text-align: left;">numpy 矩阵数据,暂时只支持1、2、3维的矩阵</td>
</tr>
<tr>
<td style="text-align: left;"><strong>name_list_dict</strong></td>
<td style="text-align: left;">以字典形式存储的每个维度的描述信息,其中字典的key为维度的名称,字典的value 为维度的坐标值的列表,列表中的元素只支持字符型 和 时间类型</td>
</tr>
<tr>
<td style="text-align: left;"><strong>legend</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应不同legend的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应x轴的维度的名称,它必须是name_list_dict 中的key,当axis = "dayofyear"时,会自动以日期形式展示横坐标,但其中不会包含年份</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ylabel</strong></td>
<td style="text-align: left;">各子图的y轴的坐标名称</td>
</tr>
<tr>
<td style="text-align: left;"><strong>vmin</strong></td>
<td style="text-align: left;">各子图的y轴的坐标范围的最小值,当它是实数时,所有子图采用相同的值,当它是列表时,每个子图按顺序采用不同的值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>vmax</strong></td>
<td style="text-align: left;">各子图的y轴的坐标范围的最大值,当它是实数时,所有子图采用相同的值,当它是列表时,每个子图按顺序采用不同的值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">如果存在多个子图,子图的列数将为ncol,缺省情况下回自动布局</td>
</tr>
<tr>
<td style="text-align: left;"><strong>grid</strong></td>
<td style="text-align: left;">是否添加网格线,只能设置为True 或False, 缺省时程序自动根据数据特征生成网格线</td>
</tr>
<tr>
<td style="text-align: left;"><strong>tag</strong></td>
<td style="text-align: left;">当tag >=0 时会给每个数据点添加数字标注,tag为数字标注的小数点后有效位数,tag 小于0时不添加标注</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">指定图片输出的文件路径</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">绘图的dpi参数,用法同matplotlib中dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>bar_width</strong></td>
<td style="text-align: left;">仅适用于bar函数,控制条柱的宽度,取值范围再0-1之间</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">各子图的标题,如果只有一个子图,title可以设为字符串, 缺省时无标题,当有多个子图时,title应该设置为字符串的列表,分别对应每个子图的标题,缺省时则自动根据name_list_dict中的维度和坐标信息来生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sparsify_xticks</strong></td>
<td style="text-align: left;">x轴坐标刻度的稀疏倍数,缺省时会自动进行稀疏化,当spasify_xticks = 1 时, 所有的刻度值都要显示, spasify_xticks = 2时,则间隔1个刻度进行显示,依次类推</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>log_y</strong></td>
<td style="text-align: left;">y轴是否采用对数坐标</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">图片的总标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>xlabel</strong></td>
<td style="text-align: left;">子图的横坐标名称</td>
</tr>
<tr>
<td style="text-align: left;"><strong>legend_col</strong></td>
<td style="text-align: left;">legend的列数,在2维和3维数据绘制时可用</td>
</tr>
<tr>
<td style="text-align: left;"><strong>color_list</strong></td>
<td style="text-align: left;">每一种线条或bar的颜色,在2维和3维数据绘制时可用。color_list 的长度是legend的数目一致,其中元素可以有两种形式,第一种形式时表示颜色的字符,例如 color_list = ["r","g","b"], 表示依次用红绿和蓝绘制三组线条(bar),第二种是grb形式,例如 color_list = [[1,0,0],[0,1,0],[0,0,1]]也表示红、绿和蓝,此处rgb数值范围是0-1,而不是0-256</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值</td>
</tr>
</tbody>
</table>
<h1>廓线绘制_lineh</h1>
<p><font face="黑体" color=blue size = 5><strong> lineh(array,name_list_dict = None,legend = None,axis = None,xlabel = "Value",vmin = None,vmax = None,ncol = None,grid = None,tag = -1,save_path = None,show = False,dpi = 300,sparsify_yticks = 1,sup_fontsize = 10,title = "" ,height = None,width = None,log_y = False,sup_title = None,ylabel = None,legend_col = None,color_list = None,hline = None,marker = None,
legend_loc = "upper right",linestyle = None,return_axs = False)</strong></font> </p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>array</font></strong></td>
<td style="text-align: left;">numpy 矩阵数据,暂时只支持1、2、3维的矩阵</td>
</tr>
<tr>
<td style="text-align: left;"><strong>name_list_dict</strong></td>
<td style="text-align: left;">以字典形式存储的每个维度的描述信息,其中字典的key为维度的名称,字典的value 为维度的坐标值的列表,列表中的元素只支持字符型 和 时间类型</td>
</tr>
<tr>
<td style="text-align: left;"><strong>legend</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应不同legend的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应x轴的维度的名称,它必须是name_list_dict 中的key,当axis = "dayofyear"时,会自动以日期形式展示横坐标,但其中不会包含年份</td>
</tr>
<tr>
<td style="text-align: left;"><strong>xlabel</strong></td>
<td style="text-align: left;">各子图的y轴的坐标名称</td>
</tr>
<tr>
<td style="text-align: left;"><strong>vmin</strong></td>
<td style="text-align: left;">各子图的y轴的坐标范围的最小值,当它是实数时,所有子图采用相同的值,当它是列表时,每个子图按顺序采用不同的值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>vmax</strong></td>
<td style="text-align: left;">各子图的y轴的坐标范围的最大值,当它是实数时,所有子图采用相同的值,当它是列表时,每个子图按顺序采用不同的值</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">如果存在多个子图,子图的列数将为ncol,缺省情况下回自动布局</td>
</tr>
<tr>
<td style="text-align: left;"><strong>grid</strong></td>
<td style="text-align: left;">是否添加网格线,只能设置为True 或False, 缺省时程序自动根据数据特征生成网格线</td>
</tr>
<tr>
<td style="text-align: left;"><strong>tag</strong></td>
<td style="text-align: left;">当tag >=0 时会给每个数据点添加数字标注,tag为数字标注的小数点后有效位数,tag 小于0时不添加标注</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">指定图片输出的文件路径</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">绘图的dpi参数,用法同matplotlib中dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">各子图的标题,如果只有一个子图,title可以设为字符串, 缺省时无标题,当有多个子图时,title应该设置为字符串的列表,分别对应每个子图的标题,缺省时则自动根据name_list_dict中的维度和坐标信息来生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>spasify_yticks</strong></td>
<td style="text-align: left;">y轴坐标刻度的稀疏倍数,缺省时会自动进行稀疏化,当spasify_yticks = 1 时, 所有的刻度值都要显示, spasify_yticks = 2时,则间隔1个刻度进行显示,依次类推</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>log_y</strong></td>
<td style="text-align: left;">数值大小方向(水平轴)是否采用对数坐标</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_title</strong></td>
<td style="text-align: left;">图片的总标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">子图标题,以列表形式传入</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ylabel</strong></td>
<td style="text-align: left;">子图的坐标名称</td>
</tr>
<tr>
<td style="text-align: left;"><strong>legend_col</strong></td>
<td style="text-align: left;">legend的列数,在2维和3维数据绘制时可用</td>
</tr>
<tr>
<td style="text-align: left;"><strong>linestyle</strong></td>
<td style="text-align: left;">legend中线条类型,以列表形式输入</td>
</tr>
<tr>
<td style="text-align: left;"><strong>color_list</strong></td>
<td style="text-align: left;">每一种线条或bar的颜色,在2维和3维数据绘制时可用。color_list 的长度是legend的数目一致,其中元素可以有两种形式,第一种形式时表示颜色的字符,例如 color_list = ["r","g","b"], 表示依次用红绿和蓝绘制三组线条(bar),第二种是grb形式,例如 color_list = [[1,0,0],[0,1,0],[0,0,1]]也表示红、绿和蓝,此处rgb数值范围是0-1,而不是0-256</td>
</tr>
<tr>
<td style="text-align: left;">vline</td>
<td style="text-align: left;">在vline的位置添加垂直线</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值</td>
</tr>
</tbody>
</table>
<h2>1维数据示例</h2>
<pre><code class="language-python">data1 = np.random.rand(10) </code></pre>
<pre><code class="language-python">meb.bar(data1,dpi = 100) # 不带任何可选参数,为了节省网络存储空间,以下都选择dpi = 100,而没有采用采用默认的dpi=300</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/9d45aad582d96487266ca1bba9b0862e?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">#通过name_list_dict设置了数据的维度属性和坐标值,字典的key会被设置成x轴的label,字典的value 会被设置成x坐标。
name_list_dict1 = {&quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
meb.bar(data1,name_list_dict=name_list_dict1,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/5e131f63de08d570dfc76935fd942481?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python"># 设置图片标题,y轴的坐标名称,y轴坐标范围,条柱宽度,添加网格线,文字标注的有效位数
meb.bar(data1,name_list_dict=name_list_dict1,title = &quot;TS评分随时效的变化&quot;,
ylabel=&quot;评分&quot;,vmin = 0,vmax = 1,bar_width= 0.4,grid = True, tag = 2,dpi = 100)
</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/7203d0c2d1260fd54a0f480b60f1fef5?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python"># 采用plot 函数绘制线条
meb.plot(data1,name_list_dict=name_list_dict1,title = &quot;TS评分随时效的变化&quot;,
ylabel=&quot;评分&quot;,vmin = 0,vmax = 1,grid = True, tag = 2,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/95b0799ecbf6e0974bcb039145890312?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">name_list_dict1 = {&quot;时间&quot;:pd.date_range(&quot;2020-7-1 08:00&quot;,&quot;2020-7-6 &quot;,freq = &quot;12h&quot;)}
print(name_list_dict1)</code></pre>
<pre><code>{'时间': DatetimeIndex(['2020-07-01 08:00:00', '2020-07-01 20:00:00',
'2020-07-02 08:00:00', '2020-07-02 20:00:00',
'2020-07-03 08:00:00', '2020-07-03 20:00:00',
'2020-07-04 08:00:00', '2020-07-04 20:00:00',
'2020-07-05 08:00:00', '2020-07-05 20:00:00'],
dtype='datetime64[ns]', freq='12H')}</code></pre>
<pre><code class="language-python"># 采用plot 函数绘制线条
data1_t = np.random.rand(10)
meb.plot(data1_t,name_list_dict=name_list_dict1,title = &quot;TS评分随时间的变化&quot;,
ylabel=&quot;评分&quot;,vmin = 0,vmax = 1,grid = True, tag = 2,dpi = 100) # 坐标是时间时,会自动生成中文的时间坐标</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/fbc29d932e8d6423ac9b40a69ddf41e1?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">name_list_dict1 = {&quot;level(hPa)&quot;:[1000,925,850,800,700,600,500,400,300,200,100,50]}
data1_h = np.random.rand(12)
meb.lineh(data1_h,name_list_dict=name_list_dict1,title = &quot;评分的垂直廓线&quot;,
xlabel=&quot;评分&quot;,vmin = 0,vmax = 1,grid = True, tag = 2,dpi = 100) # 坐标是时间时,会自动生成中文的时间坐标</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=80d1daa8c3404a0d9a0a0034e17fb373&amp;file=file.png" alt="" /></p>
<h2>2维数据示例</h2>
<p><strong>2D和3D数据绘制时条柱和线条颜色策略说明</strong>:</p>
<ol>
<li>在本模块的函数中,线条的颜色是根据matplotlib自动绘制的,具体的颜色顺序参考 <a href="https://matplotlib.org/tutorials/colors/colormaps.html">https://matplotlib.org/tutorials/colors/colormaps.html</a> 说明文档中的名称为tab10的颜色表。</li>
<li>为了方便在包含实况的检验指标(例如mem.ob_fo_mean)和不包含实况的检验指标(例如mem.rmse)的结果的对比,程序中设置了第一个legend名称中包含 "ob","OB","Ob","oB","观测","实况","零场"等字眼时,则判断它们是观测的属性,会采用第一个浅蓝色绘制线条或条柱,否则自动的从tab10的第二个颜色(即橙色)开始依次绘制。 </li>
</ol>
<pre><code class="language-python">data2 = np.random.rand(3,10)</code></pre>
<pre><code class="language-python">meb.bar(data2,dpi = 100,vmin =0) # 不带任何可选参数, 程序自动生成坐标名称和刻度,自动生成legend</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/ca5002dcf6ad670ca3f9d1587a9b937b" alt="" /></p>
<pre><code class="language-python">#通过name_list_dict设置了数据的维度属性和坐标值
#字典的第一个key和对应的value会被设置成legend,
#字典的第二个key和对应的value 会被设置成x轴名称和坐标。
name_list_dict2 = {&quot;预报成员&quot;:[&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;],
&quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
meb.bar(data2,name_list_dict=name_list_dict2,dpi = 100,log_y = True) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/6f2c16f1abf0c437eae646909c610388" alt="" /></p>
<pre><code class="language-python"># 在不用改变data2的shape的情况下,也可以切换绘图方式,以另一个维度作为x轴
meb.bar(data2,name_list_dict=name_list_dict2,axis = &quot;预报成员&quot;,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/f036516331604fc31942f1f8fd31feb8" alt="" /></p>
<pre><code class="language-python"># 设置图片标题,y轴的坐标名称,y轴坐标范围,条柱宽度,添加网格线,文字标注的有效位数,通过color_list 设置颜色
meb.bar(data2,name_list_dict=name_list_dict2,title = &quot;不同模式TS评分随时效的变化&quot;,
ylabel=&quot;评分&quot;,vmin = 0,vmax = 1.2,bar_width= 0.15,grid = True, tag = 1,dpi = 100,color_list = [&quot;r&quot;,&quot;g&quot;,&quot;b&quot;])
</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/a6d1cbb063c0db62d4f9bde8a6f287d5" alt="" /></p>
<pre><code class="language-python"># 绘制曲线图,用rgb(取值范围为0-1)方式设置线条颜色
meb.plot(data2,name_list_dict=name_list_dict2,title = &quot;不同模式TS评分随时效的变化&quot;,
ylabel=&quot;评分&quot;,vmin = 0,vmax = 1.2,grid = True, tag = 1,dpi = 100,
color_list = [[1,0,0],[0,1,0],[0,0,1]]) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/e22d3c14c9e4b98b02a19d4c3ce001f7" alt="" /></p>
<pre><code class="language-python">name_list_dict1 = {
&quot;level(hPa)&quot;:[1000,925,850,800,700,600,500,400,300,200,100,50],
&quot;member&quot;:[&quot;OBS&quot;,&quot;FST&quot;]
}
data2_h = np.random.rand(12,2)
meb.lineh(data2_h,name_list_dict=name_list_dict1,title = &quot;评分的垂直廓线&quot;,axis = &quot;level(hPa)&quot;,
xlabel=&quot;评分&quot;,grid = True, tag = 2,dpi = 100) # 坐标是时间时,会自动生成中文的时间坐标</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=403fe33888922274000de746c9487273&amp;file=file.png" alt="" /></p>
<h2>3维数据示例</h2>
<pre><code class="language-python">data3 = np.random.rand(3,4,10)</code></pre>
<pre><code class="language-python">meb.bar(data3,dpi = 100)</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/c6617575529f6a5240073d09e5bfb084?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">#通过name_list_dict设置了数据的维度属性和坐标值
#字典的第一个key和对应的value会被设置成legend,
#字典的第二个key和对应的value 会被设置成x轴名称和坐标。
name_list_dict3 = {&quot;预报成员&quot;:[&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;],
&quot;检验指标&quot;:[&quot;TS评分&quot;,&quot;Bias评分&quot;,&quot;空报率&quot;,&quot;漏报率&quot;],
&quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
meb.bar(data3,name_list_dict=name_list_dict3,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/c7c62c2c1ccc706d32405beb194e7fb4?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">meb.bar(data3,name_list_dict=name_list_dict3,legend = &quot;预报成员&quot;,axis = &quot;时效(单位:小时)&quot;,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/692f460b6de38038920f27e84882d820?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python"># 设置子图标题,y轴的坐标名称,y轴坐标范围,条柱宽度,添加网格线,文字标注的有效位数
meb.bar(data3,name_list_dict=name_list_dict3,legend = &quot;预报成员&quot;,axis = &quot;时效(单位:小时)&quot;,
title = [&quot;TS&quot;,&quot;BIAS&quot;,&quot;空报率&quot;,&quot;漏报率&quot;], ylabel= &quot;&quot;, vmin = 0,vmax = 1.2,bar_width = 0.2,grid = True,tag = 1,dpi = 100) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/058e2d87a08afcd5a2ee85dc6f0d953d?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python"># 设置子图标题,y轴的坐标名称,y轴坐标范围,条柱宽度,添加网格线,文字标注的有效位数
meb.plot(data3,name_list_dict=name_list_dict3,legend = &quot;预报成员&quot;,axis = &quot;时效(单位:小时)&quot;,
title = [&quot;TS&quot;,&quot;BIAS&quot;,&quot;空报率&quot;,&quot;漏报率&quot;], ylabel= &quot;&quot;, vmin = 0,vmax = 1.2,grid = True,
tag = 1,dpi = 100
, ncol = 2, sup_title = &quot;随机测试数据的检验指标&quot;,color_list = [&quot;r&quot;,&quot;g&quot;,&quot;b&quot;]) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/2a2ccbba2ba9cc8c84f588cdb8ea487f" alt="" /></p>
<pre><code class="language-python"># 数据第1维size+1, 并标记为观测,在后续绘图中会自动选用蓝色条柱(或线条)绘制。
# 设置save_path 可将结果保存到指定位置,也可以设置width来指定整个画面的宽度
#data3_ = np.random.rand(4,4,10)
#name_list_dict3_ = {&quot;预报成员&quot;:[&quot;观测&quot;,&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;],
# &quot;检验指标&quot;:[&quot;TS评分&quot;,&quot;Bias评分&quot;,&quot;空报率&quot;,&quot;漏报率&quot;],
# &quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
meb.bar(data3,name_list_dict=name_list_dict3,axis = &quot;预报成员&quot;,legend = &quot;时效(单位:小时)&quot;,
title = [&quot;TS&quot;,&quot;BIAS&quot;,&quot;空报率&quot;,&quot;漏报率&quot;], ylabel= &quot;&quot;, vmin = 0,vmax = 1.2,grid = True,tag = 1,
dpi = 100,ncol = 1,
save_path = r&quot;H:\test_data\output\meb\plot_test.png&quot;,show = True,width =8,
sup_title = &quot;随机测试数据的检验指标\n(2020年01月01日20时累计降水量检验)&quot;,legend_col = 6) </code></pre>
<pre><code>检验结果已以图片形式保存至H:\test_data\output\meb\plot_test.png</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/e6625f4a7f5bd63c8beaf7d9ff77fa5e" alt="" /></p>
<pre><code class="language-python">#当axis = &quot;dayofyear&quot;时,会自动以日期形式展示横坐标,但其中不会包含年份
name_list_dict3 = {&quot;预报成员&quot;:[&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;],
&quot;检验指标&quot;:[&quot;TS评分&quot;,&quot;Bias评分&quot;,&quot;空报率&quot;,&quot;漏报率&quot;],
&quot;dayofyear&quot;:[1,11,21,31,41,51,61,71,81,91]}
meb.bar(data3,name_list_dict=name_list_dict3,dpi = 100,axis = &quot;dayofyear&quot;) </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/aa3d53eab84ea7794b653ad8a44224bc" alt="" /></p>
<pre><code class="language-python">name_list_dict1 = {
&quot;level(hPa)&quot;:[1000,925,850,800,700,600,500,400,300,200,100,50],
&quot;member&quot;:[&quot;OBS&quot;,&quot;FST&quot;],
&quot;dtime&quot;:[24,48,72]}
data3_h = np.random.randn(12,2,3)
meb.lineh(data3_h,name_list_dict=name_list_dict1,sup_title = &quot;评分的垂直廓线&quot;,axis = &quot;level(hPa)&quot;,legend = &quot;member&quot;,ncol = 3,
title = [&quot;24h&quot;,&quot;48h&quot;,&quot;72h&quot;],
xlabel=&quot;评分&quot;,grid = True, tag = 2,dpi = 100) # 坐标是时间时,会自动生成中文的时间坐标</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=d799196d10066af78e93585744b378b4&amp;file=file.png" alt="" /></p>
<h1>矩阵数据绘制_mesh</h1>
<p><font face="黑体" color=blue size = 3><strong>mesh(array,name_list_dict = None,axis_x = None,axis_y = None,cmap = "rainbow",clevs = None,ncol = None,annot =None,save_path = None,show = False,dpi = 300,
spasify_xticks = None,sup_fontsize = 10,title ="",width = None,height = None)</strong></font> </p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>array</font></strong></td>
<td style="text-align: left;">numpy 矩阵数据,暂时只支持2、3维的矩阵</td>
</tr>
<tr>
<td style="text-align: left;"><strong>name_list_dict</strong></td>
<td style="text-align: left;">以字典形式存储的每个维度的描述信息,其中字典的key为维度的名称,字典的value 为维度的坐标值的列表,列表中的元素只支持字符型 和 时间类型</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis_x</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应x轴的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis_y</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应y轴的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">各子图填色方案,取为缺省值是由程序自动设置。如果需要指定, 当只有1个子图或者每个子图采用相同的填色方案,则该参数matplotlibde 的cm对象,或者代表cm对象的字符串,或者代表meteva集成的配色方案的字符串,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数功能</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">各子图填色等级,取为默认值None时由程序自动设置。如果需要指定,当有多个子图,且每个子图需要设置不同等级时,该参数为2层嵌套的列表,否则该参数为1层的列表</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">如果存在多个子图,子图的列数将为ncol,缺省情况下回自动布局</td>
</tr>
<tr>
<td style="text-align: left;"><strong>annot</strong></td>
<td style="text-align: left;">当annot为正整数时会给每个格点添加数字标注,annot为数字标注的小数点后有效位数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">指定图片输出的文件路径</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">绘图的dpi参数,用法同matplotlib中dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>bar_width</strong></td>
<td style="text-align: left;">仅适用于bar函数,控制条柱的宽度,取值范围再0-1之间</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">各子图的标题,如果只有一个子图,title可以设为字符串, 缺省时无标题,当有多个子图时,title应该设置为字符串的列表,分别对应每个子图的标题,缺省时则自动根据name_list_dict中的维度和坐标信息来生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>spasify_xticks</strong></td>
<td style="text-align: left;">x轴坐标刻度的稀疏倍数,缺省时会自动进行稀疏化,当spasify_xticks = 1 时, 所有的刻度值都要显示, spasify_xticks = 2时,则间隔1个刻度进行显示,依次类推</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值</td>
</tr>
</tbody>
</table>
<h1>矩阵数据绘制_contourf</h1>
<p><font face="黑体" color=blue size = 3><strong>contourf(array,name_list_dict = None,axis_x = None,axis_y = None,cmap = "rainbow",clevs = None,ncol = None,annot =None,save_path = None,show = False,dpi = 300,
spasify_xticks = None,sup_fontsize = 10,title ="",width = None,height = None)</strong></font> </p>
<table>
<thead>
<tr>
<th style="text-align: left;">参数</th>
<th style="text-align: left;">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><strong><font face="黑体" color=blue size = 5>array</font></strong></td>
<td style="text-align: left;">numpy 矩阵数据,暂时只支持2、3维的矩阵</td>
</tr>
<tr>
<td style="text-align: left;"><strong>name_list_dict</strong></td>
<td style="text-align: left;">以字典形式存储的每个维度的描述信息,其中字典的key为维度的名称,字典的value 为维度的坐标值的列表,列表中的元素只支持字符型 和 时间类型</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis_x</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应x轴的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>axis_y</strong></td>
<td style="text-align: left;">在绘图时,期望在子图中对应y轴的维度的名称,它必须是name_list_dict 中的key</td>
</tr>
<tr>
<td style="text-align: left;"><strong>cmap</strong></td>
<td style="text-align: left;">各子图填色方案,取为缺省值是由程序自动设置。如果需要指定, 当只有1个子图或者每个子图采用相同的填色方案,则该参数matplotlibde 的cm对象,或者代表cm对象的字符串,或者代表meteva集成的配色方案的字符串,具体可参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">meb.def_cmap_clevs函数功能</a></td>
</tr>
<tr>
<td style="text-align: left;"><strong>clevs</strong></td>
<td style="text-align: left;">各子图填色等级,取为默认值None时由程序自动设置。如果需要指定,当有多个子图,且每个子图需要设置不同等级时,该参数为2层嵌套的列表,否则该参数为1层的列表</td>
</tr>
<tr>
<td style="text-align: left;"><strong>ncol</strong></td>
<td style="text-align: left;">如果存在多个子图,子图的列数将为ncol,缺省情况下回自动布局</td>
</tr>
<tr>
<td style="text-align: left;"><strong>annot</strong></td>
<td style="text-align: left;">当annot为正整数时会给每个格点添加数字标注,annot为数字标注的小数点后有效位数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>save_path</strong></td>
<td style="text-align: left;">指定图片输出的文件路径</td>
</tr>
<tr>
<td style="text-align: left;"><strong>show</strong></td>
<td style="text-align: left;">是否已plt.show()形式在屏幕显示图片</td>
</tr>
<tr>
<td style="text-align: left;"><strong>dpi</strong></td>
<td style="text-align: left;">绘图的dpi参数,用法同matplotlib中dpi参数</td>
</tr>
<tr>
<td style="text-align: left;"><strong>bar_width</strong></td>
<td style="text-align: left;">仅适用于bar函数,控制条柱的宽度,取值范围再0-1之间</td>
</tr>
<tr>
<td style="text-align: left;"><strong>title</strong></td>
<td style="text-align: left;">各子图的标题,如果只有一个子图,title可以设为字符串, 缺省时无标题,当有多个子图时,title应该设置为字符串的列表,分别对应每个子图的标题,缺省时则自动根据name_list_dict中的维度和坐标信息来生成标题</td>
</tr>
<tr>
<td style="text-align: left;"><strong>spasify_xticks</strong></td>
<td style="text-align: left;">x轴坐标刻度的稀疏倍数,缺省时会自动进行稀疏化,当spasify_xticks = 1 时, 所有的刻度值都要显示, spasify_xticks = 2时,则间隔1个刻度进行显示,依次类推</td>
</tr>
<tr>
<td style="text-align: left;"><strong>sup_fontsize</strong></td>
<td style="text-align: left;">图片标题的字体大小,其它字体将根据标题字体大小自动设置,其中坐标轴字体大小 = sup_fontsize <em> 0.9, 坐标刻度的字体大小 = sup_fontsize </em> 0.8</td>
</tr>
<tr>
<td style="text-align: left;"><strong>width</strong></td>
<td style="text-align: left;">图片的宽度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><strong>height</strong></td>
<td style="text-align: left;">图片的高度,缺省时程序自动设置</td>
</tr>
<tr>
<td style="text-align: left;"><font face="黑体" color=blue size=5>return</font></td>
<td style="text-align: left;">无返回值</td>
</tr>
</tbody>
</table>
<h2>2维示例</h2>
<pre><code class="language-python">data2 = np.random.rand(4,10)
data2[0,0] = np.nan # 设置缺省值
data2[1,1] = meb.IV # meteva支持的另一种缺省值
#通过name_list_dict设置了数据的维度属性和坐标值
name_list_dict2 = {&quot;预报成员&quot;:[&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;,&quot;SCMOC&quot;],
&quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
#字典的第一个key和对应的value会被设置成legend,
#字典的第二个key和对应的value 会被设置成x轴名称和坐标。
meb.mesh(data2,name_list_dict=name_list_dict2,axis_x = &quot;时效(单位:小时)&quot;,
axis_y = &quot;预报成员&quot;,annot = 1)</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/96be34fedef209c5f3b724cd2153a97e?showdoc=.jpg" alt="" /></p>
<h2>3维示例</h2>
<pre><code class="language-python">data3 = np.random.rand(3,4,10)
data3[:,1,:] = np.abs(np.random.randn(3,10)) * 2
#通过name_list_dict设置了数据的维度属性和坐标值
name_list_dict3 = {&quot;预报成员&quot;:[&quot;ECMWF&quot;,&quot;GRAPES&quot;,&quot;NCEP&quot;],
&quot;检验指标&quot;:[&quot;TS评分&quot;,&quot;Bias评分&quot;,&quot;空报率&quot;,&quot;漏报率&quot;],
&quot;时效(单位:小时)&quot;:[0,3,6,9,12,15,18,21,24,27]}
#字典的第一个key和对应的value会被设置成legend,
#字典的第二个key和对应的value 会被设置成x轴名称和坐标。
meb.mesh(data3,name_list_dict=name_list_dict3,axis_x = &quot;时效(单位:小时)&quot;,axis_y = &quot;预报成员&quot;,annot = 1,ncol =2,
cmap = [&quot;bwr&quot;,meb.cmaps.bias,&quot;bwr&quot;,&quot;bwr&quot;])</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/d428f0e3aac8cc61199cc31236f6bbd4?showdoc=.jpg" alt="" /></p>
<p>在上述示例中每幅子图设置了不同的cmap,当clev是有程序自动设置的,其中TS评分、空报率、漏报率的colorbar的取值范围是根据各自数值中的最大和最小值设置的,如果要将他们统一到相同的取值范围(比如0-1),可以参考如下设置方式:</p>
<pre><code class="language-python">cmap1,clev1 = meb.color_tools.def_cmap_clevs(clevs=None,cmap = &quot;bwr&quot;,vmin = 0,vmax = 1)
cmap2,clev2 = meb.color_tools.def_cmap_clevs(clevs=None,cmap = meb.cmaps.bias,vmin =0,vmax = 5)</code></pre>
<p>上述示例中函数meb.color_tools.reset_clevs_cmap,请参考<a href="https://www.showdoc.com.cn/meteva?page_id=3975606661430140">实用工具-color工具模块</a> </p>
<pre><code class="language-python">meb.mesh(data3,name_list_dict=name_list_dict3,axis_x = &quot;时效(单位:小时)&quot;,
axis_y = &quot;预报成员&quot;,annot = 1,ncol =2,
cmap = [cmap1,cmap2,cmap1,cmap1], clevs = [clev1,clev2,clev1,clev1])
# 由于clev1和clevs2都是列表,因此clevs是双层列表,
# cmap 是1层列表,其中元素是matplotlib的cm对象 </code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitfile/sign/98d6d0c9ab15f236cc8af3a87ba3fa77?showdoc=.jpg" alt="" /></p>
<pre><code class="language-python">data3 = np.random.randn(12,4,8)
#通过name_list_dict设置了数据的维度属性和坐标值
name_list_dict3 = { &quot;level(hPa)&quot;:[1000,925,850,800,700,600,500,400,300,200,100,50],
&quot;member&quot;:[&quot;ECMWF&quot;,&quot;CMA-GFS&quot;,&quot;CMA-MESO&quot;,&quot;NCEP&quot;],
&quot;时效(单位:小时)&quot;:[3,6,9,12,15,18,21,24]}
meb.contourf(data3,name_list_dict=name_list_dict3,axis_x = &quot;时效(单位:小时)&quot;,
axis_y = &quot;level(hPa)&quot;,annot = 1,ncol =2)</code></pre>
<p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=e33d3f4f00c77a9ebd0f76837ba55c23&amp;file=file.png" alt="" /></p>
<pre><code class="language-python"></code></pre>