| 19 | # the script can alter/set/adjust to have them updated for |
| 20 | # further processing. |
| 21 | def make_plot(ins, outs): |
| 22 | |
| 23 | # figure position and row will increment |
| 24 | figure_position = 1 |
| 25 | row = 1 |
| 26 | |
| 27 | fig = plt.figure(figure_position, figsize=(6, 8.5), dpi=300) |
| 28 | |
| 29 | for key in ins: |
| 30 | dimension = ins[key] |
| 31 | ax = fig.add_subplot(len(ins.keys()), 1, row) |
| 32 | |
| 33 | # histogram the current dimension with 30 bins |
| 34 | n, bins, patches = ax.hist( dimension, 30, |
| 35 | density=0, |
| 36 | facecolor='grey', |
| 37 | alpha=0.75, |
| 38 | align='mid', |
| 39 | histtype='stepfilled', |
| 40 | linewidth=None) |
| 41 | |
| 42 | # Set plot particulars |
| 43 | ax.set_ylabel(key, size=10, rotation='horizontal') |
| 44 | ax.get_xaxis().set_visible(False) |
| 45 | ax.set_yticklabels('') |
| 46 | ax.set_yticks((),) |
| 47 | ax.set_xlim(min(dimension), max(dimension)) |
| 48 | ax.set_ylim(min(n), max(n)) |
| 49 | |
| 50 | # increment plot position |
| 51 | row = row + 1 |
| 52 | figure_position = figure_position + 1 |
| 53 | |
| 54 | # We will save the PNG bytes to a BytesIO instance |
| 55 | # and the nwrite that to a file. |
| 56 | output = BytesIO() |
| 57 | plt.savefig(output,format="PNG") |
| 58 | |
| 59 | # a module global variable, called 'pdalargs' is available |
| 60 | # to filters.programmable and filters.predicate modules that contains |
| 61 | # a dictionary of arguments that can be explicitly passed into |
| 62 | # the module by the user. We passed in a filename arg in our `pdal pipeline` call |
| 63 | filename = pdalargs['filename'] if 'filename' in pdalargs else 'histogram.png' |
| 64 | |
| 65 | # open up the filename and write out the |
| 66 | # bytes of the PNG stored in the BytesIO instance |
| 67 | with open(filename, 'wb') as o: |
| 68 | o.write(output.getvalue()) |
| 69 | |
| 70 | |
| 71 | # filters.programmable scripts need to |
| 72 | # return True to tell the filter it was successful. |
| 73 | return True |