code = std::string("import curveplot;")+
std::string("__cont=curveplot.PlotController.GetInstance()");
- PyRun_SimpleString("import site\n");
- PyRun_SimpleString("print(site.getsitepackages())\n");
int ret = PyRun_SimpleString(const_cast<char*>(code.c_str()));
if (ret == -1)
return curveId;
}
+ PlotID CurvePlot::AddBarPlot(const ColumnVector & x, const ColumnVector & y,
+ PlotID & plot_set_id,
+ std::string curve_label/*=""*/, std::string x_label/*=""*/, std::string y_label/*=""*/,
+ bool append/*=true*/)
+ {
+ PyLockWrapper lock;
+ PyObject * cont = GetInstance()->_impl->_controller;
+
+ PyObject * xx = (PyObject *)x._impl->_npArray;
+ PyObject * yy = (PyObject *)y._impl->_npArray;
+
+ PyObjWrapper ret(
+ PyObject_CallMethod(cont, (char *)"AddBarPlot", (char *)"OOOOOi", xx, yy,
+ strToPyUnicode(curve_label), strToPyUnicode(x_label), strToPyUnicode(y_label),
+ append ? 1 : 0)
+ );
+ HandleAndPrintPyError("CurvePlot::AddBarPlot(): unexpected error!");
+ // Now extract curve_id and plot_set_id from the returned tuple:
+ if(!PyTuple_Check(ret))
+ throw Exception("CurvePlot::AddBarPlot(): Unexpected returned type!");
+ PyObject * o1 = PyTuple_GetItem(ret, 0);
+ if (!PyLong_Check(o1))
+ throw Exception("CurvePlot::AddBarPlot(): Unexpected returned type!");
+ PlotID curveId = PyLong_AsLong(o1);
+ PyObject * o2 = PyTuple_GetItem(ret, 1);
+ if (!PyLong_Check(o2))
+ throw Exception("CurvePlot::AddBarPlot(): Unexpected returned type!");
+ plot_set_id = PyLong_AsLong(o2);
+ return curveId;
+ }
+
+ PlotID CurvePlot::AddStemPlot(const ColumnVector & x, const ColumnVector & y,
+ PlotID & plot_set_id,
+ std::string curve_label/*=""*/, std::string x_label/*=""*/, std::string y_label/*=""*/,
+ bool append/*=true*/)
+ {
+ PyLockWrapper lock;
+ PyObject * cont = GetInstance()->_impl->_controller;
+
+ PyObject * xx = (PyObject *)x._impl->_npArray;
+ PyObject * yy = (PyObject *)y._impl->_npArray;
+
+ PyObjWrapper ret(
+ PyObject_CallMethod(cont, (char *)"AddStemPlot", (char *)"OOOOOi", xx, yy,
+ strToPyUnicode(curve_label), strToPyUnicode(x_label), strToPyUnicode(y_label),
+ append ? 1 : 0)
+ );
+ HandleAndPrintPyError("CurvePlot::AddStemPlot(): unexpected error!");
+ // Now extract curve_id and plot_set_id from the returned tuple:
+ if(!PyTuple_Check(ret))
+ throw Exception("CurvePlot::AddStemPlot(): Unexpected returned type!");
+ PyObject * o1 = PyTuple_GetItem(ret, 0);
+ if (!PyLong_Check(o1))
+ throw Exception("CurvePlot::AddStemPlot(): Unexpected returned type!");
+ PlotID curveId = PyLong_AsLong(o1);
+ PyObject * o2 = PyTuple_GetItem(ret, 1);
+ if (!PyLong_Check(o2))
+ throw Exception("CurvePlot::AddStemPlot(): Unexpected returned type!");
+ plot_set_id = PyLong_AsLong(o2);
+ return curveId;
+ }
+
+
+
PlotID CurvePlot::AddPlotSet(std::string title/*=""*/)
{
PyLockWrapper lock;
std::string curve_label="", std::string x_label="", std::string y_label="",
bool append=true);
+ static PlotID AddBarPlot(const ColumnVector & x, const ColumnVector & y,
+ PlotID & plot_set_id,
+ std::string curve_label="", std::string x_label="", std::string y_label="",
+ bool append=true);
+
+ static PlotID AddStemPlot(const ColumnVector & x, const ColumnVector & y,
+ PlotID & plot_set_id,
+ std::string curve_label="", std::string x_label="", std::string y_label="",
+ bool append=true);
+
static PlotID AddPlotSet(std::string title="");
static PlotID DeleteCurve(PlotID curve_id=-1);
}
std::cout << " > Inside initPython()" << std::endl;
-
}
/* Little hack to gather widgets created on the Python side */
@classmethod
- def AddBarPlot(cls, x, height, width, isDirac, curve_label="", x_label="", y_label="", append=True):
+ def AddBarPlot(cls, x_ticks, height, curve_label="", x_label="", y_label="", append=True):
""" Testing some stuff with BarPlot"""
from .XYView import XYView
control = cls.GetInstance()
pm = control._plotManager
t = TableModel(control)
- data = np.transpose(np.vstack([x, height, width]))
+ x_inf = x_ticks[:-1] # TAG CHECK, verif nb ticks
+ width = x_ticks[1:] - x_ticks[:-1]
+ data = np.transpose(np.vstack([x_inf, height, width]))
t.setData(data)
# ensure a single Matplotlib repaint for all operations to come in AddBarPlot
prevLock = pm.isRepaintLocked()
if not prevLock:
pm.lockRepaint()
- curveID, plotSetID = control.plotBarPlotFromTable(t, isDirac,
+ curveID, plotSetID = control.plotBarPlotFromTable(t,
x_col_index=0, height_col_index=1, width_col_index=2,
curve_label=curve_label, append=append)
return cm.getID(),cps.getID()
- def plotBarPlotFromTable(self, table, isDirac=True,
+ def plotBarPlotFromTable(self, table,
x_col_index=0, height_col_index=1, width_col_index=2,
curve_label="", append=True):
"""
cps = self._plotManager.getCurrentPlotSet()
- bm = BarModel(self, table, isDirac, height_col_index, width_col_index)
+ bm = BarModel(self, table, height_col_index, width_col_index)
bm.setXAxisIndex(x_col_index)
# X axis label
class BarModel(Model):
- def __init__(self, controller, table=None, isDirac=True, heightIndex=-1, widthIndex=-1):
+ def __init__(self, controller, table=None, heightIndex=-1, widthIndex=-1):
Model.__init__(self, controller)
# self.ID_PLOT += 1
self._name = "BarModel"
self._title = "Barplot %d" % self.getID()
self._table = table
- self._isDirac = isDirac
self._xaxisIndex = 0 # By default the first column of the table is used for the X-s
self._heightIndex = heightIndex # column index in the table, corresponding to the bar height
ret._xaxisIndex = self._xaxisIndex
ret._heightIndex = self._heightIndex
ret._widthIndex = self._widthIndex
- ret._isDirac = self._isDirac
return ret
- def getIsDirac(self):
- return self._isDirac
-
- def setIsDirac(self, isD, silent=False):
- self._isDirac = isD
-
def setTable(self, t, silent=False):
self._table = t
if not silent:
self.perfTestAction.triggered.connect(self.perfTest)
self.addStemPlotAction.triggered.connect(self.addStemplot)
self.addBarPlotNonDiracAction.triggered.connect(self.addBarplotNonDirac)
- self.addBarPlotDiracAction.triggered.connect(self.addBarplotDirac)
def generateID(self):
self.perfActionID = self.generateID()
self.addStemPlotActionID = self.generateID()
self.addBarPlotNonDiracActionID = self.generateID()
- self.addBarPlotDiracActionID = self.generateID()
# Menus
self.etudeMenuID = self.generateID()
self.perfTestAction = ca(self.perfActionID, "Perf test", "Perf test", "", "")
self.addStemPlotAction = ca(self.addStemPlotActionID, "Add StemPlot - Dirac", "Add StemPlot - Dirac", "", "")
self.addBarPlotNonDiracAction = ca(self.addBarPlotNonDiracActionID, "Add BarPlot - Non Dirac", "Add BarPlot- Non Dirac", "", "")
- self.addBarPlotDiracAction = ca(self.addBarPlotDiracActionID, "Add BarPlot - Dirac", "Add BarPlot - Dirac", "", "")
def createToolbars(self):
pass
self._sgPyQt.createMenu(self.perfTestAction, curveMenu)
self._sgPyQt.createMenu(self.addStemPlotAction, curveMenu)
self._sgPyQt.createMenu(self.addBarPlotNonDiracAction, curveMenu)
- self._sgPyQt.createMenu(self.addBarPlotDiracAction, curveMenu)
dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() )
self._sgPyQt.createMenu(self.addTabAction, dummyMenu)
curveplot.UnlockRepaint()
print("Elapsed: %.2f" % ( time() - t0))
- @pyqtSlot()
- def addBarplotDirac(self):
- energy_val = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7])
-
- intensity = np.random.rand(energy_val.size) * 10
- isDirac = True
- width_dirac = np.full(energy_val.size, 0.05)
-
- _, ps_id = curveplot.AddBarPlot(energy_val, intensity, width_dirac, isDirac,
- x_label="Energy", y_label="Intensity", append=True)
-
- curveplot.SetLegendVisible(ps_id, True)
@pyqtSlot()
def addStemplot(self):
from curveplot import TableModel
from random import random
- energy_inf = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7])
- energy_sup = np.array([1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7, 20.])
- deltaE = energy_sup - energy_inf
- intensity = np.random.rand(energy_inf.size) * 10
- isDirac = False
+ energy_ticks = np.array([0., 1.15, 5.2, 8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 15.1, 17.8, 19.7, 20.])
- t = TableModel(None)
- t.setTitle("Non Dirac data")
- t.addColumn(energy_inf) # x : energy inf
- t.addColumn(intensity) # height : intensity
- t.addColumn(deltaE) # width : delta energy
- t.setColumnTitle(0, "Energy")
- t.setColumnTitle(1, "Intensity")
- t.setColumnTitle(2, "DeltaE")
+ # intensity.size = energy_ticks.size - 1
+ intensity = np.random.rand(energy_ticks.size - 1) * 10
+
+ _, ps_id = curveplot.AddBarPlot(energy_ticks, intensity,
+ x_label="Energy", y_label="Intensity", append=True)
- bar_label = "Some spectrum"
- cont = curveplot.PlotController.GetInstance()
- crv_id, ps_id = cont.plotBarPlotFromTable(t, isDirac,
- x_col_index=0, height_col_index=1, width_col_index=2,
- curve_label=bar_label,
- append=True)
-
curveplot.SetLegendVisible(ps_id, True)
def draw(self):
m = self._model
x_idx, height_idx, width_idx = m.getXAxisIndex(), m.getHeightIndex(), m.getWidthIndex()
- x_align = "center" if m.getIsDirac() else "edge"
+ x_align = "edge" # inf borns
d = self._model.getTable().getData()
# Bar returns a BarContainer (list of Artists)
return QObject.eventFilter(self, obj, event)
class XYView(View):
- AUTOFIT_MARGIN = 0.03 # 3%
+ AUTOFIT_MARGIN = 0.1 # 3%
# See http://matplotlib.org/api/markers_api.html:
CURVE_MARKERS = [ "o" ,# circle