Skip to content

Commit

Permalink
Added plotting of horizontal lines for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilipp committed May 15, 2018
1 parent 2eb7376 commit 6906685
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
9 changes: 9 additions & 0 deletions straditize/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,15 @@ def plot_samples(self, ax=None, *args, **kwargs):
self.sample_lines = self._plot_df(
self.sample_locs.loc[:, self.columns], ax, *args, **kwargs)

def plot_sample_hlines(self, ax=None, **kwargs):
ax = ax or self.ax
xmin, xmax = sorted(self.extent[:2])
y = self.sample_locs.index + min(self.extent[2:])
kwargs.setdefault('color', 'r')
if not len(y):
return
self.sample_hlines = [ax.hlines(y, xmin, xmax, **kwargs)]

def _plot_df(self, df, ax=None, *args, **kwargs):
vals = df.values
starts = self.column_starts
Expand Down
40 changes: 38 additions & 2 deletions straditize/widgets/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def __init__(self, straditizer_widgets, *args, **kwargs):
self.plot_potential_samples,
self.remove_potential_samples_plot,
self.can_plot_potential_samples)
self.add_item('Sample lines', self.get_samples_lines,
self.add_item('Samples', self.get_sample_hlines,
self.plot_sample_hlines, self.remove_sample_hlines_plot,
self.can_plot_sample_hlines)
self.add_item('Reconstruction', self.get_samples_lines,
self.plot_samples, self.remove_samples_plot,
self.can_plot_samples)
self.resizeColumnsToContents()
Expand Down Expand Up @@ -284,7 +287,40 @@ def can_plot_samples(self):
return (self.straditizer is not None and
self.straditizer.data_reader is not None and
self.straditizer.data_reader.full_df is not None and
self.straditizer.data_reader.sample_locs is not None)
self.straditizer.data_reader._sample_locs is not None)

# --------- plot horizontal sample lines ------------

def plot_sample_hlines(self):
"""Plot the :attr:`~straditize.binary.DataReader.full_df` of the reader
"""
stradi = self.straditizer
stradi.data_reader.plot_sample_hlines()
if stradi.magni is not None:
lines = stradi.data_reader.sample_hlines[:]
stradi.data_reader.plot_sample_hlines(ax=stradi.magni.ax)
stradi.data_reader.sample_hlines += lines

def remove_sample_hlines_plot(self):
stradi = self.straditizer
for l in stradi.data_reader.sample_hlines[:]:
try:
l.remove()
except ValueError:
pass
stradi.data_reader.sample_hlines.clear()

def get_sample_hlines(self):
try:
return self.straditizer.data_reader.sample_hlines
except AttributeError:
return []

def can_plot_sample_hlines(self):
return (self.straditizer is not None and
self.straditizer.data_reader is not None and
self.straditizer.data_reader.full_df is not None and
self.straditizer.data_reader._sample_locs is not None)

# --------- plot potential samples ------------

Expand Down
10 changes: 9 additions & 1 deletion tests/widgets/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ def test_plot_samples(self):
self.reader.digitize()
self.reader._get_sample_locs()
self.straditizer_widgets.refresh()
self._test_plot('Sample lines')
self._test_plot('Samples')

def test_plot_reconstruction(self):
self.init_reader()
self.reader.column_starts = self.column_starts
self.reader.digitize()
self.reader._get_sample_locs()
self.straditizer_widgets.refresh()
self._test_plot('Reconstruction')


if __name__ == '__main__':
Expand Down

0 comments on commit 6906685

Please sign in to comment.