29
29
to NumPy format file.
30
30
"""
31
31
32
+ import os
32
33
import sys
33
34
import docopt
34
35
import numpy as np
39
40
40
41
options = """
41
42
Usage:
42
- ./plot_cavity.py <cavity_npz> [--map-by <npy>]
43
+ ./plot_cavity.py <cavity_npz> [--save <fname> -- map-by <npy> --label <label >]
43
44
./plot_cavity.py (-h | --help)
44
45
45
46
Options:
46
- <cavity_npz> Compressed NumPy file with cavity specifications.
47
- --map-by <npy> NumPy format file with surface function to color-map finite elements.
48
- -h --help Show this screen.
47
+ <cavity_npz> Compressed NumPy file with cavity specifications.
48
+ --save <fname> Filename for the output picture, without extension.
49
+ A 600 dpi SVG is produced.
50
+ If left empty, the name of the .npz and the label are used.
51
+ --map-by <npy> NumPy format file with surface function to color-map finite elements.
52
+ --label <label> Label for the mapping colorbar.
53
+ If left empty, the NumPy filename will be used.
54
+ -h --help Show this screen.
49
55
"""
50
56
51
57
@@ -95,7 +101,7 @@ def shiftedColorMap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):
95
101
return newcmap
96
102
97
103
98
- def plot (cavity_npz , surf_func_npy = None ):
104
+ def plot (cavity_npz , save , surf_func_npy = None , label = None ):
99
105
fig = plt .figure ()
100
106
ax = fig .add_subplot (111 , projection = '3d' )
101
107
@@ -105,7 +111,7 @@ def plot(cavity_npz, surf_func_npy=None):
105
111
centroids = cavity ['centers' ]
106
112
107
113
# Plot collocation points
108
- ax .scatter (centroids [0 , :], centroids [1 , :], centroids [2 , :], c = 'black' , alpha = 0.5 )
114
+ ax .scatter (centroids [0 , :], centroids [1 , :], centroids [2 , :], c = 'black' , alpha = 0.5 , s = 5 )
109
115
110
116
# Generate color mapping
111
117
colors = (.5 , .1 , .3 , 0.3 )
@@ -114,7 +120,8 @@ def plot(cavity_npz, surf_func_npy=None):
114
120
shifted_cmap = shiftedColorMap (cm .coolwarm , midpoint = 0.75 , name = 'shifted' )
115
121
mappable = cm .ScalarMappable (cmap = shifted_cmap )
116
122
mappable .set_array (surf_func .flatten ())
117
- plt .colorbar (mappable )
123
+ cb = plt .colorbar (mappable )
124
+ cb .set_label (label )
118
125
# Provide colors for Poly3DCollection
119
126
colors = mappable .to_rgba (surf_func .flatten ())
120
127
# Generate list of vertices
@@ -126,6 +133,7 @@ def plot(cavity_npz, surf_func_npy=None):
126
133
elements = Poly3DCollection (vertices , facecolors = colors )
127
134
ax .add_collection3d (elements )
128
135
ax .set_axis_off ()
136
+ plt .savefig (os .path .join (os .getcwd (), save + '.svg' ), format = 'svg' , dpi = 600 , bbox_inches = 'tight' )
129
137
plt .show ()
130
138
131
139
@@ -137,8 +145,12 @@ def main():
137
145
sys .stderr .write (options )
138
146
sys .exit (- 1 )
139
147
cavity_npz = arguments ['<cavity_npz>' ]
148
+ cavity = os .path .splitext (cavity_npz )[0 ]
149
+ save = arguments ['--save' ] if arguments ['--save' ] else cavity
140
150
surf_func_npy = arguments ['--map-by' ]
141
- plot (cavity_npz , surf_func_npy )
151
+ surf_func = os .path .splitext (surf_func_npy )[0 ] if surf_func_npy else ''
152
+ label = arguments ['--label' ] if arguments ['--label' ] else surf_func
153
+ plot (cavity_npz , save , surf_func_npy , label )
142
154
143
155
144
156
if __name__ == '__main__' :
0 commit comments