self.memAction.triggered.connect(self.memPrint)
self.perfTestAction.triggered.connect(self.perfTest)
self.addBarPlotAction.triggered.connect(self.addBarplot)
+ self.addBarPlotNonDiracAction.triggered.connect(self.addBarplotNonDirac)
+
def generateID(self):
self._currID += 1
self.memActionID = self.generateID()
self.perfActionID = self.generateID()
self.addBarPlotActionID = self.generateID()
+ self.addBarPlotNonDiracActionID = self.generateID()
# Menus
self.etudeMenuID = self.generateID()
self.addTabAction = ca(self.addTabActionID, "Add tab", "Add tab", "", "")
self.memAction = ca(self.memActionID, "Display used mem", "Display used mem", "", "")
self.perfTestAction = ca(self.perfActionID, "Perf test", "Perf test", "", "")
- self.addBarPlotAction = ca(self.addBarPlotActionID, "Add BarPlot", "Add BarPlot", "", "")
+ self.addBarPlotAction = ca(self.addBarPlotActionID, "Add BarPlot - Dirac", "Add BarPlot - Dirac", "", "")
+ self.addBarPlotNonDiracAction = ca(self.addBarPlotActionID, "Add BarPlot - Non Dirac", "Add BarPlot- Non Dirac", "", "")
def createToolbars(self):
pass
self._sgPyQt.createMenu(self.memAction, curveMenu)
self._sgPyQt.createMenu(self.perfTestAction, curveMenu)
self._sgPyQt.createMenu(self.addBarPlotAction, curveMenu)
+ self._sgPyQt.createMenu(self.addBarPlotNonDiracAction, curveMenu)
dummyMenu = self._sgPyQt.createMenu( "Dummy", -1, self.dummyMenuID, self._sgPyQt.defaultMenuGroup() )
self._sgPyQt.createMenu(self.addTabAction, dummyMenu)
@pyqtSlot()
def addBarplot(self):
- x, height = self.__generateRandomData()
- width = np.full(x.size, 0.05)
+ energy_val = np.array([8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99])
+ # energy_val = np.array([8.15, 8.42, 8.75, 8.88, 9.1, 9.55, 9.79])
+
+ intensity = np.random.rand(energy_val.size) * 5
isDirac = True
- _, ps_id = curveplot.AddBarPlot(x, height, width, isDirac,
- x_label="the x axis", y_label="the y axis", append=True)
+ width_dirac = np.full(energy_val.size, 0.01)
+
+ _, ps_id = curveplot.AddBarPlot(energy_val, intensity, width_dirac, isDirac,
+ x_label="Energy", y_label="Intensity", append=True)
+
+ curveplot.SetLegendVisible(ps_id, True)
+ if self.cnt >= 0:
+ QTimer.singleShot(self.timeLap, self, SLOT("itemDel()"))
+
+ @pyqtSlot()
+ def addBarplotNonDirac(self):
+ # Testing with TableModel
+ from curveplot import TableModel
+ from random import random
+
+ energy_inf = np.array([8.01, 8.33, 8.67, 8.99, 9.01, 9.33, 9.99])
+ energy_sup = np.array([8.33, 8.67, 8.99, 9.01, 9.33, 9.99, 10.01])
+ deltaE = energy_sup - energy_inf
+ intensity = np.random.rand(energy_inf.size) * 5
+ isDirac = False
+
+ 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")
+
+ 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)
+
if self.cnt >= 0:
QTimer.singleShot(self.timeLap, self, SLOT("itemDel()"))
+
def clearPlotSet(self):
curveplot.ClearPlotSet()
self._isHighlighted = False
self._initialLineWidth = None
self._initialEdgeColorBar = None
+ self._initialAlpha = None
self._parentXYView = parentXYView
self._marker = None
self._color = None
+ self._opacity = None
self._lineStyle = None
def setMPLAxes(self, axes):
x_idx, height_idx, width_idx = m.getXAxisIndex(), m.getHeightIndex(), m.getWidthIndex()
x_align = "center" if m.getIsDirac() else "edge"
d = self._model.getTable().getData()
+
self._mplBars = self._mplAxes.bar(d[:, x_idx], d[:, height_idx], width=d[:, width_idx],
- align=x_align, label=m._title, picker=self._PICKER_PRECISION_BAR)
- self._initialLineWidth = self._mplBars[0].get_linewidth()
- print("Bar initial lw : ", self._initialLineWidth)
+ align=x_align, label=m._title, alpha= 0.7,
+ picker=self._PICKER_PRECISION_BAR)
+
+ self._initialLineWidth = 0. #self._mplBars[0].get_linewidth()
self._initialEdgeColorBar = self._mplBars[0].get_edgecolor()
- print("Bar initial ec : ", self._initialEdgeColorBar)
+ self._initialAlpha = self._mplBars[0].get_alpha()
+
+ Logger.Debug(" > Bar initial lw : {}".format(self._initialLineWidth))
+ Logger.Debug(" > Bar initial ec : {}".format(self._initialEdgeColorBar))
+ Logger.Debug(" > Bar initial alpha : {}".format(self._initialAlpha))
else:
x_idx, y_idx = m.getXAxisIndex(), m.getYAxisIndex()
d = self._model.getTable().getData()
if self._mplBars is None:
return
color = self.getColor()
+ opacity = self.getAlpha()
self.erase()
self.draw()
self.setColor(color)
+ self.setAlpha(opacity)
self.toggleHighlight(self._isHighlighted, force=True)
else:
if self._mplLines is None:
self.toggleHighlight(self._isHighlighted, force=True)
def setLineStyle(self, lin_style):
- lin = self._mplLines[0]
- lin.set_linestyle(lin_style)
+ if (self._model._name != "BarModel"):
+ lin = self._mplLines[0]
+ lin.set_linestyle(lin_style)
def getLineStyle(self):
- if self._mplLines is None:
- return None
- return self._mplLines[0].get_linestyle()
+ if (self._model._name != "BarModel"):
+ if self._mplLines is None:
+ return None
+ return self._mplLines[0].get_linestyle()
def setMarker(self, marker):
- lin = self._mplLines[0]
- lin.set_marker(marker)
+ if (self._model._name != "BarModel"):
+ lin = self._mplLines[0]
+ lin.set_marker(marker)
def getMarker(self):
if self._mplLines is None:
bar = self._mplBars.patches
if highlight and (force or not self._isHighlighted):
for rect in bar :
- rect.set_linewidth(2*self._initialLineWidth)
+ rect.set_linewidth(1.)
+ rect.set_alpha(1)
rect.set_edgecolor("red")
self._isHighlighted = True
elif not highlight and (force or self._isHighlighted):
for rect in bar :
rect.set_linewidth(self._initialLineWidth)
+ rect.set_alpha(self._initialAlpha)
rect.set_edgecolor(self._initialEdgeColorBar)
self._isHighlighted = False
else:
m = self._model
# Check si BarModel ou CurveModel
if (m._name == "BarModel"):
- bar = self._mplBars
- bar.set_color(rgb_color)
+ for rect in self._mplBars :
+ rect.set_facecolor(rgb_color)
else:
lin = self._mplLines[0]
lin.set_color(rgb_color)
m = self._model
# Check si BarModel ou CurveModel
if (m._name == "BarModel"):
- if self._mplbars is None:
+ if self._mplBars is None:
return None
- return self._mplBars[0].get_color()
+ return self._mplBars[0].get_facecolor()
else:
if self._mplLines is None:
return None
return self._mplLines[0].get_color()
+
+ def setAlpha(self, opacity):
+ m = self._model
+ # Check si BarModel ou CurveModel
+ if (m._name == "BarModel"):
+ bar = self._mplBars
+ bar.set_alpha(opacity)
+ else:
+ lin = self._mplLines[0]
+ lin.set_alpha(opacity)
+
+ def getAlpha(self):
+ m = self._model
+ # Check si BarModel ou CurveModel
+ if (m._name == "BarModel"):
+ if self._mplBars is None:
+ return None
+ return self._mplBars[0].get_alpha()
+ else:
+ if self._mplLines is None:
+ return None
+ return self._mplLines[0].get_alpha()
newC.setMPLAxes(self._mplAxes)
newC.draw()
if (self._model._curves[curveID]._name == "BarModel"):
- print("Appending un bar model !")
+ Logger.Debug(" > Appending a bar model")
else:
newC.setMarker(self.getMarker(go_next=True))
self._curveViews[curveID] = newC
def onPick(self, event):
""" MPL callback when picking
"""
+ Logger.Debug(" > Event onPick : {}".format(event))
+
if event.mouseevent.button == 1:
selected_id = -1
a = event.artist
+ Logger.Debug(" > Artist picked : {}".format(a))
+
+ for crv_id, legHandler in enumerate(self._legend.legendHandles):
+ if legHandler is a :
+ selected_id = crv_id
+ Logger.Debug("Legend {} selected".format(selected_id))
for crv_id, cv in list(self._curveViews.items()):
if (cv._model._name == "BarModel") :
# Checks if the picked artist is in the list of Rectangles
if a in cv._mplBars:
selected_id = crv_id
- print(selected_id, " barplot selected")
+ Logger.Debug("Barplot {} selected".format(selected_id))
else:
if cv._mplLines[0] is a:
selected_id = crv_id
- print(selected_id, " curve selected")
+ Logger.Debug("Curve {} selected".format(selected_id))
+
# Use the plotmanager so that other plot sets get their current reset:
self._controller._plotManager.setCurrentCurve(selected_id)
ncol=1, fancybox=True, shadow=True, prop={'size':fontSize, 'style': 'italic'})
else:
raise Exception("Invalid legend placement! Must be 'bottom' or 'right'")
+
+
+ # Trying to set legend items pickable
+ Logger.Debug(" > Legend handles : {}".format(self._legend.legendHandles))
+ for handler in self._legend.legendHandles: # legend_handles in newer versions of matplotlib ...
+ handler.set_picker(True)
+
# Canvas must be drawn so we can adjust the figure placement:
self._mplCanvas.draw()
self.__adjustFigureMargins(withLegend=True)