Skip to content

Commit

Permalink
Refs #4375 a few MantidPlot 1D plot unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Dec 29, 2011
1 parent 5a9bd8c commit aeb0adb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ endforeach ( PYFILE ${PYTHON_INSTALL_FILES} )
# List of .py files than must be run WITHIN MantidPlot.
set ( MANTIDPLOT_TEST_PY_FILES
MantidPlotSliceViewerTest.py
MantidPlot1DPlotTest.py
)

if ( 0 )
Expand Down
15 changes: 12 additions & 3 deletions Code/Mantid/MantidPlot/mantidplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def plot(source, *args, **kwargs):

#-----------------------------------------------------------------------------
def plotSpectrum(source, indices, error_bars = False, type = -1):
"""Open a 1D Plot of a spectrum in a workspace
"""Open a 1D Plot of a spectrum in a workspace.
This plots one or more spectra, with X as the bin boundaries,
and Y as the counts in each bin.
@param source :: workspace or name of a workspace
@param indices :: workspace index or list of workspace indices to plot
Expand All @@ -47,10 +50,16 @@ def plotSpectrum(source, indices, error_bars = False, type = -1):

#-----------------------------------------------------------------------------
def plotBin(source, indices, error_bars = False, type = 0):
"""Create a 1D Plot of a bin or bins in a workspace
"""Create a 1D Plot of bin count vs spectrum in a workspace.
This puts the spectrum number as the X variable, and the
count in the particular bin # (in 'indices') as the Y value.
If indices is a list, then several lines are created, one
for each bin index.
@param source :: workspace or name of a workspace
@param indices :: workspace index or list of workspace indices to plot
@param indices :: bin number to plot
@param error_bars :: bool, set to True to add error bars.
"""
return __doPlotting(source,indices,error_bars,type)
Expand Down
60 changes: 60 additions & 0 deletions Code/Mantid/MantidPlot/test/MantidPlot1DPlotTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""
Test of basic 1D plotting methods in MantidPlot
"""
import mantidplottests
from mantidplottests import *
import time
import numpy as np
from PyQt4 import QtGui

# =============== Create a fake workspace to plot =======================
X1 = np.linspace(0,10, 100)
Y1 = 1000*(np.sin(X1)**2) + X1*10
X1 = np.append(X1, 10.1)

X2 = np.linspace(2,12, 100)
Y2 = 500*(np.cos(X2/2.)**2) + 20
X2 = np.append(X2, 12.10)

X = np.append(X1, X2)
Y = np.append(Y1, Y2)
E = np.sqrt(Y)

CreateWorkspace("fake", X, Y, E, NSpec=2, UnitX="TOF", YUnitLabel="Counts", WorkspaceTitle="Faked data Workspace")
#CreateWorkspace("fake2", X, Y, E, NSpec=2, UnitX="TOF", YUnitLabel="Counts", WorkspaceTitle="Faked data Workspace")

class MantidPlot1DPlotTest(unittest.TestCase):

def setUp(self):
pass

def test_plotSpectrum_errorBars(self):
g = plotSpectrum("fake", 0, error_bars=True)
screenshot(g, "plotSpectrum_errorBars", "Call to plotSpectrum() of 1 spectrum, with error bars.")

def test_plotSpectrum_fromWorkspaceProxy(self):
ws = mtd["fake"]
plotSpectrum(ws, 0, error_bars=True)

def test_plotSpectrum_severalSpectra(self):
g = plotSpectrum("fake", [0, 1])
screenshot(g, "plotSpectrum_severalSpectra", "Call to plotSpectrum() of 2 spectra, no error bars.")

def test_Customized1DPlot(self):
g = plotSpectrum("fake", 0, error_bars=True)
l = g.activeLayer()
l.setCurveLineColor(0, QtGui.QColor("orange") )
l.setCurveLineWidth(0, 2 )
l.setTitle('My customized plot of <font face="Symbol">D</font>q')
l.setTitleFont(QtGui.QFont("Arial", 12))
l.setTitleColor(QtGui.QColor("red"))
l.setTitleAlignment(QtCore.Qt.AlignLeft)
l.setScale(2, 0, 3.0)
l.setAntialiasing(True)
screenshot(g, "Customized1DPlot", "1D plot of a spectrum, with error bars, an orange line of width 2, a custom title in red Arial font, with X from 0 to 3")



# Run the unit tests
mantidplottests.runTests(MantidPlot1DPlotTest)

4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/test/mantidplottests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def _replace_report_text(filename, section, newtext):
# Find the text in each section
for line in lines:
if line.startswith("<!-- "):
# All lines should!
# All lines should go <!-- Section -->
n = line.find(" ", 5)
if n > 0:
current_section = line[5:n].strip()
current_text = line[n+3:]
current_text = line[n+4:]
sections[current_section] = current_text

# Replace the section
Expand Down

0 comments on commit aeb0adb

Please sign in to comment.