geone 1.2.10__py311-none-manylinux_2_35_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- geone/__init__.py +30 -0
- geone/_version.py +6 -0
- geone/blockdata.py +232 -0
- geone/covModel.py +9725 -0
- geone/customcolors.py +490 -0
- geone/deesse_core/__init__.py +5 -0
- geone/deesse_core/_deesse.so +0 -0
- geone/deesse_core/deesse.py +2445 -0
- geone/deesseinterface.py +10181 -0
- geone/geosclassic_core/__init__.py +5 -0
- geone/geosclassic_core/_geosclassic.so +0 -0
- geone/geosclassic_core/geosclassic.py +1422 -0
- geone/geosclassicinterface.py +12336 -0
- geone/grf.py +5440 -0
- geone/img.py +6456 -0
- geone/imgplot.py +1367 -0
- geone/imgplot3d.py +1822 -0
- geone/multiGaussian.py +309 -0
- geone/pgs.py +1171 -0
- geone/randProcess.py +1122 -0
- geone/tools.py +762 -0
- geone-1.2.10.dist-info/LICENSE +58 -0
- geone-1.2.10.dist-info/METADATA +276 -0
- geone-1.2.10.dist-info/RECORD +26 -0
- geone-1.2.10.dist-info/WHEEL +5 -0
- geone-1.2.10.dist-info/top_level.txt +1 -0
geone/customcolors.py
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# -------------------------------------------------------------------------
|
|
5
|
+
# Python module: 'customcolors.py'
|
|
6
|
+
# author: Julien Straubhaar
|
|
7
|
+
# date: jan-2018
|
|
8
|
+
# -------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
Module for definition of custom colors and colormaps.
|
|
12
|
+
|
|
13
|
+
**Defined objects in this module**
|
|
14
|
+
|
|
15
|
+
- "default" color for "bad" value (nan)
|
|
16
|
+
- `cbad_def = (.9, .9, .9, 0.5)` : default color for "bad" value (nan)
|
|
17
|
+
|
|
18
|
+
- "default" color map
|
|
19
|
+
- `cmap_def`
|
|
20
|
+
|
|
21
|
+
- some colors from "libreoffice" (merci Christoph!)
|
|
22
|
+
- `col_chart01 = [x/255. for x in ( 0, 69, 134)]` : dark blue
|
|
23
|
+
- `col_chart02 = [x/255. for x in (255, 66, 14)]` : orange
|
|
24
|
+
- `col_chart03 = [x/255. for x in (255, 211, 32)]` : yellow
|
|
25
|
+
- `col_chart04 = [x/255. for x in ( 87, 157, 28)]` : green
|
|
26
|
+
- `col_chart05 = [x/255. for x in (126, 0, 33)]` : dark red
|
|
27
|
+
- `col_chart06 = [x/255. for x in (131, 202, 255)]` : light blue
|
|
28
|
+
- `col_chart07 = [x/255. for x in ( 49, 64, 4)]` : dark green
|
|
29
|
+
- `col_chart08 = [x/255. for x in (174, 207, 0)]` : light green
|
|
30
|
+
- `col_chart09 = [x/255. for x in ( 75, 31, 111)]` : purple
|
|
31
|
+
- `col_chart10 = [x/255. for x in (255, 149, 14)]` : dark yellow
|
|
32
|
+
- `col_chart11 = [x/255. for x in (197, 0, 11)]` : red
|
|
33
|
+
- `col_chart12 = [x/255. for x in ( 0, 132, 209)]` : blue
|
|
34
|
+
|
|
35
|
+
- ... with other names
|
|
36
|
+
- `col_chart_purple = col_chart09`
|
|
37
|
+
- `col_chart_darkblue = col_chart01`
|
|
38
|
+
- `col_chart_blue = col_chart12`
|
|
39
|
+
- `col_chart_lightblue = col_chart06`
|
|
40
|
+
- `col_chart_green = col_chart04`
|
|
41
|
+
- `col_chart_darkgreen = col_chart07`
|
|
42
|
+
- `col_chart_lightgreen = col_chart08`
|
|
43
|
+
- `col_chart_yellow = col_chart03`
|
|
44
|
+
- `col_chart_darkyellow = col_chart10`
|
|
45
|
+
- `col_chart_orange = col_chart02`
|
|
46
|
+
- `col_chart_red = col_chart11`
|
|
47
|
+
- `col_chart_darkred = col_chart05`
|
|
48
|
+
|
|
49
|
+
- ... in list
|
|
50
|
+
- `col_chart_list = [col_chart01, col_chart02, col_chart03, col_chart04, \
|
|
51
|
+
col_chart05, col_chart06, col_chart07, col_chart08, \
|
|
52
|
+
col_chart09, col_chart10, col_chart11, col_chart12]`
|
|
53
|
+
- `col_chart_list_s = [col_chart_list[i] for i in (8, 0, 11, 5, 3, 6, 7, 2, 9, 1, 10, 4)]`
|
|
54
|
+
|
|
55
|
+
- pre-defined colormaps
|
|
56
|
+
- `cmap1`, `cmap2`, `cmapW2B` (white to black), `cmapB2W` (black to white)
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
import numpy as np
|
|
60
|
+
import matplotlib.colors as mcolors
|
|
61
|
+
import matplotlib.pyplot as plt
|
|
62
|
+
|
|
63
|
+
from mpl_toolkits import axes_grid1
|
|
64
|
+
|
|
65
|
+
# ----------------------------------------------------------------------------
|
|
66
|
+
def add_colorbar(im, aspect=20.0, pad_fraction=1.0, **kwargs):
|
|
67
|
+
"""
|
|
68
|
+
Adds a vertical color bar to an image plot.
|
|
69
|
+
|
|
70
|
+
Parameters
|
|
71
|
+
----------
|
|
72
|
+
im : matplotlib.image.AxesImage
|
|
73
|
+
image (returned by `matplotlib.pyplot.imshow`)
|
|
74
|
+
|
|
75
|
+
aspect : float, default: 20.0
|
|
76
|
+
aspect ratio height over width of the color bar
|
|
77
|
+
|
|
78
|
+
pad_fraction : float, default: 1.0
|
|
79
|
+
padding fraction with respect to the color bar width; if w is the width
|
|
80
|
+
of the color bar, then the space between the image and the color bar will
|
|
81
|
+
be of with `pad_fraction` * w
|
|
82
|
+
|
|
83
|
+
kwargs : dict
|
|
84
|
+
keyword arguments passed to `im.axes.figure.colorbar`
|
|
85
|
+
|
|
86
|
+
Notes
|
|
87
|
+
-----
|
|
88
|
+
Code from https://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-colorbar.ipynb
|
|
89
|
+
"""
|
|
90
|
+
divider = axes_grid1.make_axes_locatable(im.axes)
|
|
91
|
+
width = axes_grid1.axes_size.AxesY(im.axes, aspect=1./aspect)
|
|
92
|
+
pad = axes_grid1.axes_size.Fraction(pad_fraction, width)
|
|
93
|
+
current_ax = plt.gca()
|
|
94
|
+
cax = divider.append_axes("right", size=width, pad=pad)
|
|
95
|
+
plt.sca(current_ax)
|
|
96
|
+
return im.axes.figure.colorbar(im, cax=cax, **kwargs)
|
|
97
|
+
# ----------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
# ----------------------------------------------------------------------------
|
|
100
|
+
def custom_cmap(cseq,
|
|
101
|
+
vseq=None,
|
|
102
|
+
ncol=256,
|
|
103
|
+
cunder=None,
|
|
104
|
+
cover=None,
|
|
105
|
+
cbad=None,
|
|
106
|
+
alpha=None,
|
|
107
|
+
cmap_name='custom_cmap'):
|
|
108
|
+
"""
|
|
109
|
+
Defines a custom color map given colors at transition values.
|
|
110
|
+
|
|
111
|
+
Parameters
|
|
112
|
+
----------
|
|
113
|
+
cseq : 1D array-like
|
|
114
|
+
sequence of colors, each color is given by a
|
|
115
|
+
3-tuple (RGB code), 4-tuple (RGBA code) or string
|
|
116
|
+
|
|
117
|
+
vseq : 1D array-like of floats, optional
|
|
118
|
+
sequence of increasing values of same length as `cseq`, values that
|
|
119
|
+
correspond to the colors given in `cseq` in the output color map;
|
|
120
|
+
by default (`None`): equally spaced values (from 0 to 1) are used
|
|
121
|
+
|
|
122
|
+
ncol : int, default: 256
|
|
123
|
+
number of colors for the color map
|
|
124
|
+
|
|
125
|
+
cunder : object defining a color (e.g. 3-tuple, str), optional
|
|
126
|
+
color (3-tuple (RGB code), 4-tuple (RGBA code) or str), used for
|
|
127
|
+
"under" values
|
|
128
|
+
|
|
129
|
+
cover : object defining a color (e.g. 3-tuple, str), optional
|
|
130
|
+
color (3-tuple (RGB code), 4-tuple (RGBA code) or str), used for
|
|
131
|
+
"over" values
|
|
132
|
+
|
|
133
|
+
cbad : object defining a color (e.g. 3-tuple, str), optional
|
|
134
|
+
color (3-tuple (RGB code), 4-tuple (RGBA code) or str), used for
|
|
135
|
+
"bad" values
|
|
136
|
+
|
|
137
|
+
alpha : 1D array-like of floats, or float, optional
|
|
138
|
+
values of the "alpha" channel (for transparency), for each color in
|
|
139
|
+
`cseq` (if a `alpha` is a float, the same value is used for every color)
|
|
140
|
+
|
|
141
|
+
cmap_name : str, default: 'custom_cmap'
|
|
142
|
+
name of the output color map
|
|
143
|
+
|
|
144
|
+
Returns
|
|
145
|
+
-------
|
|
146
|
+
colormap : `matplotlib.colors.LinearSegmentedColormap`
|
|
147
|
+
color map
|
|
148
|
+
|
|
149
|
+
Examples
|
|
150
|
+
--------
|
|
151
|
+
>>> # # Import if needed
|
|
152
|
+
>>> # import numpy as np
|
|
153
|
+
>>> # import matplotlib.pyplot as plt
|
|
154
|
+
>>> #
|
|
155
|
+
>>> # Set min and max value to be displayed
|
|
156
|
+
>>> vmin, vmax = -1.0, 3.0
|
|
157
|
+
>>> #
|
|
158
|
+
>>> # Create a custom colormap
|
|
159
|
+
>>> # - from blue to white for values from vmin to 0
|
|
160
|
+
>>> # - from white to red for values from 0 to vmax
|
|
161
|
+
>>> # - with specified colors for "under", "over" and "bad" values
|
|
162
|
+
>>> my_cmap = custom_cmap(
|
|
163
|
+
>>> ('blue', 'white', 'red'), vseq=(vmin,0,vmax),
|
|
164
|
+
>>> cunder='cyan', cover='violet', cbad='gray', alpha=1)
|
|
165
|
+
>>> #
|
|
166
|
+
>>> # Array of values to display
|
|
167
|
+
>>> zz = np.linspace(-2, 4, 500).reshape(10, 50)
|
|
168
|
+
>>> zz[:, 20:25] = np.nan
|
|
169
|
+
>>> #
|
|
170
|
+
>>> # Show the array, specifiying min, max and the color map
|
|
171
|
+
>>> im = plt.imshow(zz, vmin=vmin, vmax=vmax, cmap=my_cmap)
|
|
172
|
+
>>> add_colorbar(im, aspect=5., extend='both') # add color bar
|
|
173
|
+
>>> plt.show()
|
|
174
|
+
"""
|
|
175
|
+
fname = 'custom_cmap'
|
|
176
|
+
|
|
177
|
+
# Set alpha sequence
|
|
178
|
+
if alpha is None:
|
|
179
|
+
alpha = 1.0
|
|
180
|
+
aseq = np.asarray(alpha, dtype=float) # numpy.ndarray (possibly 0-dimensional)
|
|
181
|
+
if aseq.size == 1:
|
|
182
|
+
aseq = aseq.flat[0] * np.ones(len(cseq))
|
|
183
|
+
elif aseq.size != len(cseq):
|
|
184
|
+
print(f'ERROR ({fname}): length of `alpha` not compatible with `cseq`')
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
# Set vseqn: sequence of values rescaled in [0,1]
|
|
188
|
+
if vseq is not None:
|
|
189
|
+
if len(vseq) != len(cseq):
|
|
190
|
+
print(f'ERROR ({fname}): length of `vseq` and `cseq` differs')
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
if sum(np.diff(vseq) <= 0.0 ):
|
|
194
|
+
print(f'ERROR ({fname}): `vseq` is not an increasing sequence')
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
# Linearly rescale vseq on [0,1]
|
|
198
|
+
vseqn = (np.array(vseq,dtype=float) - vseq[0]) / (vseq[-1] - vseq[0])
|
|
199
|
+
|
|
200
|
+
else:
|
|
201
|
+
vseqn = np.linspace(0,1,len(cseq))
|
|
202
|
+
|
|
203
|
+
# Set cseqRGB: sequence of colors as RGB-tuples
|
|
204
|
+
cseqRGB = []
|
|
205
|
+
for c in cseq:
|
|
206
|
+
try:
|
|
207
|
+
cseqRGB.append(mcolors.ColorConverter().to_rgb(c))
|
|
208
|
+
except:
|
|
209
|
+
cseqRGB.append(c)
|
|
210
|
+
|
|
211
|
+
# Set dictionary to define the color map
|
|
212
|
+
cdict = {
|
|
213
|
+
'red' :[(vseqn[i], cseqRGB[i][0], cseqRGB[i][0]) for i in range(len(cseq))],
|
|
214
|
+
'green':[(vseqn[i], cseqRGB[i][1], cseqRGB[i][1]) for i in range(len(cseq))],
|
|
215
|
+
'blue' :[(vseqn[i], cseqRGB[i][2], cseqRGB[i][2]) for i in range(len(cseq))],
|
|
216
|
+
'alpha':[(vseqn[i], aseq[i], aseq[i]) for i in range(len(cseq))]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
cmap = mcolors.LinearSegmentedColormap(cmap_name, cdict, N=ncol)
|
|
220
|
+
|
|
221
|
+
if cunder is not None:
|
|
222
|
+
try:
|
|
223
|
+
cmap.set_under(mcolors.ColorConverter().to_rgba(cunder))
|
|
224
|
+
except:
|
|
225
|
+
cmap.set_under(cunder)
|
|
226
|
+
|
|
227
|
+
if cover is not None:
|
|
228
|
+
try:
|
|
229
|
+
cmap.set_over(mcolors.ColorConverter().to_rgba(cover))
|
|
230
|
+
except:
|
|
231
|
+
cmap.set_over(cover)
|
|
232
|
+
|
|
233
|
+
if cbad is not None:
|
|
234
|
+
try:
|
|
235
|
+
cmap.set_bad(mcolors.ColorConverter().to_rgba(cbad))
|
|
236
|
+
except:
|
|
237
|
+
cmap.set_bad(cbad)
|
|
238
|
+
|
|
239
|
+
return cmap
|
|
240
|
+
# ----------------------------------------------------------------------------
|
|
241
|
+
|
|
242
|
+
# Default colormap for function in geone
|
|
243
|
+
# ======================================
|
|
244
|
+
cmap_def = 'viridis'
|
|
245
|
+
|
|
246
|
+
# Some colors and colormaps
|
|
247
|
+
# =========================
|
|
248
|
+
|
|
249
|
+
# Chart color from libreoffice (merci Christoph)
|
|
250
|
+
col_chart01 = [x/255. for x in ( 0, 69, 134)] # dark blue
|
|
251
|
+
col_chart02 = [x/255. for x in (255, 66, 14)] # orange
|
|
252
|
+
col_chart03 = [x/255. for x in (255, 211, 32)] # yellow
|
|
253
|
+
col_chart04 = [x/255. for x in ( 87, 157, 28)] # green
|
|
254
|
+
col_chart05 = [x/255. for x in (126, 0, 33)] # dark red
|
|
255
|
+
col_chart06 = [x/255. for x in (131, 202, 255)] # light blue
|
|
256
|
+
col_chart07 = [x/255. for x in ( 49, 64, 4)] # dark green
|
|
257
|
+
col_chart08 = [x/255. for x in (174, 207, 0)] # light green
|
|
258
|
+
col_chart09 = [x/255. for x in ( 75, 31, 111)] # purple
|
|
259
|
+
col_chart10 = [x/255. for x in (255, 149, 14)] # dark yellow
|
|
260
|
+
col_chart11 = [x/255. for x in (197, 0, 11)] # red
|
|
261
|
+
col_chart12 = [x/255. for x in ( 0, 132, 209)] # blue
|
|
262
|
+
|
|
263
|
+
# ... other names
|
|
264
|
+
col_chart_purple = col_chart09
|
|
265
|
+
col_chart_darkblue = col_chart01
|
|
266
|
+
col_chart_blue = col_chart12
|
|
267
|
+
col_chart_lightblue = col_chart06
|
|
268
|
+
col_chart_green = col_chart04
|
|
269
|
+
col_chart_darkgreen = col_chart07
|
|
270
|
+
col_chart_lightgreen = col_chart08
|
|
271
|
+
col_chart_yellow = col_chart03
|
|
272
|
+
col_chart_darkyellow = col_chart10
|
|
273
|
+
col_chart_orange = col_chart02
|
|
274
|
+
col_chart_red = col_chart11
|
|
275
|
+
col_chart_darkred = col_chart05
|
|
276
|
+
|
|
277
|
+
# ... list
|
|
278
|
+
col_chart_list = [col_chart01, col_chart02, col_chart03, col_chart04,
|
|
279
|
+
col_chart05, col_chart06, col_chart07, col_chart08,
|
|
280
|
+
col_chart09, col_chart10, col_chart11, col_chart12]
|
|
281
|
+
|
|
282
|
+
# ... list reordered
|
|
283
|
+
col_chart_list_s = [col_chart_list[i] for i in (8, 0, 11, 5, 3, 6, 7, 2, 9, 1, 10, 4)]
|
|
284
|
+
|
|
285
|
+
# Default color for bad value (nan)
|
|
286
|
+
cbad_def = (.9, .9, .9, 0.5)
|
|
287
|
+
|
|
288
|
+
# Pre-defined colormaps
|
|
289
|
+
# =====================
|
|
290
|
+
|
|
291
|
+
# colormap cmap1 / cmap1_alpha (increasing alpha values)
|
|
292
|
+
# --------------
|
|
293
|
+
cbad1 = (.9, .9, .9, 0.5)
|
|
294
|
+
# cunder1 = [x/255. for x in (160, 40, 160)] + [0.5] # +[0.5] ... for appending alpha channel
|
|
295
|
+
# cover1 = [x/255. for x in (250, 80, 120)] + [0.5] # +[0.5] ... for appending alpha channel
|
|
296
|
+
cunder1 = [x/255. for x in (200, 10, 250)] + [0.5] # +[0.5] ... for appending alpha channel
|
|
297
|
+
cover1 = [x/255. for x in (250, 10, 10)] + [0.5] # +[0.5] ... for appending alpha channel
|
|
298
|
+
cmaplist1 = ([x/255. for x in (160, 40, 240)],
|
|
299
|
+
[x/255. for x in ( 0, 240, 240)],
|
|
300
|
+
[x/255. for x in (240, 240, 0)],
|
|
301
|
+
[x/255. for x in (180, 10, 10)])
|
|
302
|
+
cmap1 = custom_cmap(cmaplist1, cunder=cunder1, cover=cover1, cbad=cbad1, alpha=1.0)
|
|
303
|
+
cmap1_alpha = custom_cmap(cmaplist1, alpha=np.linspace(0, 1, len(cmaplist1)), cunder=cunder1, cover=cover1, cbad=cbad1)
|
|
304
|
+
|
|
305
|
+
# colormap cmap2 / cmap2_alpha (increasing alpha values)
|
|
306
|
+
# --------------
|
|
307
|
+
cmaplist2 = ['purple', 'blue', 'cyan', 'yellow', 'red', 'black']
|
|
308
|
+
cbad2 = cbad_def
|
|
309
|
+
cunder2 = cbad_def
|
|
310
|
+
cover2 = cbad_def
|
|
311
|
+
cmap2 = custom_cmap(cmaplist2, cunder=cunder2, cover=cover2, cbad=cbad2, alpha=1.0)
|
|
312
|
+
cmap2_alpha = custom_cmap(cmaplist2, alpha=np.linspace(0, 2, len(cmaplist2)), cunder=cunder2, cover=cover2, cbad=cbad2)
|
|
313
|
+
|
|
314
|
+
# colormap cmapW2B / cmapB2W (white to black / black to white)
|
|
315
|
+
# --------------
|
|
316
|
+
cmapW2B = custom_cmap(['white', 'black'], cunder=(0.0, 0.0, 1.0, 0.5), cover=(1.0, 0.0, 0.0, 0.5), cbad=col_chart_yellow+[0.5], alpha=1.0)
|
|
317
|
+
cmapB2W = custom_cmap(['black', 'white'], cunder=(0.0, 0.0, 1.0, 0.5), cover=(1.0, 0.0, 0.0, 0.5), cbad=col_chart_yellow+[0.5], alpha=1.0)
|
|
318
|
+
|
|
319
|
+
# "Extended" existing colormap from matplotlib, by adding specific colors for under values, over values and bad values
|
|
320
|
+
# # Example for cmap 'terrain'
|
|
321
|
+
# cmap_terrain_ext = custom_cmap([plt.get_cmap('terrain')(x) for x in np.linspace(0, 1, 256)], ncol=256, cunder='pink', cover='orange', cbad='red')
|
|
322
|
+
# # or:
|
|
323
|
+
# cmap_terrain_ext = plt.get_cmap('terrain')
|
|
324
|
+
# cmap_terrain_ext.set_under('pink')
|
|
325
|
+
# cmap_terrain_ext.set_over('orange')
|
|
326
|
+
# cmap_terrain_ext.set_bad('red')
|
|
327
|
+
# ----------------------------------------------------------------------------
|
|
328
|
+
#
|
|
329
|
+
# # Notes:
|
|
330
|
+
# # =====
|
|
331
|
+
# # To show available colormaps in matplotlib:
|
|
332
|
+
# plt.colormaps()
|
|
333
|
+
#
|
|
334
|
+
# # To show some colormaps (LinearSegmentedColormap) from matplotlib:
|
|
335
|
+
# cm_name = [name for name in plt.cm.datad.keys()]
|
|
336
|
+
# cmap = plt.get_cmap('ocean') # get the colormap named 'ocean' (cm_name[105])
|
|
337
|
+
#
|
|
338
|
+
# # To get current rcParams (matplotlib)
|
|
339
|
+
# import matplotlib
|
|
340
|
+
# matplotlib.rcParams
|
|
341
|
+
#
|
|
342
|
+
# # Useful function to convert color from/to rgb[a]/hex:
|
|
343
|
+
# import matplotlib
|
|
344
|
+
# matplotlib.mcolors.to_rgb()
|
|
345
|
+
# matplotlib.mcolors.to_rgba()
|
|
346
|
+
# matplotlib.mcolors.to_hex()
|
|
347
|
+
# matplotlib.mcolors.to_hex(,keep_alpha=True)
|
|
348
|
+
# ----------------------------------------------------------------------------
|
|
349
|
+
|
|
350
|
+
if __name__ == "__main__":
|
|
351
|
+
print("Module 'geone.customcolors' example:")
|
|
352
|
+
import matplotlib.pyplot as plt
|
|
353
|
+
|
|
354
|
+
# Plot a function of two variable in a given domain
|
|
355
|
+
# Set domain and number of cell in each direction
|
|
356
|
+
xmin, xmax = -2, 2
|
|
357
|
+
ymin, ymax = -1, 2
|
|
358
|
+
nx, ny = 200, 150
|
|
359
|
+
|
|
360
|
+
# Set the cell size
|
|
361
|
+
sx, sy = (xmax-xmin)/nx, (ymax-ymin)/ny
|
|
362
|
+
|
|
363
|
+
# Set the meshgrid
|
|
364
|
+
x, y = xmin + 0.5 * sx + sx * np.arange(nx), ymin + 0.5 * sy + sy * np.arange(ny)
|
|
365
|
+
# # equivalently:
|
|
366
|
+
# x, y = np.arange(xmin+sx/2, xmax, sx), np.arange(ymin+sy/2, ymax ,sy)
|
|
367
|
+
# x, y = np.linspace(xmin+sx/2, xmax-sx/2, nx), np.linspace(ymin+sy/2, ymax-sy/2, ny)
|
|
368
|
+
xx,yy = np.meshgrid(x,y)
|
|
369
|
+
|
|
370
|
+
# Set the function values
|
|
371
|
+
zz = xx**2 + yy**2 - 2
|
|
372
|
+
zz[np.where(zz < -1.7)] = np.nan
|
|
373
|
+
|
|
374
|
+
# Specify some points in the grid
|
|
375
|
+
px = np.arange(xmin,xmax,.1)
|
|
376
|
+
py = np.zeros(len(px))
|
|
377
|
+
pz = px**2 + py**2 - 2
|
|
378
|
+
pz[np.where(pz < -1.7)] = np.nan
|
|
379
|
+
|
|
380
|
+
# Set min and max value to be displayed
|
|
381
|
+
vmin, vmax = -1.0, 3.0
|
|
382
|
+
|
|
383
|
+
# Create a custom colormap
|
|
384
|
+
my_cmap = custom_cmap(('blue', 'white', 'red'), vseq=(vmin,0,vmax),
|
|
385
|
+
cunder='cyan', cover='violet', cbad='gray', alpha=.3)
|
|
386
|
+
|
|
387
|
+
# Display
|
|
388
|
+
fig, ax = plt.subplots(2,2,figsize=(16,10))
|
|
389
|
+
# --- 1st plot ---
|
|
390
|
+
cax = ax[0,0]
|
|
391
|
+
im_plot = cax.imshow(zz, cmap=cmap1, vmin=vmin, vmax=vmax, origin='lower',
|
|
392
|
+
extent=[xmin, xmax, ymin, ymax], interpolation='none')
|
|
393
|
+
cax.set_xlim(xmin, xmax)
|
|
394
|
+
cax.set_ylim(ymin, ymax)
|
|
395
|
+
cax.grid()
|
|
396
|
+
cax.set_xlabel("x-axis")
|
|
397
|
+
cax.set_xticks([-1, 1])
|
|
398
|
+
cax.set_xticklabels(['x=-1', 'x=1'], fontsize=8)
|
|
399
|
+
|
|
400
|
+
# cbarShrink = 0.9
|
|
401
|
+
# plt.colorbar(extend='both', shrink=cbarShrink, aspect=20*cbarShrink)
|
|
402
|
+
add_colorbar(im_plot, extend='both')
|
|
403
|
+
|
|
404
|
+
# add points
|
|
405
|
+
col = [0 for i in range(len(pz))]
|
|
406
|
+
for i in range(len(pz)):
|
|
407
|
+
if ~ np.isnan(pz[i]):
|
|
408
|
+
col[i] = cmap1((pz[i]-vmin)/(vmax-vmin))
|
|
409
|
+
else:
|
|
410
|
+
col[i] = mcolors.ColorConverter().to_rgba(cbad1)
|
|
411
|
+
|
|
412
|
+
cax.scatter(px, py, marker='o', s=50, edgecolor='black', color=col)
|
|
413
|
+
cax.set_title('colormap: cmap1')
|
|
414
|
+
|
|
415
|
+
# --- 2nd plot ---
|
|
416
|
+
plt.subplot(2,2,2)
|
|
417
|
+
im_plot = plt.imshow(zz,cmap=my_cmap, vmin=vmin, vmax=vmax, origin='lower',
|
|
418
|
+
extent=[xmin, xmax, ymin, ymax], interpolation='none')
|
|
419
|
+
plt.grid()
|
|
420
|
+
|
|
421
|
+
cbar = add_colorbar(im_plot, ticks=[vmin,vmax])
|
|
422
|
+
# cbar.ax.set_yticklabels(cbar.get_ticks(), fontsize=16)
|
|
423
|
+
cbar.set_ticks([vmin, 0, vmax])
|
|
424
|
+
cbar.ax.set_yticklabels(["min={}".format(vmin), 0, "max={}".format(vmax)],
|
|
425
|
+
fontsize=16)
|
|
426
|
+
|
|
427
|
+
col = [0 for i in range(len(pz))]
|
|
428
|
+
for i in range(len(pz)):
|
|
429
|
+
if not np.isnan(pz[i]):
|
|
430
|
+
col[i] = my_cmap((pz[i]-vmin)/(vmax-vmin))
|
|
431
|
+
else:
|
|
432
|
+
col[i] = mcolors.ColorConverter().to_rgba('gray')
|
|
433
|
+
|
|
434
|
+
# add points
|
|
435
|
+
plt.scatter(px, py, marker='o', s=50, edgecolor='black', color=col)
|
|
436
|
+
|
|
437
|
+
plt.title('colormap: my_cmap')
|
|
438
|
+
|
|
439
|
+
# --- 3rd plot ---
|
|
440
|
+
plt.subplot(2,2,3)
|
|
441
|
+
im_plot = plt.imshow(zz, cmap=custom_cmap(col_chart_list, ncol=len(col_chart_list)),
|
|
442
|
+
vmin=vmin, vmax=vmax, origin='lower',
|
|
443
|
+
extent=[xmin,xmax,ymin,ymax], interpolation='none')
|
|
444
|
+
plt.grid()
|
|
445
|
+
# plt.colorbar(shrink=cbarShrink, aspect=20*cbarShrink)
|
|
446
|
+
add_colorbar(im_plot)
|
|
447
|
+
|
|
448
|
+
#col = custom_cmap(col_chart_list, ncol=len(col_chart_list))((pz-vmin)/(vmax-vmin))
|
|
449
|
+
col = [0 for i in range(len(pz))]
|
|
450
|
+
for i in range(len(pz)):
|
|
451
|
+
if ~ np.isnan(pz[i]):
|
|
452
|
+
col[i] = custom_cmap(col_chart_list, ncol=len(col_chart_list))((pz[i]-vmin)/(vmax-vmin))
|
|
453
|
+
else:
|
|
454
|
+
col[i] = mcolors.ColorConverter().to_rgba('white')
|
|
455
|
+
|
|
456
|
+
plt.scatter(px, py, marker='o', s=50, edgecolor='black', color=col)
|
|
457
|
+
|
|
458
|
+
plt.title('colormap: col_chart_list')
|
|
459
|
+
|
|
460
|
+
# --- 4th plot ---
|
|
461
|
+
plt.subplot(2,2,4)
|
|
462
|
+
im_plot = plt.imshow(zz, cmap=custom_cmap(col_chart_list_s,
|
|
463
|
+
ncol=len(col_chart_list_s)),
|
|
464
|
+
vmin=vmin, vmax=vmax, origin='lower',
|
|
465
|
+
extent=[xmin, xmax, ymin, ymax], interpolation='none')
|
|
466
|
+
plt.grid()
|
|
467
|
+
# plt.colorbar(shrink=cbarShrink, aspect=20*cbarShrink)
|
|
468
|
+
add_colorbar(im_plot)
|
|
469
|
+
|
|
470
|
+
#col = custom_cmap(col_chart_list_s, ncol=len(col_chart_list_s))((pz-vmin)/(vmax-vmin))
|
|
471
|
+
col = [0 for i in range(len(pz))]
|
|
472
|
+
for i in range(len(pz)):
|
|
473
|
+
if ~ np.isnan(pz[i]):
|
|
474
|
+
col[i] = custom_cmap(col_chart_list_s, ncol=len(col_chart_list_s))((pz[i]-vmin)/(vmax-vmin))
|
|
475
|
+
else:
|
|
476
|
+
col[i] = mcolors.ColorConverter().to_rgba('white')
|
|
477
|
+
|
|
478
|
+
plt.scatter(px, py, marker='o', s=50, edgecolor='black', color=col)
|
|
479
|
+
|
|
480
|
+
plt.title('colormap: col_chart_list_s')
|
|
481
|
+
|
|
482
|
+
# main title
|
|
483
|
+
plt.suptitle(r'$z=x^2 + y^2 - 2$', fontsize=24)
|
|
484
|
+
|
|
485
|
+
# plt.tight_layout()
|
|
486
|
+
|
|
487
|
+
# fig.show()
|
|
488
|
+
plt.show()
|
|
489
|
+
|
|
490
|
+
a = input("Press enter to continue...")
|
|
Binary file
|