diff --git a/Framework/PythonInterface/mantid/plots/pfunctions.py b/Framework/PythonInterface/mantid/plots/pfunctions.py index af922cf826deb04f92eca30d1f2caaff7204d2f4..f629b8ee8199a0d0a02ea743d8e20b1c73b42673 100644 --- a/Framework/PythonInterface/mantid/plots/pfunctions.py +++ b/Framework/PythonInterface/mantid/plots/pfunctions.py @@ -42,7 +42,9 @@ def getAxesLabels(workspace): ''' get axis labels from a Workspace2D or an MDHistoWorkspace Returns a tuple. The first element is the quantity label, such as "Intensity" or "Counts". All other elements in the tuple are labels for axes. - Some of them are latef formatted already.''' + Some of them are latex formatted already. + :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.dataobjects.MDHistoWorkspace` + ''' if isinstance(workspace,mantid.dataobjects.MDHistoWorkspace): axes = ['Intensity'] dims = workspace.getNonIntegratedDimensions() @@ -342,7 +344,7 @@ def _getMDData2D_bin_centers(workspace,normalization): tricontour, tricontourf, tripcolor) Note return coordinates are 1d vectors. Use numpy.meshgrid to generate 2d versions ''' - x,y,data=_getMDData2D_bin_bounds(workspace,normalization,withError=False) + x,y,data=_getMDData2D_bin_bounds(workspace,normalization) x=points_from_boundaries(x) y=points_from_boundaries(y) return (x,y,data) diff --git a/Framework/PythonInterface/test/python/mantid/plots/pfunctionsTest.py b/Framework/PythonInterface/test/python/mantid/plots/pfunctionsTest.py index c9c5cba88adbc32d34b9483dfd15e3152c290b59..045549da5a8a093820884bb5021aa21ce02e5ebf 100644 --- a/Framework/PythonInterface/test/python/mantid/plots/pfunctionsTest.py +++ b/Framework/PythonInterface/test/python/mantid/plots/pfunctionsTest.py @@ -1,16 +1,16 @@ from __future__ import (absolute_import, division, print_function) import unittest -#from mantid.simpleapi import CreateWorkspace,DeleteWorkspace,CreateMDHistoWorkspace, ConjoinWorkspaces -#import mantid.plots.functions as funcs -#import mantid.api +from mantid.simpleapi import CreateWorkspace,DeleteWorkspace,CreateMDHistoWorkspace, ConjoinWorkspaces +import mantid.plots.pfunctions as funcs +import mantid.api import numpy as np -#from mantid.kernel import config +from mantid.kernel import config import matplotlib.pyplot as plt class PlotsFunctionsTest(unittest.TestCase): - """ + @classmethod def setUpClass(cls): cls.g1da=config['graph1d.autodistribution'] @@ -93,8 +93,8 @@ class PlotsFunctionsTest(unittest.TestCase): DeleteWorkspace('ws2d_point_rag') DeleteWorkspace('ws2d_point_uneven') DeleteWorkspace('ws2d_histo_uneven') - """ - def xtest_getWkspIndexDistAndLabel(self): + + def test_getWkspIndexDistAndLabel(self): #fail case self.assertRaises(RuntimeError,funcs._getWkspIndexDistAndLabel,self.ws2d_histo) #get info from a 2d workspace @@ -108,16 +108,16 @@ class PlotsFunctionsTest(unittest.TestCase): self.assertFalse(dist) self.assertEqual(kwargs['label'],'spec 1') - def xtest_getAxesLabels(self): + def test_getAxesLabels(self): axs=funcs.getAxesLabels(self.ws2d_histo) self.assertEqual(axs,('', 'Wavelength ($\\AA$)', 'Energy transfer ($meV$)')) - def xtest_getAxesLabeld_MDWS(self): + def test_getAxesLabeld_MDWS(self): axs=funcs.getAxesLabels(self.ws_MD_2d) #should get the first two dimension labels only self.assertEqual(axs,('Intensity', 'Dim1 ($\\AA^{-1}$)', 'Dim2 (EnergyTransfer)')) - def xtest_getDataUnevenFlag(self): + def test_getDataUnevenFlag(self): flag,kwargs=funcs._getDataUnevenFlag(self.ws2d_histo_rag, AxisAligned=True, other_kwarg=1) self.assertTrue(flag) self.assertEquals(kwargs,{'other_kwarg':1}) @@ -128,18 +128,17 @@ class PlotsFunctionsTest(unittest.TestCase): self.assertTrue(flag) self.assertEquals(kwargs,{'other_kwarg':3}) - - def xtest_boundaries_from_points(self): + def test_boundaries_from_points(self): centers=np.array([1.,2.,4.,8.]) bounds=funcs.boundaries_from_points(centers) self.assertTrue(np.array_equal(bounds,np.array([0.5,1.5,3,6,10]))) - def xtest_points_from_boundaries(self): + def test_points_from_boundaries(self): bounds=np.array([1.,3,4,10]) centers=funcs.points_from_boundaries(bounds) self.assertTrue(np.array_equal(centers,np.array([2.,3.5,7]))) - def xtest_getSpectrum(self): + def test_getSpectrum(self): #get data divided by bin width x,y,dy,dx=funcs._getSpectrum(self.ws2d_histo, 1, False,withDy=True, withDx=True) self.assertTrue(np.array_equal(x,np.array([15.,25.]))) @@ -155,24 +154,24 @@ class PlotsFunctionsTest(unittest.TestCase): #fail case - try to find spectrum out of range self.assertRaises(RuntimeError,funcs._getSpectrum, self.ws2d_histo, 10, True) - def xtest_getMDData2D_bin_bounds(self): + def test_getMDData2D_bin_bounds(self): x,y,data=funcs._getMDData2D_bin_bounds(self.ws_MD_2d,mantid.api.MDNormalization.NoNormalization) #logger.error(str(coords)) np.testing.assert_allclose(x,np.array([-3,-1.8,-0.6,0.6,1.8,3]),atol=1e-10) np.testing.assert_allclose(y,np.array([-10,-6,-2,2,6,10.]),atol=1e-10) np.testing.assert_allclose(data,np.arange(25).reshape(5,5),atol=1e-10) - def xtest_getMDData2D_bin_centers(self): + def test_getMDData2D_bin_centers(self): x,y,data=funcs._getMDData2D_bin_centers(self.ws_MD_2d,mantid.api.MDNormalization.NumEventsNormalization) np.testing.assert_allclose(x,np.array([-2.4,-1.2,0,1.2,2.4]),atol=1e-10) np.testing.assert_allclose(y,np.array([-8,-4,0,4,8]),atol=1e-10) np.testing.assert_allclose(data,np.arange(25).reshape(5,5)*0.1,atol=1e-10) - def xtest_getMDData1D(self): + def test_getMDData1D(self): coords,data,err=funcs._getMDData1D(self.ws_MD_1d,mantid.api.MDNormalization.NumEventsNormalization) np.testing.assert_allclose(coords,np.array([-8,-4,0,4,8]),atol=1e-10) - def xtest_getMatrix2DData_rect(self): + def test_getMatrix2DData_rect(self): #contour from aligned point data x,y,z=funcs._getMatrix2DData(self.ws2d_point,True,histogram2D=False) np.testing.assert_allclose(x,np.array([[1,2,3,4],[1,2,3,4],[1,2,3,4]])) @@ -190,7 +189,7 @@ class PlotsFunctionsTest(unittest.TestCase): np.testing.assert_allclose(x,np.array([[10,20,30],[10,20,30],[10,20,30]])) np.testing.assert_allclose(y,np.array([[4,4,4],[6,6,6],[8,8,8]])) - def xtest_getMatrix2DData_rag(self): + def test_getMatrix2DData_rag(self): #contour from ragged point data x,y,z=funcs._getMatrix2DData(self.ws2d_point_rag,True,histogram2D=False) np.testing.assert_allclose(x,np.array([[1,2,3,4],[2,4,6,8]])) @@ -210,7 +209,7 @@ class PlotsFunctionsTest(unittest.TestCase): #check that fails for uneven data self.assertRaises(ValueError,funcs._getMatrix2DData, self.ws2d_point_uneven,True) - def xtest_getUnevenData(self): + def test_getUnevenData(self): #even points x,y,z=funcs._getUnevenData(self.ws2d_point_rag,True) np.testing.assert_allclose(x[0],np.array([0.5,1.5,2.5,3.5,4.5])) @@ -244,24 +243,38 @@ class PlotsFunctionsTest(unittest.TestCase): np.testing.assert_allclose(z[0],np.array([1,2,3])) np.testing.assert_allclose(z[1],np.array([1,2,3,4])) - def xtest_1dplots(self): + def test_1dplots(self): fig, ax = plt.subplots() funcs.plot(ax,self.ws2d_histo,'rs',specNum=1) funcs.plot(ax,self.ws2d_histo,specNum=2,linewidth=6) funcs.plot(ax,self.ws_MD_1d,'bo') - def xtest_1derrorbars(self): + def test_1derrorbars(self): fig, ax = plt.subplots() funcs.errorbar(ax,self.ws2d_histo,'rs',specNum=1) funcs.errorbar(ax,self.ws2d_histo,specNum=2,linewidth=6) funcs.errorbar(ax,self.ws_MD_1d,'bo') - def xtest_1dscatter(self): + def test_1dscatter(self): fig, ax = plt.subplots() funcs.scatter(ax,self.ws2d_histo,specNum=1) funcs.scatter(ax,self.ws2d_histo,specNum=2) funcs.scatter(ax,self.ws_MD_1d) + def test_2dcontours(self): + fig, ax = plt.subplots() + funcs.contour(ax,self.ws2d_histo_rag) + funcs.contourf(ax,self.ws2d_histo,vmin=0) + funcs.tricontour(ax,self.ws_MD_2d) + funcs.tricontourf(ax,self.ws_MD_2d) + self.assertRaises(ValueError,funcs.contour, ax, self.ws2d_point_uneven) + + def test_2dpcolors(self): + fig, ax = plt.subplots() + funcs.pcolor(ax,self.ws2d_histo_rag) + funcs.tripcolor(ax,self.ws2d_histo,vmin=0) + funcs.pcolormesh(ax,self.ws_MD_2d) + funcs.pcolorfast(ax,self.ws2d_point_uneven,vmin=-1) if __name__ == '__main__': unittest.main() diff --git a/docs/source/api/python/mantid/plots/index.rst b/docs/source/api/python/mantid/plots/index.rst index cc489aa94f20f32aa5589c483ff097f85900146b..04fd68010e5ddb200302a814e51db2fc252f5a7e 100644 --- a/docs/source/api/python/mantid/plots/index.rst +++ b/docs/source/api/python/mantid/plots/index.rst @@ -103,28 +103,27 @@ Types of functions **Informational** -* :func:`~mantid.plots.getAxesLabels` +* :func:`~mantid.plots.pfunctions.getAxesLabels` **1D Plotting** -* :func:`~mantid.plots.plot` - Plot lines and/or markers -* :func:`~mantid.plots.errorbar` - Plot valuse with errorbars -* :func:`~mantid.plots.scatter` - Make a scatter plot +* :func:`~mantid.plots.pfunctions.plot` - Plot lines and/or markers +* :func:`~mantid.plots.pfunctions.errorbar` - Plot valuse with errorbars +* :func:`~mantid.plots.pfunctions.scatter` - Make a scatter plot **2D Plotting - uniform grid** -* :func:`~mantid.plots.contour` - Draw contours at specified levels -* :func:`~mantid.plots.contourf` - Draw contours at calculated levels -* :func:`~mantid.plots.pcolor` - Draw a pseudocolor plot of a 2-D array -* :func:`~mantid.plots.pcolorfast` - Draw a pseudocolor plot of a 2-D array -* :func:`~mantid.plots.pcolormesh` - Draw a quadrilateral mesh +* :func:`~mantid.plots.pfunctions.contour` - Draw contours at specified levels +* :func:`~mantid.plots.pfunctions.contourf` - Draw contours at calculated levels +* :func:`~mantid.plots.pfunctions.pcolor` - Draw a pseudocolor plot of a 2-D array +* :func:`~mantid.plots.pfunctions.pcolorfast` - Draw a pseudocolor plot of a 2-D array +* :func:`~mantid.plots.pfunctions.pcolormesh` - Draw a quadrilateral mesh **2D Plotting - nonuniform grid** -* :func:`~mantid.plots.tripcolor` - Draw a pseudocolor plot of an unstructured triangular grid -* :func:`~mantid.plots.triplot` - Draw a unstructured triangular grid as lines and/or markers -* :func:`~mantid.plots.tricontour` - Draw contours at specified levels on an unstructured triangular grid -* :func:`~mantid.plots.tricontourf` - Draw contours at calculated levels on an unstructured triangular grid +* :func:`~mantid.plots.pfunctions.tripcolor` - Draw a pseudocolor plot of an unstructured triangular grid +* :func:`~mantid.plots.pfunctions.tricontour` - Draw contours at specified levels on an unstructured triangular grid +* :func:`~mantid.plots.pfunctions.tricontourf` - Draw contours at calculated levels on an unstructured triangular grid matplotlib demonstrates the difference between uniform and nonuniform grids well in `this example @@ -133,7 +132,7 @@ grids well in `this example Available Functions =================== -.. automodule:: mantid.plots +.. automodule:: mantid.plots.pfunctions :members: getAxesLabels, plot, errorbar, scatter, contour, contourf, pcolor, pcolorfast, pcolormesh, tripcolor, triplot, tricontour, tricontourf