forked from flashlxy/PyMICAPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicapsFile.py
73 lines (70 loc) · 2.56 KB
/
MicapsFile.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
#
# Author: Liu xianyao
# Email: flashlxy@qq.com
# Update: 2017-04-06
# Copyright: ©江西省气象台 2017
# Version: 1.1.20170406
from __future__ import print_function
import os
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
from Contour import Contour
from File import File
from Legend import Legend
from Title import Title
from UV import UV
class MicapsFile:
def __init__(self, leaf):
self.file = File(leaf)
self.legend = Legend(leaf)
self.contour = Contour(leaf)
self.title = Title(leaf)
self.uv = UV(leaf)
@staticmethod
def DrawTitle(m, title, headtxt):
if m is plt:
if title.mtitleposition is None:
for desc in title.descs:
fontfile = r"C:\WINDOWS\Fonts\{0}".format(desc.font["family"])
if not os.path.exists(fontfile):
font = FontProperties(
size=desc.font["fontsize"], weight=desc.font["weight"]
)
else:
font = FontProperties(
fname=fontfile,
size=desc.font["fontsize"],
weight=desc.font["weight"],
)
plt.text(
desc.pos[0],
desc.pos[1],
desc.text,
# size=desc.font['fontsize'], weight=desc.font['weight'],
color=desc.font["color"],
fontdict=desc.font,
fontproperties=font,
rotation=0,
ha="left",
va="top",
)
else:
if title.mtitleposition == [0, 0]:
plt.title(headtxt, fontdict={"fontsize": 14})
else:
plt.text(
title.mtitleposition[0],
title.mtitleposition[1],
headtxt,
size=14,
weight="bold",
# color='blue',
# fontdict=desc.font,
# fontproperties=font,
rotation=0,
ha="left",
va="top",
)
else:
plt.title(headtxt)