-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_histo.py
78 lines (63 loc) · 2.54 KB
/
do_histo.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
import numpy
import numpy as np
# import matplotlib stuff and make sure to use the
# AGG renderer.
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
# This only works for Python 3. Use
# StringIO for Python 2.
from io import BytesIO
# The make_plot function will do all of our work. The
# filters.programmable filter expects a function name in the
# module that has at least two arguments -- "ins" which
# are numpy arrays for each dimension, and the "outs" which
# the script can alter/set/adjust to have them updated for
# further processing.
def make_plot(ins, outs):
# figure position and row will increment
figure_position = 1
row = 1
fig = plt.figure(figure_position, figsize=(6, 8.5), dpi=300)
for key in ins:
dimension = ins[key]
ax = fig.add_subplot(len(ins.keys()), 1, row)
# histogram the current dimension with 30 bins
n, bins, patches = ax.hist( dimension, 30,
density=0,
facecolor='grey',
alpha=0.75,
align='mid',
histtype='stepfilled',
linewidth=None)
print("-----------------------")
print(key)
print(n)
print(bins)
# Set plot particulars
ax.set_ylabel(key, size=10, rotation='horizontal')
ax.get_xaxis().set_visible(False)
ax.set_yticklabels('')
ax.set_yticks((),)
ax.set_xlim(min(dimension), max(dimension))
ax.set_ylim(min(n), max(n))
# increment plot position
row = row + 1
figure_position = figure_position + 1
# We will save the PNG bytes to a BytesIO instance
# and the nwrite that to a file.
output = BytesIO()
plt.savefig(output,format="PNG")
# a module global variable, called 'pdalargs' is available
# to filters.programmable and filters.predicate modules that contains
# a dictionary of arguments that can be explicitly passed into
# the module by the user. We passed in a filename arg in our `pdal pipeline` call
filename = pdalargs['filename'] if 'filename' in pdalargs else 'histogram.png'
# open up the filename and write out the
# bytes of the PNG stored in the BytesIO instance
with open(filename, 'wb') as o:
o.write(output.getvalue())
# filters.programmable scripts need to
# return True to tell the filter it was successful.
return True