代码拉取完成,页面将自动刷新
同步操作将从 刘胜胜/气象数据可视化,用matplotlib和basemap绘制micaps数据 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: utf-8 -*-
#
# Author: Liu xianyao
# Email: flashlxy@qq.com
# Update: 2017-04-11
# Copyright: ©江西省气象台 2017
# Version: 2.0.20170411
from __future__ import print_function
from Projection import Projection
class Legend:
def __init__(self, root):
p = root.find("Legend")
if p is None:
print(u'没有图例节点')
return
# 图例图片文件路径,图例叠加到产品图上的位置,为空表示自行生成图例
legend_pic = p.find("LegendPic").text
self.islegendpic = False
self.legendpic = ''
self.legendpos = [0, 0]
self.legendopacity = 1
if not (legend_pic is None or legend_pic.strip() == ''):
self.islegendpic = True
legend_pics = legend_pic.strip().split(',')
if 1 == len(legend_pics):
self.legendpic = legend_pics[0].strip()
elif 4 == len(legend_pics):
self.legendpic = legend_pics[0].strip()
self.legendpos = [float(legend_pics[1].strip()), float(legend_pics[2].strip())]
self.legendopacity = float(legend_pics[3].strip())
else:
self.legendpic = legend_pics[0].strip()
# 图例的延展类型:neither,min,max default is neither
self.extend = Projection.leaf_to_string(p, 'Extend', 'neither')
# 是否取MICAPS数据本身的图例值
self.micapslegendvalue = Projection.leaf_to_bool(p, "MicapsLegendValue", True, 'TRUE')
# When micapslegendvalue is true, the setting is working.
# if pin the legend values, [begin value, stop value, step] is working.default is None
# else use the data self legend values
self.pinlegendvalue = Projection.leaf_to_list(p, "PinLegendValue", None)
self.valid(self.pinlegendvalue)
# NCL colorbar 的别名
self.micapslegendcolor = Projection.leaf_to_string(p, 'MicapsLegendColor', 'ncl_default')
# 图例填充样式数组,一般和自定义的legend结合使用,如不够LegendValue数组的长度,则会用最后一个样式自动补齐
self.hatches = Projection.leaf_to_list(p, "Hatches", [''])
self.validhatches(self.hatches)
# 图例等级值
self.legendvalue = Projection.leaf_to_list(p, "LegendValue", None)
# 实际显示在图例上的值
self.legendvaluealias = Projection.leaf_to_list(p, "LegendValueAlias", None)
# 图例颜色值
self.legendcolor = Projection.leaf_to_list(p, "LegendColor", None)
# 图例抽稀间隔
self.thinning = Projection.leaf_to_int(p, "Thinning", 1)
# 图例字体
self.font = Projection.leaf_to_dict(p, "Font", None)
# 图例标题
self.title = Projection.leaf_to_string(p, 'Title', '')
# 图例标题字体
self.titlefont = Projection.leaf_to_dict(p, "TitleFont", None)
# 图例标题位置
self.titlepos = Projection.leaf_to_dict(p, "TitlePos",
{'rotation': 90, 'va': 'top', 'ha': 'center', 'ypercent': 0.5})
# ---------- 无投影时的图例配置 start --------
# 图例放置方式
self.orientation = Projection.leaf_to_string(p, 'Orientation', 'vertical')
# 图例离边框位置
self.anchor = Projection.leaf_to_list(p, "Anchor", [0, 0])
# 图例收缩系数
self.shrink = Projection.leaf_to_float(p, "Shrink", 1)
self.fraction = Projection.leaf_to_float(p, 'Fraction', 0.15)
# ---------- 有投影时的图例配置 start --------
# 图例收缩系数
self.size = Projection.leaf_to_string(leaf=p, code='Size', defvalue='5%')
# 图例离边框位置
self.pad = Projection.leaf_to_string(leaf=p, code='Pad', defvalue='2%')
# 图例放置位置
self.location = Projection.leaf_to_string(leaf=p, code='Location', defvalue='right')
def valid(self, pin):
if pin is not None and len(pin) == 3:
if pin[1] < pin[0] or pin[2] < 0:
self.pinlegendvalue = None
else:
self.pinlegendvalue = None
def validhatches(self, hatches):
hatches_list = ["", "/", "\\", "|", "-", "+", "x", "o", "O", ".", "*"]
if hatches is not None:
self.hatches = [a if a in hatches_list else '' for a in hatches]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。