Changeset 6d05e1d in sasview for src/sas/qtgui/PlotterBase.py
- Timestamp:
- Dec 6, 2016 5:39:24 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 55d89f8
- Parents:
- b94889a
- git-author:
- Piotr Rozyczko <rozyczko@…> (12/06/16 05:38:55)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (12/06/16 05:39:24)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/PlotterBase.py
ref01be4 r6d05e1d 1 import logging2 import copy3 import numpy4 1 import pylab 5 2 6 3 from PyQt4 import QtGui 7 from PyQt4 import QtCore8 4 9 5 # TODO: Replace the qt4agg calls below with qt5 equivalent. … … 13 9 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas 14 10 from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar 15 from matplotlib.backend_bases import NavigationToolbar216 11 17 12 import matplotlib.pyplot as plt … … 45 40 # set the layout 46 41 layout = QtGui.QVBoxLayout() 42 layout.setMargin(0) 47 43 layout.addWidget(self.canvas) 48 44 49 45 # defaults 50 46 self.current_plot = 111 51 self._data = [] 47 self._data = [] # Original 1D/2D object 48 self._xscale = 'log' 49 self._yscale = 'log' 52 50 self.qx_data = [] 53 51 self.qy_data = [] 54 52 self.color=0 55 53 self.symbol=0 54 self.dimension=1 56 55 self.grid_on = False 57 56 self.scale = 'linear' 57 self.x_label = "log10(x)" 58 self.y_label = "log10(y)" 58 59 59 60 # default color map … … 64 65 65 66 if not quickplot: 67 # set the layout 66 68 layout.addWidget(self.toolbar) 67 69 # Notify the helper 68 70 PlotHelper.addPlot(self) 71 # Add the context menu 72 self.contextMenu() 69 73 # Notify the listeners 70 74 self.parent.communicator.activeGraphsSignal.emit(PlotHelper.currentPlots()) … … 80 84 @data.setter 81 85 def data(self, data=None): 82 """ data setter """83 pass86 """ virtual data setter """ 87 raise ImportError("Data setter must be implemented in derived class.") 84 88 85 89 def title(self, title=""): 86 90 """ title setter """ 87 self.title = title 88 89 def id(self, id=""): 90 """ id setter """ 91 self.id = id 92 91 self._title = title 92 93 #def id(self, id=""): 94 # """ id setter """ 95 # self.id = id 96 97 @property 98 def xLabel(self, xlabel=""): 99 """ x-label setter """ 100 return self.x_label 101 102 @xLabel.setter 93 103 def xLabel(self, xlabel=""): 94 104 """ x-label setter """ 95 105 self.x_label = r'$%s$'% xlabel 96 106 107 @property 108 def yLabel(self, ylabel=""): 109 """ y-label setter """ 110 return self.y_label 111 112 @yLabel.setter 97 113 def yLabel(self, ylabel=""): 98 114 """ y-label setter """ … … 102 118 def yscale(self): 103 119 """ Y-axis scale getter """ 104 return self. yscale120 return self._yscale 105 121 106 122 @yscale.setter 107 123 def yscale(self, scale='linear'): 108 124 """ Y-axis scale setter """ 109 self. subplot.set_yscale(scale, nonposy='clip')110 self. yscale = scale125 self.ax.set_yscale(scale, nonposy='clip') 126 self._yscale = scale 111 127 112 128 @property 113 129 def xscale(self): 114 130 """ X-axis scale getter """ 115 return self. xscale131 return self._xscale 116 132 117 133 @xscale.setter 118 134 def xscale(self, scale='linear'): 119 135 """ X-axis scale setter """ 120 self. subplot.set_xscale(scale)121 self. xscale = scale122 123 def contextMenu QuickPlot(self):136 self.ax.set_xscale(scale) 137 self._xscale = scale 138 139 def contextMenu(self): 124 140 """ 125 141 Define context menu and associated actions for the MPL widget … … 131 147 self.actionCopyToClipboard = self.contextMenu.addAction("Copy to Clipboard") 132 148 self.contextMenu.addSeparator() 133 self.actionToggleGrid = self.contextMenu.addAction("Toggle Grid On/Off")134 self.contextMenu.addSeparator()135 self.actionChangeScale = self.contextMenu.addAction("Change Scale")136 149 137 150 # Define the callbacks … … 139 152 self.actionPrintImage.triggered.connect(self.onImagePrint) 140 153 self.actionCopyToClipboard.triggered.connect(self.onClipboardCopy) 141 self.actionToggleGrid.triggered.connect(self.onGridToggle) 142 self.actionChangeScale.triggered.connect(self.onScaleChange) 154 155 def contextMenuQuickPlot(self): 156 """ 157 Define context menu and associated actions for the quickplot MPL widget 158 """ 159 raise ImportError("Context menu method must be implemented in derived class.") 143 160 144 161 def contextMenuEvent(self, event): … … 217 234 self.ax.grid(self.grid_on) 218 235 self.canvas.draw_idle() 219 220 def onScaleChange(self):221 """222 Show a dialog allowing axes rescaling223 """224 if self.properties.exec_() == QtGui.QDialog.Accepted:225 xLabel, yLabel = self.properties.getValues()226 #self.xyTransform(xLabel, yLabel)227 228 def xyTransform(self, xLabel="", yLabel=""):229 """230 Transforms x and y in View and set the scale231 """232 # The logic should be in the right order233 self.ly = None234 self.q_ctrl = None235 # Changing the scale might be incompatible with236 # currently displayed data (for instance, going237 # from ln to log when all plotted values have238 # negative natural logs).239 # Go linear and only change the scale at the end.240 self.set_xscale("linear")241 self.set_yscale("linear")242 _xscale = 'linear'243 _yscale = 'linear'244 # Local data is either 1D or 2D245 #for item in list:246 #if item.id == 'fit':247 # continue248 item.setLabel(self.xLabel, self.yLabel)249 # control axis labels from the panel itself250 yname, yunits = item.get_yaxis()251 if self.yaxis_label != None:252 yname = self.yaxis_label253 yunits = self.yaxis_unit254 else:255 self.yaxis_label = yname256 self.yaxis_unit = yunits257 xname, xunits = item.get_xaxis()258 if self.xaxis_label != None:259 xname = self.xaxis_label260 xunits = self.xaxis_unit261 else:262 self.xaxis_label = xname263 self.xaxis_unit = xunits264 # Goes through all possible scales265 if self.xLabel == "x":266 item.transformX(transform.toX, transform.errToX)267 self.graph._xaxis_transformed("%s" % xname, "%s" % xunits)268 if self.xLabel == "x^(2)":269 item.transformX(transform.toX2, transform.errToX2)270 xunits = convert_unit(2, xunits)271 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits)272 if self.xLabel == "x^(4)":273 item.transformX(transform.toX4, transform.errToX4)274 xunits = convert_unit(4, xunits)275 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits)276 if self.xLabel == "ln(x)":277 item.transformX(transform.toLogX, transform.errToLogX)278 self.graph._xaxis_transformed("\ln{(%s)}" % xname, "%s" % xunits)279 if self.xLabel == "log10(x)":280 item.transformX(transform.toX_pos, transform.errToX_pos)281 _xscale = 'log'282 self.graph._xaxis_transformed("%s" % xname, "%s" % xunits)283 if self.xLabel == "log10(x^(4))":284 item.transformX(transform.toX4, transform.errToX4)285 xunits = convert_unit(4, xunits)286 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits)287 _xscale = 'log'288 if self.yLabel == "ln(y)":289 item.transformY(transform.toLogX, transform.errToLogX)290 self.graph._yaxis_transformed("\ln{(%s)}" % yname, "%s" % yunits)291 if self.yLabel == "y":292 item.transformY(transform.toX, transform.errToX)293 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits)294 if self.yLabel == "log10(y)":295 item.transformY(transform.toX_pos, transform.errToX_pos)296 _yscale = 'log'297 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits)298 if self.yLabel == "y^(2)":299 item.transformY(transform.toX2, transform.errToX2)300 yunits = convert_unit(2, yunits)301 self.graph._yaxis_transformed("%s^{2}" % yname, "%s" % yunits)302 if self.yLabel == "1/y":303 item.transformY(transform.toOneOverX, transform.errOneOverX)304 yunits = convert_unit(-1, yunits)305 self.graph._yaxis_transformed("1/%s" % yname, "%s" % yunits)306 if self.yLabel == "y*x^(2)":307 item.transformY(transform.toYX2, transform.errToYX2)308 xunits = convert_unit(2, self.xaxis_unit)309 self.graph._yaxis_transformed("%s \ \ %s^{2}" % (yname, xname),310 "%s%s" % (yunits, xunits))311 if self.yLabel == "y*x^(4)":312 item.transformY(transform.toYX4, transform.errToYX4)313 xunits = convert_unit(4, self.xaxis_unit)314 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),315 "%s%s" % (yunits, xunits))316 if self.yLabel == "1/sqrt(y)":317 item.transformY(transform.toOneOverSqrtX,318 transform.errOneOverSqrtX)319 yunits = convert_unit(-0.5, yunits)320 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname,321 "%s" % yunits)322 if self.yLabel == "ln(y*x)":323 item.transformY(transform.toLogXY, transform.errToLogXY)324 self.graph._yaxis_transformed("\ln{(%s \ \ %s)}" % (yname, xname),325 "%s%s" % (yunits, self.xaxis_unit))326 if self.yLabel == "ln(y*x^(2))":327 item.transformY(transform.toLogYX2, transform.errToLogYX2)328 xunits = convert_unit(2, self.xaxis_unit)329 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname),330 "%s%s" % (yunits, xunits))331 if self.yLabel == "ln(y*x^(4))":332 item.transformY(transform.toLogYX4, transform.errToLogYX4)333 xunits = convert_unit(4, self.xaxis_unit)334 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname),335 "%s%s" % (yunits, xunits))336 if self.yLabel == "log10(y*x^(4))":337 item.transformY(transform.toYX4, transform.errToYX4)338 xunits = convert_unit(4, self.xaxis_unit)339 _yscale = 'log'340 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),341 "%s%s" % (yunits, xunits))342 item.transformView()343 344 # set new label and units345 yname = self.graph.prop["ylabel"]346 yunits = ''347 xname = self.graph.prop["xlabel"]348 xunits = ''349 350 self.resetFitView()351 self.prevXtrans = self.xLabel352 self.prevYtrans = self.yLabel353 self.graph.render(self)354 self.set_xscale(_xscale)355 self.set_yscale(_yscale)356 357 self.xaxis(xname, xunits, self.xaxis_font,358 self.xaxis_color, self.xaxis_tick)359 self.yaxis(yname, yunits, self.yaxis_font,360 self.yaxis_color, self.yaxis_tick)361 self.subplot.texts = self.textList362 363 self.canvas.draw_idle()
Note: See TracChangeset
for help on using the changeset viewer.