def test_get_uneven_data(self): # even points x, y, z = funcs.get_uneven_data(self.ws2d_point_rag, True) np.testing.assert_allclose(x[0], np.array([0.5, 1.5, 2.5, 3.5, 4.5])) np.testing.assert_allclose(x[1], np.array([1, 3, 5, 7, 9])) np.testing.assert_allclose(y[0], np.array([0.5, 1.5])) np.testing.assert_allclose(y[1], np.array([1.5, 2.5])) np.testing.assert_allclose(z[0], np.array([2, 2, 2, 2])) np.testing.assert_allclose(z[1], np.array([2, 2, 2, 2])) # even histo x, y, z = funcs.get_uneven_data(self.ws2d_histo_rag, True) np.testing.assert_allclose(x[0], np.array([1, 2, 3, 4, 5])) np.testing.assert_allclose(x[1], np.array([2, 4, 6, 8, 10])) np.testing.assert_allclose(y[0], np.array([5, 7])) np.testing.assert_allclose(y[1], np.array([7, 9])) np.testing.assert_allclose(z[0], np.array([2, 2, 2, 2])) np.testing.assert_allclose(z[1], np.array([2, 2, 2, 2])) # uneven points x, y, z = funcs.get_uneven_data(self.ws2d_point_uneven, True) np.testing.assert_allclose(x[0], np.array([5, 15, 25, 35])) np.testing.assert_allclose(x[1], np.array([10, 20, 30, 40, 50])) np.testing.assert_allclose(y[0], np.array([0.5, 1.5])) np.testing.assert_allclose(y[1], np.array([1.5, 2.5])) np.testing.assert_allclose(z[0], np.array([1, 2, 3])) np.testing.assert_allclose(z[1], np.array([1, 2, 3, 4])) # uneven histo x, y, z = funcs.get_uneven_data(self.ws2d_histo_uneven, True) np.testing.assert_allclose(x[0], np.array([10, 20, 30, 40])) np.testing.assert_allclose(x[1], np.array([15, 25, 35, 45, 55])) np.testing.assert_allclose(y[0], np.array([10, 15])) np.testing.assert_allclose(y[1], np.array([15, 25])) np.testing.assert_allclose(z[0], np.array([1, 2, 3])) np.testing.assert_allclose(z[1], np.array([1, 2, 3, 4]))
def _pcolorpieces(axes, workspace, distribution, *args, **kwargs): ''' Helper function for pcolor, pcolorfast, and pcolormesh that will plot a 2d representation of each spectra. The polycollections or meshes will be normalized to the same intensity limits. :param axes: :class:`matplotlib.axes.Axes` object that will do the plotting :param workspace: :class:`mantid.api.MatrixWorkspace` to extract the data from :param distribution: ``None`` (default) asks the workspace. ``False`` means divide by bin width. ``True`` means do not divide by bin width. Applies only when the the matrix workspace is a histogram. :param pcolortype: this keyword allows the plotting to be one of pcolormesh or pcolorfast if there is "mesh" or "fast" in the value of the keyword, or pcolor by default :return: A list of the pcolor pieces created ''' (x, y, z) = get_uneven_data(workspace, distribution) mini = numpy.min([numpy.min(i) for i in z]) maxi = numpy.max([numpy.max(i) for i in z]) if 'vmin' in kwargs: mini = kwargs['vmin'] if 'vmax' in kwargs: maxi = kwargs['vmax'] if 'norm' not in kwargs: kwargs['norm'] = matplotlib.colors.Normalize(vmin=mini, vmax=maxi) else: if kwargs['norm'].vmin is None: kwargs['norm'].vmin = mini if kwargs['norm'].vmax is None: kwargs['norm'].vmax = maxi # setup the particular pcolor to use pcolortype = kwargs.pop('pcolortype', '').lower() if 'mesh' in pcolortype: pcolor = axes.pcolormesh elif 'fast' in pcolortype: pcolor = axes.pcolorfast else: pcolor = axes.pcolor pieces = [] for xi, yi, zi in zip(x, y, z): XX, YY = numpy.meshgrid(xi, yi, indexing='ij') pieces.append(pcolor(XX, YY, zi.reshape(-1, 1), **kwargs)) return pieces