Skip to content

Commit

Permalink
[ERT,CR,histograms] add parameter 'nr_of_bins' to histogram plotting
Browse files Browse the repository at this point in the history
function
  • Loading branch information
m-weigand committed Nov 8, 2019
1 parent c870726 commit f1e21f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/reda/containers/ERT.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def pseudosection(self, column='r', filename=None, log10=False, **kwargs):

def histogram(self, column='r', filename=None, log10=False, **kwargs):
"""Plot a histogram of one data column"""
return_dict = HS.plot_histograms(self.data, column)
return_dict = HS.plot_histograms(self.data, column, **kwargs)
if filename is not None:
return_dict['all'].savefig(filename, dpi=300)
return return_dict
Expand Down
15 changes: 12 additions & 3 deletions lib/reda/plotters/histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def plot_histograms(ertobj, keys, **kwargs):
log10plot : bool, optional
default: True
extra_dims : list, optional
?
nr_bins : None|int
if an int is given, use this as the number of bins, otherwise use a
heuristic.
Examples
--------
Expand Down Expand Up @@ -82,6 +86,9 @@ def plot_histograms(ertobj, keys, **kwargs):
subdata = subdata_raw[~np.isnan(subdata_raw)]
subdata = subdata[np.isfinite(subdata)]

nr_of_bins = kwargs.get('nr_of_bins', _get_nr_bins(subdata.size))
print('nr of bins', nr_of_bins)

subdata_log10_with_nan = np.log10(subdata[subdata > 0])
subdata_log10 = subdata_log10_with_nan[~np.isnan(
subdata_log10_with_nan)
Expand All @@ -97,7 +104,7 @@ def plot_histograms(ertobj, keys, **kwargs):
ax = axes[0]
ax.hist(
subdata,
_get_nr_bins(subdata.size),
nr_of_bins,
)
ax.set_xlabel(
units.get_label(key)
Expand All @@ -111,7 +118,7 @@ def plot_histograms(ertobj, keys, **kwargs):
ax = axes[1]
ax.hist(
subdata_log10,
_get_nr_bins(subdata.size),
nr_of_bins,
)
ax.set_xlabel(r'$log_{10}($' + units.get_label(key) + ')')
ax.set_ylabel('count')
Expand Down Expand Up @@ -302,7 +309,9 @@ def plot_histograms_extra_dims(dataobj, keys, primary_dim=None, **kwargs):
subdata_log10_with_nan)
]

subdata_log10 = subdata_log10[np.isfinite(subdata_log10)]
subdata_log10 = subdata_log10[
np.isfinite(subdata_log10)
]
subdata = subdata_log10

ax = axes.flat[index]
Expand Down

0 comments on commit f1e21f2

Please sign in to comment.