forked from apryet/Qgridder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgridder_utils_plot.py
97 lines (72 loc) · 2.69 KB
/
qgridder_utils_plot.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
"""
/***************************************************************************
qgridder_utils_plot.py
Qgridder - A QGIS plugin
This file gathers functions which facilitate pre- and post-processing of
spatially distributed numerical models based on Qgridder grids.
Qgridder builds 2D regular and unstructured grids and comes together with
pre- and post-processing capabilities for spatially distributed modeling.
-------------------
begin : 2013-04-08
copyright : (C) 2013 by Pryet
email : alexandre.pryet@ensegid.fr
***************************************************************************/
This plugin uses functions from fTools
Copyright (C) 2008-2011 Carson Farmer
EMAIL: carson.farmer (at) gmail.com
WEB : http://www.ftools.ca/fTools.html
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
****
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import numpy as np
from math import *
from qgridder_utils_base import *
import ftools_utils
from matplotlib import pyplot as plt
import matplotlib.dates as mdates
# ======= Plot
def plot_chart(obs = {'t':[], 'val':[]}, simul = {'t':[], 'val':[]}, xlim = [], ylim = [], title=''):
"""
Draws a plot of observed and simulated records. Designed to accept dates from mdates on the x-axis.
Parameters
----------
obs : dictionary {'t':[], 'val':[] } with observed values
simul : dictionary {'t':[], 'val':[] } with observed values
Returns
-------
Examples
--------
"""
# initialize plot
axes = plt.axes()
axes.clear()
t_obs = obs['t']
val_obs = obs['val']
t_simul = simul['t']
val_simul = simul['val']
if len(xlim) == 2 :
axes.set_xlim(xlim[0],xlim[1])
if len(ylim) == 2 :
axes.set_ylim(ylim[0],ylim[1])
# plot records
axes.plot(t_obs,val_obs,'g+',label='Obs.')
axes.plot(t_simul,val_simul,'r-',label='Simul.')
# print plot decoration
axes.grid()
# plot title
axes.set_title(title)
# print plot decoration
l = axes.legend()
l.legendPatch.set_alpha(0.5)
# show plot
plt.show()