def test_to_bins(self): vals = [-0.1, 0.5, 0.8] xbins = self.plotter.to_bins(vals, 0) assert_items_almost_equal(xbins, [-0.2, 1.0, 1.6]) ybins = self.plotter.to_bins(vals, 1) assert_items_almost_equal(ybins, [0.0, 2.0, 3.0]) assert_equal(self.plotter.to_bins(None, 0), None)
def test_cumulative(self): histo = Histogram(n_bins=5) hist = histo.histogram(self.data) cumulative = histo.cumulative(None).values() assert_items_almost_equal(cumulative, [5.0, 5.0, 7.0, 8.0, 9.0, 10.0]) assert_items_almost_equal(histo.cumulative(maximum=1.0), [0.5, 0.5, 0.7, 0.8, 0.9, 1.0])
def test_reverse_cumulative(self): histo = Histogram(n_bins=5) hist = histo.histogram(self.data) assert_items_almost_equal(histo.reverse_cumulative(), [10, 5, 5, 3, 2]) assert_items_almost_equal(histo.reverse_cumulative(maximum=1.0), [1.0, 0.5, 0.5, 0.3, 0.2])
def test_map_to_float_bins_cvtraj(self): hist = PathDensityHistogram(self.cvs, self.left_bin_edges, self.bin_widths) cv_traj = [[0.6, 0.564642473395035, 0.36], [0.7, 0.644217687237691, 0.49]] bin_traj = hist.map_to_float_bins(cv_traj) assert_items_almost_equal(bin_traj[0], [2.4, 1.12928494679007, 0.9]) assert_items_almost_equal(bin_traj[1], [2.8, 1.28843537447538, 1.225])
def test_reverse_cumulative(self): histo = Histogram(n_bins=5) hist = histo.histogram(self.data) rev_cumulative = histo.reverse_cumulative(maximum=None) assert_items_almost_equal(rev_cumulative.values(), [10, 5, 5, 3, 2, 1]) rev_cumulative = histo.reverse_cumulative(maximum=1.0) assert_items_almost_equal(rev_cumulative.values(), [1.0, 0.5, 0.5, 0.3, 0.2, 0.1])
def test_ticks_and_labels(self): # mock axes, make sure they work as expected fake_ax = MockAxes([-1.0, 0.0, 1.0], [-6.0, 0.0, 6.0]) assert_items_equal(fake_ax.get_xticks(), [-1.0, 0.0, 1.0]) assert_items_equal(fake_ax.get_yticks(), [-6.0, 0.0, 6.0]) old_format = self.plotter.label_format self.plotter.label_format = "{:4.2f}" xticks, xlabels = self.plotter.ticks_and_labels( ticks=[-2.0, -1.0, 0.0, 1.0, 2.0], ax=fake_ax, dof=0) assert_items_almost_equal(xticks, [-2.0, -1.0, 0.0, 1.0, 2.0]) assert_items_equal(xlabels, ["-1.00", "-0.50", "0.00", "0.50", "1.00"]) yticks, ylabels = self.plotter.ticks_and_labels(ticks=None, ax=fake_ax, dof=1) assert_items_almost_equal(yticks, [-6.0, 0.0, 6.0]) assert_items_equal(ylabels, ["-1.90", "-0.10", "1.70"]) self.plotter.label_format = old_format
def test_ticks_and_labels(self): # mock axes, make sure they work as expected fake_ax = MockAxes([-1.0, 0.0, 1.0], [-6.0, 0.0, 6.0]) assert_items_equal(fake_ax.get_xticks(), [-1.0, 0.0, 1.0]) assert_items_equal(fake_ax.get_yticks(), [-6.0, 0.0, 6.0]) old_format = self.plotter.label_format self.plotter.label_format = "{:4.2f}" xticks, xlabels = self.plotter.ticks_and_labels( ticks=[-2.0, -1.0, 0.0, 1.0, 2.0], ax=fake_ax, dof=0 ) assert_items_almost_equal(xticks, [-2.0, -1.0, 0.0, 1.0, 2.0]) assert_items_equal(xlabels, ["-1.00", "-0.50", "0.00", "0.50", "1.00"]) yticks, ylabels = self.plotter.ticks_and_labels( ticks=None, ax=fake_ax, dof=1 ) assert_items_almost_equal(yticks, [-6.0, 0.0, 6.0]) assert_items_equal(ylabels, ["-1.90", "-0.10", "1.70"]) self.plotter.label_format = old_format
def test_cumulative(self): histo = Histogram(n_bins=5) hist = histo.histogram(self.data) assert_items_almost_equal(histo.cumulative(), [5.0, 5.0, 7.0, 8.0, 10.0]) assert_items_almost_equal(histo.cumulative(maximum=1.0), [0.5, 0.5, 0.7, 0.8, 1.0])