matplotlib hist while ignoring a particular no data value
You can use a boolean array to select the required indices:
selected_values = (e_data > (no_data + eps)) & (e_data < (no_data - eps))pyplot.hist(e_data[selected_values])
(e_data > (no_data + eps))
will create an array of np.bool
with the same shape as e_data
, set to True
at a given index if and only if the value at that index is greater than (no_data + eps)
. &
is the element-wise and operator to satisfy both conditions.
Alternatively, if no_data
is just a convention, I would set those values to numpy.nan
instead, and use e_data[numpy.isfinite(e_data)]
.