Changeset 9290b1a in sasview for src/sas/qtgui/Plotter.py
- Timestamp:
- Dec 16, 2016 12:43:18 PM (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:
- d3ca363
- Parents:
- 0ba0774
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Plotter.py
r27313b7 r9290b1a 2 2 3 3 import matplotlib.pyplot as plt 4 4 from matplotlib.font_manager import FontProperties 5 6 from sas.sasgui.guiframe.dataFitting import Data1D 5 7 from sas.sasgui.plottools import transform 6 8 from sas.sasgui.plottools.convert_units import convert_unit 7 9 from sas.qtgui.PlotterBase import PlotterBase 10 from sas.qtgui.AddText import AddText 8 11 9 12 class PlotterWidget(PlotterBase): … … 27 30 self.title(title=value.title) 28 31 29 def plot(self, marker=None, linestyle=None, hide_error=False):32 def plot(self, data=None, marker=None, linestyle=None, hide_error=False): 30 33 """ 31 34 Plot self._data 32 35 """ 36 # Data1D 37 if isinstance(data, Data1D): 38 self.data = data 39 assert(self._data) 40 33 41 # Shortcut for an axis 34 42 ax = self.ax … … 45 53 marker=marker, 46 54 linestyle=linestyle, 47 label=self._title) 55 label=self._title, 56 picker=True) 48 57 else: 49 58 ax.errorbar(self._data.view.x, self._data.view.y, … … 54 63 lolims=False, uplims=False, 55 64 xlolims=False, xuplims=False, 56 label=self._title) 65 label=self._title, 66 picker=True) 57 67 58 68 # Now add the legend with some customizations. 59 legend = ax.legend(loc='upper right', shadow=True) 69 self.legend = ax.legend(loc='upper right', shadow=True) 70 #self.legend.get_frame().set_alpha(0.4) 71 self.legend.set_picker(True) 60 72 61 73 # Current labels for axes … … 142 154 Show a dialog allowing adding custom text to the chart 143 155 """ 144 print("onAddText") 145 pass 156 self.addText = AddText(self) 157 if self.addText.exec_() == QtGui.QDialog.Accepted: 158 # Retrieve the new text, its font and color 159 extra_text = self.addText.text() 160 extra_font = self.addText.font() 161 extra_color = self.addText.color() 162 163 # Place the text on the screen at (0,0) 164 pos_x = self.x_click 165 pos_y = self.y_click 166 167 # Map QFont onto MPL font 168 mpl_font = FontProperties() 169 mpl_font.set_size(int(extra_font.pointSize())) 170 mpl_font.set_family(str(extra_font.family())) 171 mpl_font.set_weight(int(extra_font.weight())) 172 # MPL style names 173 styles = ['normal', 'italic', 'oblique'] 174 # QFont::Style maps directly onto the above 175 try: 176 mpl_font.set_style(styles[extra_font.style()]) 177 except: 178 pass 179 180 if len(extra_text) > 0: 181 new_text = self.ax.text(str(pos_x), 182 str(pos_y), 183 extra_text, 184 color=extra_color, 185 fontproperties=mpl_font) 186 # Update the list of annotations 187 self.textList.append(new_text) 188 self.canvas.draw_idle() 146 189 147 190 def onRemoveText(self): 148 191 """ 149 Remove the most recent added text 150 """ 151 print("onRemoveText") 152 pass 192 Remove the most recently added text 193 """ 194 num_text = len(self.textList) 195 if num_text < 1: 196 return 197 txt = self.textList[num_text - 1] 198 text_remove = txt.get_text() 199 txt.remove() 200 self.textList.remove(txt) 201 202 self.canvas.draw_idle() 153 203 154 204 def onSetGraphRange(self): … … 172 222 # Clear the plot first 173 223 plt.cla() 224 self.ax.cla() 174 225 175 226 # Changing the scale might be incompatible with
Note: See TracChangeset
for help on using the changeset viewer.