Changeset 10bfeb3 in sasview
- Timestamp:
- Apr 27, 2012 10:23:08 AM (13 years ago)
- Branches:
- master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f60a8c2
- Parents:
- 8a621ac
- Location:
- plottools/src/danse/common/plottools
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
plottools/src/danse/common/plottools/BaseInteractor.py
r82a54b8 r10bfeb3 22 22 update() - draw the interactors 23 23 24 The following are provided by the base class: 24 The following are provided by the base class: 25 25 26 26 connect_markers(markers) - register callbacks for all markers … … 53 53 Clear old markers and interfaces. 54 54 ''' 55 for h in self.markers: h.remove() 56 if self.markers: self.base.connect.clear(*self.markers) 55 for h in self.markers: 56 h.remove() 57 if self.markers: 58 self.base.connect.clear(*self.markers) 57 59 self.markers = [] 58 60 … … 127 129 the mouse leaves the window. 128 130 """ 129 inside, prop= self.axes.contains(ev)131 inside, _ = self.axes.contains(ev) 130 132 if inside: 131 133 self.clickx, self.clicky = ev.xdata, ev.ydata … … 147 149 elif ev.key in ['up', 'down', 'right', 'left']: 148 150 dx, dy = self.dpixel(self.clickx, self.clicky, nudge=ev.control) 149 if ev.key == 'up': self.clicky += dy 150 elif ev.key == 'down': self.clicky -= dy 151 elif ev.key == 'right': self.clickx += dx 152 else: self.clickx -= dx 151 if ev.key == 'up': 152 self.clicky += dy 153 elif ev.key == 'down': 154 self.clicky -= dy 155 elif ev.key == 'right': 156 self.clickx += dx 157 else: 158 self.clickx -= dx 153 159 self.move(self.clickx, self.clicky, ev) 154 160 else: … … 172 178 dx, dy = nx-x, ny-y 173 179 return dx, dy 174 -
plottools/src/danse/common/plottools/PlotPanel.py
r6e75ed0 r10bfeb3 13 13 from matplotlib.figure import Figure 14 14 import os 15 import fittings16 15 import transform 17 from matplotlib.widgets import RectangleSelector18 from pylab import gca, gcf19 16 from plottables import Data1D 20 17 #TODO: make the plottables interactive 21 18 from binder import BindArtist 22 19 from matplotlib.font_manager import FontProperties 23 24 #from matplotlib import cm25 #from matplotlib.ticker import LinearLocator, FixedLocator, FormatStrFormatter26 27 20 DEBUG = False 28 21 … … 33 26 import operator 34 27 35 import math, pylab, re 28 import math 29 import pylab 36 30 DEFAULT_CMAP = pylab.cm.jet 37 31 import copy 38 32 import numpy 39 33 40 def show_tree(obj,d=0): 34 35 def show_tree(obj, d=0): 41 36 """Handy function for displaying a tree of graph objects""" 42 37 print "%s%s" % ("-"*d, obj.__class__.__name__) … … 44 39 for a in obj.get_children(): show_tree(a, d+1) 45 40 46 from unitConverter import UnitConvertion as convertUnit 41 from unitConverter import UnitConvertion as convertUnit 42 47 43 48 44 def _rescale(lo, hi, step, pt=None, bal=None, scale='linear'): … … 60 56 loprev = lo 61 57 hiprev = hi 62 ptprev = pt63 58 if scale == 'log': 64 59 assert lo > 0 65 if lo > 0 60 if lo > 0: 66 61 lo = math.log10(lo) 67 if hi > 0 62 if hi > 0: 68 63 hi = math.log10(hi) 69 if pt is not None: pt = math.log10(pt) 64 if pt is not None: 65 pt = math.log10(pt) 70 66 71 67 # Compute delta from axis range * %, or 1-% if persent is negative … … 94 90 95 91 def CopyImage(canvas): 96 """ 97 0: matplotlib plot 98 1: wx.lib.plot 99 2: other 100 101 """ 102 bmp = wx.BitmapDataObject() 103 bmp.SetBitmap(canvas.bitmap) 104 105 wx.TheClipboard.Open() 106 wx.TheClipboard.SetData(bmp) 107 wx.TheClipboard.Close() 92 """ 93 0: matplotlib plot 94 1: wx.lib.plot 95 2: other 96 """ 97 bmp = wx.BitmapDataObject() 98 bmp.SetBitmap(canvas.bitmap) 99 100 wx.TheClipboard.Open() 101 wx.TheClipboard.SetData(bmp) 102 wx.TheClipboard.Close() 108 103 109 104 … … 116 111 """ 117 112 def __init__(self, parent, id=-1, xtransform=None, 118 ytransform=None, scale='log_{10}', 113 ytransform=None, scale='log_{10}', 119 114 color=None, dpi=None, **kwargs): 120 115 """ … … 123 118 self.parent = parent 124 119 self.dimension = 1 125 self.gotLegend = 0 # to begin, legend is not picked.120 self.gotLegend = 0 # to begin, legend is not picked. 126 121 self.legend_pos_loc = None 127 122 self.legend = None 128 self.line_collections_list = [] 123 self.line_collections_list = [] 129 124 self.figure = Figure(None, dpi, linewidth=2.0) 130 self.color = '#b3b3b3' 125 self.color = '#b3b3b3' 131 126 from canvas import FigureCanvas 132 self.canvas = FigureCanvas(self, -1, self.figure) 127 self.canvas = FigureCanvas(self, -1, self.figure) 133 128 self.SetColor(color) 134 129 #self.SetBackgroundColour(parent.GetBackgroundColour()) 135 130 self._resizeflag = True 136 self._SetSize() 131 self._SetSize() 137 132 self.subplot = self.figure.add_subplot(111) 138 133 self.figure.subplots_adjust(left=0.2, bottom=.2) … … 171 166 if xtransform != None: 172 167 self.xLabel = xtransform 173 else: 168 else: 174 169 self.xLabel = "log10(x)" 175 170 if ytransform != None: … … 203 198 #self.selected_plottable = None 204 199 205 # new data for the fit 200 # new data for the fit 206 201 self.fit_result = Data1D(x=[], y=[], dy=None) 207 202 self.fit_result.symbol = 13 … … 239 234 self.zmax_2D = None 240 235 241 #index array 236 #index array 242 237 self.index_x = None 243 238 self.index_y = None … … 275 270 276 271 # Default locations 277 self._default_save_location = os.getcwd() 272 self._default_save_location = os.getcwd() 278 273 # let canvas know about axes 279 274 self.canvas.set_panel(self) 280 275 281 #Bind focus to change the border color 276 #Bind focus to change the border color 282 277 self.canvas.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) 283 278 self.canvas.Bind(wx.EVT_KILL_FOCUS, self.on_kill_focus) … … 288 283 pixels = self.parent.GetClientSize() 289 284 self.canvas.SetSize(pixels) 290 self.figure.set_size_inches( (pixels[0])/self.figure.get_dpi(),291 (pixels[1])/self.figure.get_dpi(), forward=True )285 self.figure.set_size_inches(pixels[0] / self.figure.get_dpi(), 286 pixels[1] / self.figure.get_dpi(), forward=True) 292 287 293 288 def On_Paint(self, event): … … 295 290 """ 296 291 self.canvas.SetBackgroundColour(self.color) 297 #dc = wx.PaintDC(self.canvas) 298 #dc.SetPen(wx.Pen(self.color)) 299 #x, y = self.GetSize() 300 #dc.DrawRectangle(0, 0, x, y) 301 #dc.DrawRectangle(1, 1, x-1, y-1) 302 #self.draw() 292 303 293 def on_set_focus(self, event): 304 294 """ … … 323 313 Set the resizing (True/False) 324 314 """ 325 pass # Not implemented315 pass # Not implemented 326 316 327 def schedule_full_draw(self, func='append'): 317 def schedule_full_draw(self, func='append'): 328 318 """ 329 319 Put self in schedule to full redraw list 330 320 """ 331 pass # Not implemented321 pass # Not implemented 332 322 333 323 def add_toolbar(self): … … 359 349 self.toolbar.update() 360 350 361 def onLeftDown(self, event): 351 def onLeftDown(self, event): 362 352 """ 363 353 left button down and ready to drag … … 371 361 self.xInit, self.yInit = event.xdata, event.ydata 372 362 try: 373 pos_x = float(event.xdata) # / size_x374 pos_y = float(event.ydata) # / size_y375 pos_x = "%8.3g" % pos_x376 pos_y = "%8.3g" % pos_y363 pos_x = float(event.xdata) # / size_x 364 pos_y = float(event.ydata) # / size_y 365 pos_x = "%8.3g" % pos_x 366 pos_y = "%8.3g" % pos_y 377 367 self.position = str(pos_x), str(pos_y) 378 368 wx.PostEvent(self.parent, StatusEvent(status=self.position)) 379 369 except: 380 self.position = None 381 #size_x, size_y = self.GetClientSizeTuple() 382 383 384 def onLeftUp(self, event): 370 self.position = None 371 372 def onLeftUp(self, event): 385 373 """ 386 374 Dragging is done 387 388 375 """ 389 376 # Check that the LEFT button was released 390 377 if event.button == 1: 391 378 self.leftdown = False 392 self.mousemotion = False 379 self.mousemotion = False 393 380 self.leftup = True 394 381 395 #release the legend 382 #release the legend 396 383 if self.gotLegend == 1: 397 384 self.gotLegend = 0 … … 405 392 self.legend.legendPatch.set_alpha(alpha) 406 393 407 def onPick(self, event): 394 def onPick(self, event): 408 395 """ 409 396 On pick legend … … 412 399 if event.artist == legend: 413 400 #gets the box of the legend. 414 bbox = self.legend.get_window_extent() 401 bbox = self.legend.get_window_extent() 415 402 #get mouse coordinates at time of pick. 416 self.mouse_x = event.mouseevent.x 403 self.mouse_x = event.mouseevent.x 417 404 self.mouse_y = event.mouseevent.y 418 405 #get legend coordinates at time of pick. 419 self.legend_x = bbox.xmin 406 self.legend_x = bbox.xmin 420 407 self.legend_y = bbox.ymin 421 408 #indicates we picked up the legend. 422 self.gotLegend = 1 409 self.gotLegend = 1 423 410 self.set_legend_alpha(0.5) 424 425 426 def _on_legend_motion(self, event): 411 412 def _on_legend_motion(self, event): 427 413 """ 428 414 On legend in motion … … 435 421 lo_y, hi_y = ax.get_ylim() 436 422 # How much the mouse moved. 437 x = mouse_diff_x = self.mouse_x - event.x 423 x = mouse_diff_x = self.mouse_x - event.x 438 424 y = mouse_diff_y = self.mouse_y - event.y 439 425 # Put back inside … … 444 430 if y < lo_y: 445 431 y = lo_y 446 if y > hi_y:432 if y > hi_y: 447 433 y = hi_y 448 434 # Move the legend from its previous location by that same amount … … 456 442 self.resizing = True 457 443 self.canvas.set_resizing(self.resizing) 458 self.canvas.draw() 444 self.canvas.draw() 459 445 460 def onMouseMotion(self, event): 446 def onMouseMotion(self, event): 461 447 """ 462 448 check if the left button is press and the mouse in moving. 463 computer delta for x and y coordinates and then calls draghelper 449 computer delta for x and y coordinates and then calls draghelper 464 450 to perform the drag 465 451 … … 471 457 #Disable dragging without the toolbar to allow zooming with toolbar 472 458 return 473 self.mousemotion = True 459 self.mousemotion = True 474 460 if self.leftdown == True and self.mousemotion == True: 475 461 ax = event.inaxes 476 if ax != None: #the dragging is perform inside the figure462 if ax != None: # the dragging is perform inside the figure 477 463 self.xFinal, self.yFinal = event.xdata, event.ydata 478 464 # Check whether this is the first point … … 489 475 ydelta = math.log10(self.yFinal) - math.log10(self.yInit) 490 476 self._dragHelper(xdelta, ydelta) 491 else:# no dragging is perform elsewhere 492 self._dragHelper(0,0) 493 494 477 else: # no dragging is perform elsewhere 478 self._dragHelper(0, 0) 479 495 480 def _offset_graph(self): 496 481 """ 497 Zoom and offset the graph to the last known settings 498 482 Zoom and offset the graph to the last known settings 499 483 """ 500 484 for ax in self.axes: … … 580 564 # Event occurred inside a plotting area 581 565 lo, hi = ax.get_xlim() 582 lo, hi = _rescale(lo, hi, step, 566 lo, hi = _rescale(lo, hi, step, 583 567 pt=event.xdata, scale=ax.get_xscale()) 584 568 if not self.xscale == 'log' or lo > 0: … … 593 577 self._scale_ylo = lo 594 578 self._scale_yhi = hi 595 ax.set_ylim((lo, hi))579 ax.set_ylim((lo, hi)) 596 580 else: 597 581 # Check if zoom happens in the axes … … 602 586 insidex, _ = ax.xaxis.contains(event) 603 587 if insidex: 604 xdata, _ = ax.transAxes.inverted().transform_point((x, y)) 605 #xdata,_ = ax.transAxes.inverse_xy_tup((x,y)) 588 xdata, _ = ax.transAxes.inverted().transform_point((x, y)) 606 589 insidey, _ = ax.yaxis.contains(event) 607 590 if insidey: 608 _, ydata = ax.transAxes.inverted().transform_point((x, y)) 609 #_,ydata = ax.transAxes.inverse_xy_tup((x,y)) 591 _, ydata = ax.transAxes.inverted().transform_point((x, y)) 610 592 if xdata is not None: 611 593 lo, hi = ax.get_xlim() 612 lo, hi = _rescale(lo, hi, step, 594 lo, hi = _rescale(lo, hi, step, 613 595 bal=xdata, scale=ax.get_xscale()) 614 596 if not self.xscale == 'log' or lo > 0: … … 618 600 if ydata is not None: 619 601 lo, hi = ax.get_ylim() 620 lo, hi = _rescale(lo, hi, step, bal=ydata, 602 lo, hi = _rescale(lo, hi, step, bal=ydata, 621 603 scale=ax.get_yscale()) 622 if not self.yscale =='log' or lo>0:604 if not self.yscale == 'log' or lo > 0: 623 605 self._scale_ylo = lo 624 606 self._scale_yhi = hi … … 630 612 Return values and labels used by Fit Dialog 631 613 """ 632 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue,\614 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue,\ 633 615 self.ErrAvalue, self.ErrBvalue, self.Chivalue 634 616 635 def setTrans(self, xtrans, ytrans): 617 def setTrans(self, xtrans, ytrans): 636 618 """ 637 619 … … 643 625 self.prevYtrans = ytrans 644 626 645 def onFitting(self, event): 627 def onFitting(self, event): 646 628 """ 647 629 when clicking on linear Fit on context menu , display Fitting Dialog … … 660 642 from fitDialog import LinearFit 661 643 662 if len(list.keys()) >0:644 if len(list.keys()) > 0: 663 645 first_item = list.keys()[0] 664 dlg = LinearFit(parent=None, plottable=first_item, 646 dlg = LinearFit(parent=None, plottable=first_item, 665 647 push_data=self.onFitDisplay, 666 transform=self.returnTrans, 648 transform=self.returnTrans, 667 649 title='Linear Fit') 668 650 669 651 if (self.xmin != 0.0)and (self.xmax != 0.0)\ 670 652 and(self.xminView != 0.0)and (self.xmaxView != 0.0): 671 dlg.setFitRange(self.xminView, self.xmaxView, 653 dlg.setFitRange(self.xminView, self.xmaxView, 672 654 self.xmin, self.xmax) 673 dlg.ShowModal() 655 dlg.ShowModal() 674 656 675 657 def set_selected_from_menu(self, menu, id): … … 688 670 break 689 671 690 def linear_plottable_fit(self, plot): 691 """ 692 when clicking on linear Fit on context menu 672 def linear_plottable_fit(self, plot): 673 """ 674 when clicking on linear Fit on context menu, display Fitting Dialog 693 675 694 676 :param plot: PlotPanel owning the graph … … 706 688 self._fit_dialog.register_close(self._linear_fit_close) 707 689 # Show a non-model dialog 708 self._fit_dialog.Show() 690 self._fit_dialog.Show() 709 691 710 692 def _linear_fit_close(self): … … 714 696 self._fit_dialog = None 715 697 716 717 698 def _onProperties(self, event): 718 699 """ 719 700 when clicking on Properties on context menu , 720 701 The Property dialog is displayed 721 The user selects a transformation for x or y value and 702 The user selects a transformation for x or y value and 722 703 a new plot is displayed 723 704 """ … … 734 715 dial.setValues(self.prevXtrans, self.prevYtrans, self.viewModel) 735 716 if dial.ShowModal() == wx.ID_OK: 736 self.xLabel, self.yLabel, self.viewModel = dial.getValues()717 self.xLabel, self.yLabel, self.viewModel = dial.getValues() 737 718 if self.viewModel == "Guinier lny vs x^(2)": 738 719 self.xLabel = "x^(2)" … … 809 790 self.draw() 810 791 811 def _SetSize(self, pixels =None):792 def _SetSize(self, pixels=None): 812 793 """ 813 794 This method can be called to force the Plot to be a desired size, … … 818 799 pixels = tuple(self.GetClientSize()) 819 800 self.canvas.SetSize(pixels) 820 self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(),821 float( pixels[1] )/self.figure.get_dpi() )801 self.figure.set_size_inches(float(pixels[0]) / self.figure.get_dpi(), 802 float(pixels[1]) / self.figure.get_dpi()) 822 803 823 804 def draw(self): … … 828 809 self.figure.canvas.draw_idle() 829 810 830 831 #pick up the legend patch832 811 def legend_picker(self, legend, event): 833 return self.legend.legendPatch.contains(event) 812 """ 813 Pick up the legend patch 814 """ 815 return self.legend.legendPatch.contains(event) 834 816 835 817 def get_loc_label(self): … … 880 862 881 863 id = wx.NewId() 882 slicerpop.Append(id, '&Printer setup', 'Set image size')864 slicerpop.Append(id, '&Printer setup', 'Set image size') 883 865 wx.EVT_MENU(self, id, self.onPrinterSetup) 884 866 885 867 id = wx.NewId() 886 slicerpop.Append(id, '&Printer Preview', 'Set image size')868 slicerpop.Append(id, '&Printer Preview', 'Set image size') 887 869 wx.EVT_MENU(self, id, self.onPrinterPreview) 888 870 … … 968 950 handles2, labels2 = zip(*hl) 969 951 self.line_collections_list = handles2 970 self.legend = self.subplot.legend(handles2, labels2, 952 self.legend = self.subplot.legend(handles2, labels2, 971 953 prop=FontProperties(size=10), numpoints=1, 972 954 handletextsep=.05, loc=self.legendLoc) 973 955 if self.legend != None: 974 self.legend.set_picker(self.legend_picker) 975 self.legend.set_axes(self.subplot) 976 977 self.subplot.figure.canvas.draw_idle() 956 self.legend.set_picker(self.legend_picker) 957 self.legend.set_axes(self.subplot) 958 959 self.subplot.figure.canvas.draw_idle() 978 960 self.legend_on = not self.legend_on 979 961 … … 984 966 menu = event.GetEventObject() 985 967 id = event.GetId() 986 label = 968 label = menu.GetLabel(id) 987 969 988 970 self.legendLoc = label … … 994 976 handles2, labels2 = zip(*hl) 995 977 self.line_collections_list = handles2 996 self.legend = self.subplot.legend(handles2, labels2, 997 prop=FontProperties(size=10), 978 self.legend = self.subplot.legend(handles2, labels2, 979 prop=FontProperties(size=10), numpoints=1, 998 980 handletextsep=.05, loc=self.legendLoc) 999 981 if self.legend != None: 1000 self.legend.set_picker(self.legend_picker) 1001 self.legend.set_axes(self.subplot) 1002 self.subplot.figure.canvas.draw_idle() 1003 #self._onEVT_FUNC_PROPERTY() 982 self.legend.set_picker(self.legend_picker) 983 self.legend.set_axes(self.subplot) 984 self.subplot.figure.canvas.draw_idle() 1004 985 1005 986 def remove_legend(self, ax=None): … … 1007 988 Remove legend for ax or the current axes. 1008 989 """ 1009 from pylab import gca , draw990 from pylab import gca 1010 991 if ax is None: 1011 992 ax = gca() 1012 993 ax.legend_ = None 1013 #draw() 1014 1015 def _on_addtext(self, event): 994 995 def _on_addtext(self, event): 1016 996 """ 1017 997 Allows you to add text to the plot … … 1038 1018 colour = textdial.getColor() 1039 1019 if len(label) > 0 and xpos > 0 and ypos > 0: 1040 new_text = self.subplot.text(str(xpos), str(ypos), label, 1020 new_text = self.subplot.text(str(xpos), str(ypos), label, 1041 1021 fontproperties=font, 1042 1022 color=colour) 1043 1023 self.textList.append(new_text) 1044 self.subplot.figure.canvas.draw_idle() 1024 self.subplot.figure.canvas.draw_idle() 1045 1025 except: 1046 1026 if self.parent != None: 1047 1027 from sans.guiframe.events import StatusEvent 1048 msg = "Add Text: Error. Check your property values..."1028 msg = "Add Text: Error. Check your property values..." 1049 1029 wx.PostEvent(self.parent, StatusEvent(status = msg )) 1050 1030 else: … … 1055 1035 #based on this and plot it at user designated coordinates 1056 1036 1057 def onGridOnOff(self, event): 1037 def onGridOnOff(self, event): 1058 1038 """ 1059 1039 Allows ON/OFF Grid … … 1065 1045 self.subplot.figure.canvas.draw_idle() 1066 1046 1067 def _on_xaxis_label(self, event): 1047 def _on_xaxis_label(self, event): 1068 1048 """ 1069 1049 Allows you to add text to the plot … … 1090 1070 self._check_zoom_plot() 1091 1071 1092 def _check_zoom_plot(self): 1072 def _check_zoom_plot(self): 1093 1073 """ 1094 1074 Check the zoom range and plot (1D only) … … 1102 1082 if self.is_zoomed or toolbar_zoomed: 1103 1083 # Recover the x,y limits 1104 self.subplot.set_xlim((xlo, xhi)) 1105 self.subplot.set_ylim((ylo, yhi)) 1084 self.subplot.set_xlim((xlo, xhi)) 1085 self.subplot.set_ylim((ylo, yhi)) 1106 1086 1107 def _on_yaxis_label(self, event): 1087 def _on_yaxis_label(self, event): 1108 1088 """ 1109 1089 Allows you to add text to the plot … … 1130 1110 self._check_zoom_plot() 1131 1111 1132 1133 1112 def _on_axis_label(self, axis='x'): 1134 1113 """ … … 1138 1117 """ 1139 1118 is_ok = True 1140 title = 'Modify %s axis label' % axis1119 title = 'Modify %s axis label' % axis 1141 1120 font = 'serif' 1142 1121 colour = 'black' … … 1147 1126 label = self.yaxis_label 1148 1127 unit = self.yaxis_unit 1149 textdial = TextDialog(None, -1, title, label, unit) 1128 textdial = TextDialog(None, -1, title, label, unit) 1150 1129 if textdial.ShowModal() == wx.ID_OK: 1151 1130 try: … … 1160 1139 is_tick = textdial.getTickLabel() 1161 1140 label_temp = textdial.getText() 1162 if label_temp.count("\%s" % "\\") > 0:1141 if label_temp.count("\%s" % "\\") > 0: 1163 1142 if self.parent != None: 1164 1143 from sans.guiframe.events import StatusEvent 1165 msg = "Add Label: Error. Can not use double '\\' "1144 msg = "Add Label: Error. Can not use double '\\' " 1166 1145 msg += "characters..." 1167 wx.PostEvent(self.parent, StatusEvent(status = msg))1146 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1168 1147 else: 1169 1148 label = label_temp 1170 1149 except: 1171 1150 if self.parent != None: 1172 from sans.guiframe.events import StatusEvent 1173 msg = "Add Label: Error. Check your property values..."1174 wx.PostEvent(self.parent, StatusEvent(status = msg))1151 from sans.guiframe.events import StatusEvent 1152 msg = "Add Label: Error. Check your property values..." 1153 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1175 1154 else: 1176 1155 pass … … 1189 1168 if num_text < 1: 1190 1169 if self.parent != None: 1191 from sans.guiframe.events import StatusEvent 1170 from sans.guiframe.events import StatusEvent 1192 1171 msg= "Remove Text: Nothing to remove. " 1193 wx.PostEvent(self.parent, StatusEvent(status = msg))1172 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1194 1173 else: 1195 1174 raise … … 1200 1179 txt.remove() 1201 1180 if self.parent != None: 1202 from sans.guiframe.events import StatusEvent 1181 from sans.guiframe.events import StatusEvent 1203 1182 msg= "Removed Text: '%s'. " % text_remove 1204 wx.PostEvent(self.parent, StatusEvent(status = msg))1183 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1205 1184 except: 1206 1185 if self.parent != None: 1207 from sans.guiframe.events import StatusEvent 1186 from sans.guiframe.events import StatusEvent 1208 1187 msg= "Remove Text: Error occurred. " 1209 wx.PostEvent(self.parent, StatusEvent(status = msg))1188 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1210 1189 else: 1211 1190 raise 1212 1191 self.textList.remove(txt) 1213 1192 1214 self.subplot.figure.canvas.draw_idle() 1193 self.subplot.figure.canvas.draw_idle() 1215 1194 1216 1195 def properties(self, prop): … … 1220 1199 1221 1200 """ 1222 # The particulars of how they are stored and manipulated (e.g., do 1201 # The particulars of how they are stored and manipulated (e.g., do 1223 1202 # we want an inventory internally) is not settled. I've used a 1224 1203 # property dictionary for now. … … 1231 1210 self.subplot.set_ylabel(r"$%s$" % prop["ylabel"]) 1232 1211 self.subplot.set_title(prop["title"]) 1233 1234 # Properties defined by user1235 #self.axes.grid(True)1236 1212 1237 1213 def clear(self): … … 1245 1221 """Commit the plot after all objects are drawn""" 1246 1222 # TODO: this is when the backing store should be swapped in. 1247 if self.legend_on: 1223 if self.legend_on: 1248 1224 ax = self.subplot 1249 1225 ax.texts = self.textList … … 1255 1231 handles2, labels2 = zip(*hl) 1256 1232 self.line_collections_list = handles2 1257 self.legend = ax.legend(handles2, labels2, 1258 prop=FontProperties(size=10), 1233 self.legend = ax.legend(handles2, labels2, numpoints=1, 1234 prop=FontProperties(size=10), 1259 1235 handletextsep=.05, loc=self.legendLoc) 1260 1236 if self.legend != None: 1261 1237 self.legend.set_picker(self.legend_picker) 1262 self.legend.set_axes(self.subplot) 1238 self.legend.set_axes(self.subplot) 1263 1239 1264 1240 except: 1265 self.legend = ax.legend(prop=FontProperties(size=10), numpoints=1, 1266 handletextsep=.05, loc=self.legendLoc) 1241 self.legend = ax.legend(prop=FontProperties(size=10), 1242 numpoints=1, handletextsep=.05, 1243 loc=self.legendLoc) 1267 1244 1268 1245 def xaxis(self, label, units, font=None, color='black', t_font=None): … … 1276 1253 1277 1254 """ 1278 if units != "": 1255 if units != "": 1279 1256 label = label + " (" + units + ")" 1280 1257 if label.count("{") > 0 and label.count("$") < 2: … … 1284 1261 if t_font != None: 1285 1262 for tick in self.subplot.xaxis.get_major_ticks(): 1286 tick.label.set_fontproperties(t_font) 1263 tick.label.set_fontproperties(t_font) 1287 1264 for line in self.subplot.xaxis.get_ticklines(): 1288 1265 size = t_font.get_size() 1289 1266 line.set_markersize(size / 3) 1290 #line.set_markeredgewidth(int(size / 24 + 1))1291 1267 else: 1292 1268 self.subplot.set_xlabel(label, color=color) … … 1295 1271 def yaxis(self, label, units, font=None, color='black', t_font=None): 1296 1272 """yaxis label and units.""" 1297 if units != "": 1273 if units != "": 1298 1274 label = label + " (" + units + ")" 1299 1275 if label.count("{") > 0 and label.count("$") < 2: … … 1311 1287 pass 1312 1288 1313 def _connect_to_xlim(self, callback):1289 def _connect_to_xlim(self, callback): 1314 1290 """Bind the xlim change notification to the callback""" 1315 1291 def process_xlim(axes): … … 1317 1293 callback(lo, hi) 1318 1294 self.subplot.callbacks.connect('xlim_changed', process_xlim) 1319 1320 #def connect(self,trigger,callback):1321 # print "PlotPanel.connect???"1322 # if trigger == 'xlim': self._connect_to_xlim(callback)1323 1295 1324 1296 def interactive_points(self, x, y, dx=None, dy=None, name='', color=0, 1325 symbol=0, markersize=5, id=None, label=None, hide_error=False): 1297 symbol=0, markersize=5, id=None, label=None, 1298 hide_error=False): 1326 1299 """Draw markers with error bars""" 1327 1300 self.subplot.set_yscale('linear') … … 1336 1309 hide_error=hide_error) 1337 1310 1338 self.subplot.set_yscale(self.yscale, nonposy='clip')1311 self.subplot.set_yscale(self.yscale, nonposy='clip') 1339 1312 self.subplot.set_xscale(self.xscale) 1340 1313 1341 1342 def interactive_curve(self,x,y,dy=None,name='',color=0,symbol=0,id=None,label=None):1314 def interactive_curve(self, x, y, dy=None, name='', color=0, 1315 symbol=0, id=None, label=None): 1343 1316 """Draw markers with error bars""" 1344 1317 self.subplot.set_yscale('linear') … … 1350 1323 p.curve(x, y, dy=dy, color=color, symbol=symbol, label=label) 1351 1324 1352 self.subplot.set_yscale(self.yscale, nonposy='clip')1325 self.subplot.set_yscale(self.yscale, nonposy='clip') 1353 1326 self.subplot.set_xscale(self.xscale) 1354 1327 1355 1356 1328 def plottable_selected(self, id): 1357 1329 """ … … 1362 1334 1363 1335 def points(self, x, y, dx=None, dy=None, 1364 color=0, symbol=0, marker_size=5, label=None,id=None, hide_error=False): 1336 color=0, symbol=0, marker_size=5, label=None, 1337 id=None, hide_error=False): 1365 1338 """Draw markers with error bars""" 1366 #self.subplot.set_yscale('linear')1367 #self.subplot.set_xscale('linear')1368 1339 1369 1340 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] … … 1377 1348 linestyle='', 1378 1349 label=label) 1379 1380 1350 else: 1381 1351 col = self._color(color) 1382 1352 if hide_error: 1383 1353 h = self.subplot.plot(x, y, color=col, 1384 marker=self._symbol(symbol), markersize=marker_size, 1354 marker=self._symbol(symbol), 1355 markersize=marker_size, 1385 1356 linestyle='', 1386 1357 label=label) 1387 1388 1358 else: 1389 h = self.subplot.errorbar(x, y, yerr=dy, xerr=None,1390 ecolor=col, capsize=2, linestyle='', 1359 h = self.subplot.errorbar(x, y, yerr=dy, xerr=None, 1360 ecolor=col, capsize=2, linestyle='', 1391 1361 barsabove=False, 1392 1362 mec=col, mfc=col, … … 1423 1393 zmax_2D_temp = math.log10(self.zmax_2D) 1424 1394 1425 self.image(data=self.data, qx_data=self.qx_data, 1426 qy_data=self.qy_data, xmin=self.xmin_2D, 1395 self.image(data=self.data, qx_data=self.qx_data, 1396 qy_data=self.qy_data, xmin=self.xmin_2D, 1427 1397 xmax=self.xmax_2D, 1428 ymin=self.ymin_2D, ymax=self.ymax_2D, 1398 ymin=self.ymin_2D, ymax=self.ymax_2D, 1429 1399 cmap=self.cmap, zmin=zmin_2D_temp, 1430 1400 zmax=zmax_2D_temp) 1431 1401 1432 def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 1433 zmin, zmax, color=0, symbol=0, markersize=0, label='data2D', cmap=DEFAULT_CMAP): 1402 def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 1403 zmin, zmax, color=0, symbol=0, markersize=0, 1404 label='data2D', cmap=DEFAULT_CMAP): 1434 1405 """ 1435 1406 Render the current data … … 1443 1414 self.ymin_2D = ymin 1444 1415 self.ymax_2D = ymax 1445 self.zmin_2D = zmin 1416 self.zmin_2D = zmin 1446 1417 self.zmax_2D = zmax 1447 1418 c = self._color(color) … … 1449 1420 if self.data == None: 1450 1421 return 1451 if self.data.ndim == 1: 1422 if self.data.ndim == 1: 1452 1423 output = self._build_matrix() 1453 1424 else: … … 1456 1427 if self.scale == 'log_{10}': 1457 1428 try: 1458 if self.zmin_2D <= 0 andlen(output[output > 0]) > 0:1459 zmin_temp = self.zmin_2D 1429 if self.zmin_2D <= 0 and len(output[output > 0]) > 0: 1430 zmin_temp = self.zmin_2D 1460 1431 output[output>0] = numpy.log10(output[output>0]) 1461 1432 #In log scale Negative values are not correct in general 1462 1433 #output[output<=0] = math.log(numpy.min(output[output>0])) 1463 elif self.zmin_2D 1434 elif self.zmin_2D <= 0: 1464 1435 zmin_temp = self.zmin_2D 1465 output[output>0] = numpy.zeros(len(output)) 1466 output[output<=0] = -32 1436 output[output>0] = numpy.zeros(len(output)) 1437 output[output<=0] = -32 1467 1438 else: 1468 1439 zmin_temp = self.zmin_2D … … 1481 1452 self.subplot.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 1482 1453 1483 im = self.subplot.imshow(output, interpolation='nearest', 1454 im = self.subplot.imshow(output, interpolation='nearest', 1484 1455 origin='lower', 1485 1456 vmin=zmin_temp, vmax=self.zmax_2D, 1486 cmap=self.cmap, 1457 cmap=self.cmap, 1487 1458 extent=(self.xmin_2D, self.xmax_2D, 1488 1459 self.ymin_2D, self.ymax_2D)) … … 1494 1465 self.subplot.figure.clear() 1495 1466 1496 self.subplot.figure.subplots_adjust(left=0.1, right=.8, bottom=.1) 1467 self.subplot.figure.subplots_adjust(left=0.1, right=.8, bottom=.1) 1497 1468 1498 1469 X = self.x_bins[0:-1] … … 1514 1485 logging.error("PlotPanel could not import Axes3D") 1515 1486 self.subplot.figure.clear() 1516 ax = 1487 ax = Axes3D(self.subplot.figure) 1517 1488 if len(X) > 60: 1518 1489 ax.cla() … … 1521 1492 im = ax.plot_surface(X, Y, output, rstride=1, cstride=1, cmap=cmap, 1522 1493 linewidth=0, antialiased=False) 1523 #ax.set_zlim3d(zmin_temp, self.zmax_2D) 1524 #ax.set_frame_on(False) 1525 self.subplot.set_axis_off() 1494 self.subplot.set_axis_off() 1526 1495 1527 1496 if cbax == None: 1528 1497 ax.set_frame_on(False) 1529 cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20)1498 cb = self.subplot.figure.colorbar(im, shrink=0.8, aspect=20) 1530 1499 else: 1531 cb = self.subplot.figure.colorbar(im, cax=cbax)1500 cb = self.subplot.figure.colorbar(im, cax=cbax) 1532 1501 cb.update_bruteforce(im) 1533 1502 cb.set_label('$' + self.scale + '$') … … 1538 1507 1539 1508 def _build_matrix(self): 1540 """ 1509 """ 1541 1510 Build a matrix for 2d plot from a vector 1542 1511 Returns a matrix (image) with ~ square binning 1543 Requirement: need 1d array formats of 1512 Requirement: need 1d array formats of 1544 1513 self.data, self.qx_data, and self.qy_data 1545 1514 where each one corresponds to z, x, or y axis values … … 1561 1530 #Note: Can not use scipy.interpolate.Rbf: 1562 1531 # 'cause too many data points (>10000)<=JHC. 1563 # 1d array to use for weighting the data point averaging 1564 #when they fall into a same bin. 1565 weights_data 1566 # get histogram of ones w/len(data); this will provide 1532 # 1d array to use for weighting the data point averaging 1533 #when they fall into a same bin. 1534 weights_data = numpy.ones([self.data.size]) 1535 # get histogram of ones w/len(data); this will provide 1567 1536 #the weights of data on each bins 1568 weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1537 weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1569 1538 y=self.qx_data, 1570 1571 1539 bins=[self.y_bins, self.x_bins], 1540 weights=weights_data) 1572 1541 # get histogram of data, all points into a bin in a way of summing 1573 image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1542 image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1574 1543 y=self.qx_data, 1575 1576 1544 bins=[self.y_bins, self.x_bins], 1545 weights=self.data) 1577 1546 # Now, normalize the image by weights only for weights>1: 1578 1547 # If weight == 1, there is only one data point in the bin so 1579 1548 # that no normalization is required. 1580 image[weights >1] = image[weights>1]/weights[weights>1]1549 image[weights > 1] = image[weights>1]/weights[weights>1] 1581 1550 # Set image bins w/o a data point (weight==0) as None (was set to zero 1582 1551 # by histogram2d.) 1583 image[weights ==0] = None1552 image[weights == 0] = None 1584 1553 1585 1554 # Fill empty bins with 8 nearest neighbors only when at least … … 1587 1556 loop = 0 1588 1557 1589 # do while loop until all vacant bins are filled up up 1558 # do while loop until all vacant bins are filled up up 1590 1559 #to loop = max_loop 1591 1560 while(not(numpy.isfinite(image[weights == 0])).all()): 1592 if loop >= max_loop: # this protects never-ending loop1561 if loop >= max_loop: # this protects never-ending loop 1593 1562 break 1594 1563 image = self._fillup_pixels(image=image, weights=weights) … … 1597 1566 return image 1598 1567 1599 def _get_bins(self): 1568 def _get_bins(self): 1600 1569 """ 1601 1570 get bins 1602 set x_bins and y_bins into self, 1d arrays of the index with 1571 set x_bins and y_bins into self, 1d arrays of the index with 1603 1572 ~ square binning 1604 Requirement: need 1d array formats of 1573 Requirement: need 1d array formats of 1605 1574 self.qx_data, and self.qy_data 1606 1575 where each one corresponds to x, or y axis values 1607 1608 1576 """ 1609 1577 # No qx or qy given in a vector format … … 1624 1592 y_size = ymax - ymin 1625 1593 1626 # estimate the # of pixels on each axes 1594 # estimate the # of pixels on each axes 1627 1595 npix_y = int(math.floor(math.sqrt(len(self.qy_data)))) 1628 1596 npix_x = int(math.floor(len(self.qy_data) / npix_y)) 1629 1597 1630 # bin size: x- & y-directions 1598 # bin size: x- & y-directions 1631 1599 xstep = x_size / (npix_x - 1) 1632 1600 ystep = y_size / (npix_y - 1) … … 1640 1608 # store x and y bin centers in q space 1641 1609 x_bins = numpy.arange(xmin, xmax + xstep / 10, xstep) 1642 y_bins = numpy.arange(ymin, ymax + ystep / 10, ystep) 1610 y_bins = numpy.arange(ymin, ymax + ystep / 10, ystep) 1643 1611 1644 1612 #set x_bins and y_bins 1645 self.x_bins = x_bins 1646 self.y_bins = y_bins 1647 1648 def _fillup_pixels(self, image=None, weights=None): 1649 """ 1650 Fill z values of the empty cells of 2d image matrix 1613 self.x_bins = x_bins 1614 self.y_bins = y_bins 1615 1616 def _fillup_pixels(self, image=None, weights=None): 1617 """ 1618 Fill z values of the empty cells of 2d image matrix 1651 1619 with the average over up-to next nearest neighbor points 1652 1620 … … 1691 1659 # go 4 next nearest neighbors when no non-zero 1692 1660 # neighbor exists 1693 #if weight[n_y][n_x] == 0:1694 1661 if n_y != 0 and n_x != 0 and\ 1695 1662 numpy.isfinite(image[n_y-1][n_x-1]): … … 1721 1688 self.subplot.set_xscale('linear') 1722 1689 1723 hlist = self.subplot.plot(x, y, color=c, marker='',1724 1690 self.subplot.plot(x, y, color=c, marker='', 1691 linestyle='-', label=label) 1725 1692 self.subplot.set_yscale(self.yscale) 1726 1693 self.subplot.set_xscale(self.xscale) … … 1728 1695 def _color(self, c): 1729 1696 """Return a particular colour""" 1730 return self.colorlist[c %len(self.colorlist)]1697 return self.colorlist[c % len(self.colorlist)] 1731 1698 1732 1699 def _symbol(self, s): 1733 1700 """Return a particular symbol""" 1734 return self.symbollist[s %len(self.symbollist)]1701 return self.symbollist[s % len(self.symbollist)] 1735 1702 1736 1703 def _replot(self, remove_fit=False): … … 1753 1720 Receive the x and y transformation from myDialog, 1754 1721 Transforms x and y in View 1755 and set the scale 1756 """ 1722 and set the scale 1723 """ 1757 1724 # The logic should be in the right order 1758 1725 # Delete first, and then get the whole list... … … 1763 1730 list = self.graph.returnPlottable() 1764 1731 # Changing the scale might be incompatible with 1765 # currently displayed data (for instance, going 1732 # currently displayed data (for instance, going 1766 1733 # from ln to log when all plotted values have 1767 # negative natural logs). 1734 # negative natural logs). 1768 1735 # Go linear and only change the scale at the end. 1769 1736 self.set_xscale("linear") … … 1789 1756 self.xaxis_label = xname 1790 1757 self.xaxis_unit = xunits 1791 # Goes through all possible scales 1758 # Goes through all possible scales 1792 1759 if(self.xLabel == "x"): 1793 1760 item.transformX(transform.toX, transform.errToX) … … 1795 1762 if(self.xLabel == "x^(2)"): 1796 1763 item.transformX(transform.toX2, transform.errToX2) 1797 xunits = convertUnit(2, xunits)1764 xunits = convertUnit(2, xunits) 1798 1765 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1799 1766 if(self.xLabel == "x^(4)"): 1800 1767 item.transformX(transform.toX4, transform.errToX4) 1801 xunits = convertUnit(4, xunits)1768 xunits = convertUnit(4, xunits) 1802 1769 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1803 1770 if(self.xLabel == "ln(x)"): 1804 item.transformX(transform.toLogX, transform.errToLogX)1805 self.graph._xaxis_transformed("\ln\\ %s" % xname, "%s" % xunits) 1771 item.transformX(transform.toLogX, transform.errToLogX) 1772 self.graph._xaxis_transformed("\ln\\ %s" % xname, "%s" % xunits) 1806 1773 if(self.xLabel == "log10(x)"): 1807 1774 item.transformX(transform.toX_pos, transform.errToX_pos) … … 1810 1777 if(self.xLabel == "log10(x^(4))"): 1811 1778 item.transformX(transform.toX4, transform.errToX4) 1812 xunits = convertUnit(4, xunits)1779 xunits = convertUnit(4, xunits) 1813 1780 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1814 1781 _xscale = 'log' … … 1819 1786 item.transformY(transform.toX, transform.errToX) 1820 1787 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits) 1821 if(self.yLabel == "log10(y)"): 1788 if(self.yLabel == "log10(y)"): 1822 1789 item.transformY(transform.toX_pos, transform.errToX_pos) 1823 _yscale = 'log' 1790 _yscale = 'log' 1824 1791 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits) 1825 1792 if(self.yLabel == "y^(2)"): 1826 item.transformY(transform.toX2, transform.errToX2) 1827 yunits = convertUnit(2, yunits) 1793 item.transformY(transform.toX2, transform.errToX2) 1794 yunits = convertUnit(2, yunits) 1828 1795 self.graph._yaxis_transformed("%s^{2}" % yname, "%s" % yunits) 1829 1796 if(self.yLabel == "1/y"): … … 1833 1800 if(self.yLabel == "y*x^(4)"): 1834 1801 item.transformY(transform.toYX4, transform.errToYX4) 1835 xunits = convertUnit(4, self.xaxis_unit) 1836 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),1837 "%s%s" % (yunits, xunits))1802 xunits = convertUnit(4, self.xaxis_unit) 1803 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1804 "%s%s" % (yunits, xunits)) 1838 1805 if(self.yLabel == "1/sqrt(y)"): 1839 1806 item.transformY(transform.toOneOverSqrtX, 1840 transform.errOneOverSqrtX 1807 transform.errOneOverSqrtX) 1841 1808 yunits = convertUnit(-0.5, yunits) 1842 self.graph._yaxis_transformed("1/\sqrt{%s}" %yname, "%s" % yunits) 1809 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 1810 "%s" % yunits) 1843 1811 if(self.yLabel == "ln(y*x)"): 1844 1812 item.transformY(transform.toLogXY, transform.errToLogXY) 1845 self.graph._yaxis_transformed("\ln (%s \ \ %s)" % (yname, xname),1846 1813 self.graph._yaxis_transformed("\ln (%s \ \ %s)" % (yname, xname), 1814 "%s%s" % (yunits, self.xaxis_unit)) 1847 1815 if(self.yLabel == "ln(y*x^(2))"): 1848 1816 item.transformY( transform.toLogYX2, transform.errToLogYX2) 1849 xunits = convertUnit(2, self.xaxis_unit) 1850 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname),1851 "%s%s" % (yunits, xunits))1817 xunits = convertUnit(2, self.xaxis_unit) 1818 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 1819 "%s%s" % (yunits, xunits)) 1852 1820 if(self.yLabel == "ln(y*x^(4))"): 1853 1821 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1854 xunits = convertUnit(4, self.xaxis_unit) 1855 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname),1856 "%s%s" % (yunits, xunits))1822 xunits = convertUnit(4, self.xaxis_unit) 1823 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 1824 "%s%s" % (yunits, xunits)) 1857 1825 if(self.yLabel == "log10(y*x^(4))"): 1858 1826 item.transformY(transform.toYX4, transform.errToYX4) 1859 xunits = convertUnit(4, self.xaxis_unit) 1860 _yscale = 'log' 1861 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),1862 "%s%s" % (yunits, xunits))1827 xunits = convertUnit(4, self.xaxis_unit) 1828 _yscale = 'log' 1829 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1830 "%s%s" % (yunits, xunits)) 1863 1831 if(self.viewModel == "Guinier lny vs x^(2)"): 1864 1832 item.transformX(transform.toX2, transform.errToX2) 1865 xunits = convertUnit(2, xunits) 1866 self.graph._xaxis_transformed("%s^{2}" % xname, 1867 item.transformY(transform.toLogX,transform.errToLogX 1868 self.graph._yaxis_transformed("\ln\ \ %s" % yname, 1833 xunits = convertUnit(2, xunits) 1834 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1835 item.transformY(transform.toLogX,transform.errToLogX) 1836 self.graph._yaxis_transformed("\ln\ \ %s" % yname, "%s" % yunits) 1869 1837 if(self.viewModel == "Porod y*x^(4) vs x^(4)"): 1870 1838 item.transformX(transform.toX4, transform.errToX4) 1871 xunits = convertUnit(4, self.xaxis_unit) 1839 xunits = convertUnit(4, self.xaxis_unit) 1872 1840 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1873 1841 item.transformY(transform.toYX4, transform.errToYX4) 1874 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname),1875 "%s%s" % (yunits, xunits))1842 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1843 "%s%s" % (yunits, xunits)) 1876 1844 item.transformView() 1877 1845 … … 1881 1849 xname = self.graph.prop["xlabel"] 1882 1850 xunits = '' 1883 #self.yaxis_label = yname1884 #self.yaxis_unit = yunits1885 #self.xaxis_label = xname1886 #self.xaxis_unit = xunits1887 1851 1888 self.resetFitView() 1889 self.prevXtrans = self.xLabel 1890 self.prevYtrans = self.yLabel 1852 self.resetFitView() 1853 self.prevXtrans = self.xLabel 1854 self.prevYtrans = self.yLabel 1891 1855 self.graph.render(self) 1892 1856 self.set_xscale(_xscale) 1893 1857 self.set_yscale(_yscale) 1894 1858 1895 self.xaxis(xname, xunits, self.xaxis_font, 1859 self.xaxis(xname, xunits, self.xaxis_font, 1896 1860 self.xaxis_color, self.xaxis_tick) 1897 self.yaxis(yname, yunits, self.yaxis_font, 1861 self.yaxis(yname, yunits, self.yaxis_font, 1898 1862 self.yaxis_color, self.yaxis_tick) 1899 1863 self.subplot.texts = self.textList 1900 1864 self.subplot.figure.canvas.draw_idle() 1901 1865 1902 def onFitDisplay(self, tempx, tempy, xminView, 1866 def onFitDisplay(self, tempx, tempy, xminView, 1903 1867 xmaxView, xmin, xmax, func): 1904 1868 """ … … 1928 1892 item.onFitRange(None, None) 1929 1893 # Create new data plottable with result 1930 self.fit_result.x = [] 1894 self.fit_result.x = [] 1931 1895 self.fit_result.y = [] 1932 self.fit_result.x = tempx 1933 self.fit_result.y = tempy 1896 self.fit_result.x = tempx 1897 self.fit_result.y = tempy 1934 1898 self.fit_result.dx = None 1935 1899 self.fit_result.dy = None 1936 1900 #Load the view with the new values 1937 1901 self.fit_result.reset_view() 1938 # Add the new plottable to the graph 1939 self.graph.add(self.fit_result) 1902 # Add the new plottable to the graph 1903 self.graph.add(self.fit_result) 1940 1904 self.graph.render(self) 1941 1905 self._offset_graph() … … 1952 1916 dial = LabelDialog(None, -1, 'Modify Window Title', old_caption) 1953 1917 if dial.ShowModal() == wx.ID_OK: 1954 new_caption = dial.getText() 1918 new_caption = dial.getText() 1955 1919 1956 1920 # send to guiframe to change the panel caption 1957 caption = self.parent.on_change_caption(self.window_name, 1958 old_caption, new_caption) 1921 caption = self.parent.on_change_caption(self.window_name, 1922 old_caption, new_caption) 1959 1923 1960 1924 # also set new caption in plot_panels list … … 1967 1931 def onResetGraph(self, event): 1968 1932 """ 1969 Reset the graph by plotting the full range of data 1933 Reset the graph by plotting the full range of data 1970 1934 """ 1971 1935 list = [] … … 2012 1976 print "Error in copy Image" 2013 1977 2014 2015 2016 #--------------------------------------------------------------- 1978 1979 #--------------------------------------------------------------- 2017 1980 class NoRepaintCanvas(FigureCanvasWxAgg): 2018 1981 """ … … 2036 1999 self.realize() 2037 2000 if self._drawn < 2: 2038 self.draw(repaint =False)2001 self.draw(repaint=False) 2039 2002 self._drawn += 1 2040 2003 self.gui_repaint(drawDC=wx.PaintDC(self)) 2041 2042 -
plottools/src/danse/common/plottools/PropertyDialog.py
rb4da6df r10bfeb3 1 #!/usr/bin/python2 3 # myDialog.py4 1 """ 5 2 """ … … 15 12 """ 16 13 self.parent = parent 17 vbox 14 vbox = wx.BoxSizer(wx.VERTICAL) 18 15 sizer = wx.GridBagSizer(5,5) 19 16 … … 42 39 x_size += self.view.GetSize()[0] 43 40 self.view.SetMinSize((160, 30)) 44 sizer.Add(self.view, (iy,ix), (1,1), 41 sizer.Add(self.view, (iy,ix), (1,1), 45 42 wx.EXPAND|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 46 43 self.SetMinSize((x_size, 50)) … … 52 49 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 53 50 sizer_button.Add(btOk, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 54 sizer_button.Add(btCancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 55 vbox.Add(sizer_button, 0, 51 sizer_button.Add(btCancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 52 vbox.Add(sizer_button, 0, 56 53 wx.EXPAND|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 10) 57 54 # scale value for x … … 77 74 self.yvalue.Insert("ln(y*x^(4))", 9) 78 75 self.yvalue.Insert("log10(y*x^(4))", 10) 79 # type of view or model used 76 # type of view or model used 80 77 self.view.SetValue("--") 81 78 self.view.Insert("--", 0) … … 83 80 self.view.Insert("Porod y*x^(4) vs x^(4)", 2) 84 81 self.SetSizer(vbox) 85 self.Fit() 82 self.Fit() 86 83 self.Centre() 87 84 … … 97 94 return self.xvalue.GetValue(), self.yvalue.GetValue(),\ 98 95 self.view.GetValue() 99 100 101 if __name__ == "__main__":102 app = wx.App()103 dialog = Properties(None, -1, 'Properties')104 dialog.ShowModal()105 app.MainLoop()106 107 -
plottools/src/danse/common/plottools/SizeDialog.py
r82a54b8 r10bfeb3 1 1 import wx 2 2 3 3 4 class SizeDialog(wx.Dialog): … … 5 6 wx.Dialog.__init__(self, parent, id, title, size=(300, 175)) 6 7 7 #panel = wx.Panel(self, -1)8 9 8 mainbox = wx.BoxSizer(wx.VERTICAL) 10 9 vbox = wx.BoxSizer(wx.VERTICAL) … … 12 11 hbox = wx.BoxSizer(wx.HORIZONTAL) 13 12 text1 = "Enter in a custom size (float values > 0 accepted)" 14 msg = wx.StaticText(self, -1, text1, (30,15), style=wx.ALIGN_CENTRE)13 msg = wx.StaticText(self, -1, text1, (30,15), style=wx.ALIGN_CENTRE) 15 14 msg.SetLabel(text1) 16 15 self.myTxtCtrl = wx.TextCtrl(self, -1, '', (100, 50)) 17 16 18 textbox.Add(self.myTxtCtrl, flag=wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 17 textbox.Add(self.myTxtCtrl, flag=wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 19 18 border=10, proportion=2) 20 19 vbox.Add(msg, flag=wx.ALL, border=10, proportion=1) … … 23 22 self.myTxtCtrl.SetValue(str(10)) 24 23 25 okButton = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25))26 closeButton = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25))24 okButton = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 25 closeButton = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 27 26 28 27 hbox.Add(okButton) 29 hbox.Add((20, 20))28 hbox.Add((20, 20)) 30 29 hbox.Add(closeButton) 31 30 32 31 mainbox.Add(vbox, flag=wx.ALL, border=10) 33 32 mainbox.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5) 34 mainbox.Add(hbox, flag=wx.CENTER, 33 mainbox.Add(hbox, flag=wx.CENTER, 35 34 border=10) 36 35 self.SetSizer(mainbox) … … 41 40 """ 42 41 return self.myTxtCtrl.GetValue() 43 -
plottools/src/danse/common/plottools/TextDialog.py
rf80236f r10bfeb3 10 10 FAMILY = ['serif', 'sans-serif', 'fantasy', 'monospace'] 11 11 SIZE = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] 12 STYLE 12 STYLE = ['normal', 'italic'] 13 13 WEIGHT = ['light', 'normal', 'bold'] 14 14 COLOR = ['black', 'blue', 'green', 'red', 'cyan', 'magenta', 'yellow'] 15 15 16 16 17 class TextDialog(wx.Dialog): … … 36 37 _BOX_WIDTH = 60 37 38 font_size = 12 38 font_description= wx.StaticBox(self, -1, 'Font', 39 font_description= wx.StaticBox(self, -1, 'Font', 39 40 size=(PNL_WIDTH-20, 70)) 40 41 font_box = wx.StaticBoxSizer(font_description, wx.VERTICAL) … … 73 74 else: 74 75 enter_text += ":" 75 self.textString 76 self.textString = wx.TextCtrl(self, -1, size=(PNL_WIDTH-30, height ),\ 76 77 style=styles) 77 78 self.textString.SetValue(str(label)) 78 79 self.textString.SetToolTipString("The text that will be displayed.") 79 80 #font family 80 self.fontFamily = 81 self.fontFamily = wx.ComboBox(self, -1, style=wx.CB_READONLY) 81 82 wx.EVT_COMBOBOX(self.fontFamily, -1, self.on_family) 82 83 self.fontFamily.SetMinSize((_BOX_WIDTH, -1)) … … 85 86 self.fontFamily.SetToolTipString("Font family of the text.") 86 87 #font weight 87 self.fontWeight = 88 self.fontWeight = wx.ComboBox(self, -1, style=wx.CB_READONLY) 88 89 wx.EVT_COMBOBOX(self.fontWeight, -1, self.on_weight) 89 90 self.fontWeight.SetMinSize((_BOX_WIDTH, -1)) … … 92 93 self.fontWeight.SetToolTipString("Font weight of the text.") 93 94 #font family 94 self.fontSize = 95 self.fontSize = wx.ComboBox(self, -1, style=wx.CB_READONLY) 95 96 wx.EVT_COMBOBOX(self.fontSize, -1, self.on_size) 96 97 self.fontSize.SetMinSize((_BOX_WIDTH, -1)) … … 99 100 self.fontSize.SetToolTipString("Font size of the text.") 100 101 #font style 101 self.fontStyle = 102 self.fontStyle = wx.ComboBox(self, -1, style=wx.CB_READONLY) 102 103 wx.EVT_COMBOBOX(self.fontStyle, -1, self.on_style) 103 104 self.fontStyle.SetMinSize((_BOX_WIDTH, -1)) … … 106 107 self.fontStyle.SetToolTipString("Font style of the text.") 107 108 #font color 108 self.fontColor = 109 self.fontColor = wx.ComboBox(self, -1, style=wx.CB_READONLY) 109 110 wx.EVT_COMBOBOX(self.fontColor, -1, self.on_color) 110 111 self.fontColor.SetMinSize((_BOX_WIDTH, -1)) … … 115 116 self.static_line_1 = wx.StaticLine(self, -1) 116 117 self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25)) 117 self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', 118 self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', 118 119 size=(_BOX_WIDTH, 25)) 119 120 120 121 # Intro 121 explanation 122 explanation = "Select font properties :" 122 123 vbox.Add(sizer) 123 124 ix = 0 … … 131 132 family_box.Add(self.fontSize, -1, 0) 132 133 if unit_box != None: 133 family_box.Add((_BOX_WIDTH/2, -1))134 family_box.Add((_BOX_WIDTH/2, -1)) 134 135 family_box.Add(tick_label_text, -1, 0) 135 136 family_box.Add(self.tick_label_check, -1, 0) … … 152 153 sizer.Add(wx.StaticText(self, -1, enter_text), (iy, ix), 153 154 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 154 text_box.Add((15, 10))155 text_box.Add((15, 10)) 155 156 text_box.Add(self.textString) 156 157 vbox.Add(text_box, 0, wx.EXPAND, 15) … … 161 162 vbox.Add(unit_box, 0,wx.LEFT, 15) 162 163 163 vbox.Add((10, 10))164 vbox.Add((10, 10)) 164 165 vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 165 166 sizer_button = wx.BoxSizer(wx.HORIZONTAL) … … 168 169 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 169 170 sizer_button.Add(self.closeButton, 0, 170 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 171 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 171 172 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 172 173 self.SetSizer(vbox) … … 180 181 list = FAMILY 181 182 for idx in range(len(list)): 182 self.fontFamily.Append(list[idx], idx)183 self.fontFamily.Append(list[idx], idx) 183 184 184 185 def _set_size_list(self): … … 198 199 list = WEIGHT 199 200 for idx in range(len(list)): 200 self.fontWeight.Append(list[idx], idx)201 self.fontWeight.Append(list[idx], idx) 201 202 202 203 def _set_style_list(self): … … 207 208 list = STYLE 208 209 for idx in range(len(list)): 209 self.fontStyle.Append(list[idx], idx)210 self.fontStyle.Append(list[idx], idx) 210 211 211 212 def _set_color_list(self): … … 216 217 list = COLOR 217 218 for idx in range(len(list)): 218 self.fontColor.Append(list[idx], idx)219 self.fontColor.Append(list[idx], idx) 219 220 220 221 def on_tick_label(self, event): … … 230 231 """ 231 232 event.Skip() 232 self.family = self.fontFamily.GetValue() 233 self.family = self.fontFamily.GetValue() 233 234 234 235 def on_style(self, event): … … 251 252 """ 252 253 event.Skip() 253 self.size = self.fontSize.GetValue() 254 self.size = self.fontSize.GetValue() 254 255 255 256 def on_color(self, event): … … 258 259 """ 259 260 event.Skip() 260 self.color = self.fontColor.GetValue() 261 self.color = self.fontColor.GetValue() 261 262 262 263 def getText(self): … … 294 295 Returns font tyle for the text box 295 296 """ 296 return str(self.style) 297 return str(self.style) 297 298 298 299 def getWeight(self): -
plottools/src/danse/common/plottools/binder.py
r0e553fd r10bfeb3 2 2 Extension to MPL to support the binding of artists to key/mouse events. 3 3 """ 4 import sys 5 4 6 5 7 class Selection: … … 12 14 artist = None 13 15 prop = {} 16 14 17 def __init__(self, artist=None, prop={}): 15 18 self.artist, self.prop = artist, self.prop … … 23 26 def __nonzero__(self): 24 27 return self.artist is not None 28 25 29 26 30 class BindArtist: … … 66 70 ] 67 71 68 69 # Turn off picker if it hasn't already been done70 #try:71 # canvas.mpl_disconnect(canvas.button_pick_id)72 # canvas.mpl_disconnect(canvas.scroll_pick_id)73 #except:74 # pass75 72 self._current = None 76 73 self._actions = {} … … 121 118 In case we need to disconnect from the canvas... 122 119 """ 123 try: 120 try: 124 121 for cid in self._connections: self.canvas.mpl_disconnect(cid) 125 except: 122 except: 123 print "Error disconnection canvas: %s" % sys.exc_value 126 124 pass 127 125 self._connections = [] … … 165 163 shift,control,alt,meta are flags which are true if the 166 164 corresponding key is pressed at the time of the event. 167 details is a dictionary of artist specific details, such as the 165 details is a dictionary of artist specific details, such as the 168 166 id(s) of the point that were clicked. 169 167 … … 182 180 TODO: Attach multiple callbacks to the same event? 183 181 TODO: Clean up interaction with toolbar modes 184 TODO: push/pushclear/pop context so that binding changes for 182 TODO: push/pushclear/pop context so that binding changes for 185 183 the duration 186 184 TODO: e.g., to support ? context sensitive help … … 193 191 # Register the trigger callback 194 192 self._actions[trigger][artist] = action 195 #print "==> added",artist,[artist],"to",trigger,":",196 #self._actions[trigger].keys()197 193 198 194 # Maintain a list of all artists 199 if artist not in self._artists: 195 if artist not in self._artists: 200 196 self._artists.append(artist) 201 197 … … 239 235 # TODO: sort by zorder of axes then by zorder within axes 240 236 self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 241 # print "search"," ".join([str(h) for h in self._artists])242 237 found = Selection() 243 #print "searching in",self._artists244 238 for artist in self._artists: 245 239 # TODO: should contains() return false if invisible? 246 if not artist.get_visible(): 240 if not artist.get_visible(): 247 241 continue 248 242 # TODO: optimization - exclude artists not inaxes … … 255 249 found.artist, found.prop = artist, prop 256 250 break 257 #print "found",found.artist258 251 259 252 # TODO: how to check if prop is equal? … … 296 289 x, y = transform.inverse_xy_tup((x, y)) 297 290 298 299 291 event.xdata, event.ydata = x, y 300 292 self.trigger(self._hasclick, 'drag', event) 301 293 else: 302 294 found = self._find_current(event) 303 #print "found",found.artist304 295 self.trigger(found, 'motion', event) 305 296 … … 312 303 # Check for double-click 313 304 event_time = time.time() 314 #print event_time,self._last_time,self.dclick_threshhold315 #print (event_time > self._last_time + self.dclick_threshhold)316 #print event.button,self._last_button317 305 if (event.button != self._last_button) or \ 318 306 (event_time > self._last_time + self.dclick_threshhold): … … 376 364 # TODO: Can we tab between items? 377 365 # TODO: How do unhandled events get propogated to axes, figure and 378 # TODO: finally to application? Do we need to implement a full tags 366 # TODO: finally to application? Do we need to implement a full tags 379 367 # TODO: architecture a la Tk? 380 368 # TODO: Do modifiers cause a grab? Does the artist see the modifiers? … … 408 396 found = self._find_current(event) 409 397 self.trigger(found, 'scroll', event) 410 -
plottools/src/danse/common/plottools/canvas.py
r4a4164c r10bfeb3 1 1 """ 2 This module implements a faster canvas for plotting. 2 This module implements a faster canvas for plotting. 3 3 it ovewrites some matplolib methods to allow printing on sys.platform=='win32' 4 4 """ … … 27 27 """ 28 28 pass 29 #print "overriding select" 30 def select(self): 31 """ 32 """ 33 #print "in new select"29 30 31 def select(self): 32 """ 33 """ 34 34 pass 35 35 36 36 37 def unselect(self): 37 38 """ … … 39 40 pass 40 41 42 41 43 def OnPrintPage(self, page): 42 44 """ 43 override printPage of matplotlib 45 override printPage of matplotlib 44 46 """ 45 47 self.canvas.draw() 46 dc 48 dc = self.GetDC() 47 49 try: 48 50 (ppw, pph) = self.GetPPIPrinter() # printer's pixels per in … … 61 63 62 64 # draw the bitmap, scaled appropriately 63 vscale = float(ppw) / fig_dpi65 vscale = float(ppw) / fig_dpi 64 66 65 67 # set figure resolution,bg color for printer … … 67 69 self.canvas.figure.set_facecolor('#FFFFFF') 68 70 69 renderer 71 renderer = RendererWx(self.canvas.bitmap, self.canvas.figure.dpi) 70 72 self.canvas.figure.draw(renderer) 71 self.canvas.bitmap.SetWidth( 72 self.canvas.bitmap.SetHeight( int(self.canvas.bitmap.GetHeight()* vscale))73 self.canvas.bitmap.SetWidth(int(self.canvas.bitmap.GetWidth() * vscale)) 74 self.canvas.bitmap.SetHeight(int(self.canvas.bitmap.GetHeight() * vscale)) 73 75 self.canvas.draw() 74 76 75 77 # page may need additional scaling on preview 76 78 page_scale = 1.0 77 if self.IsPreview(): page_scale = float(dcw)/pgw 79 if self.IsPreview(): 80 page_scale = float(dcw)/pgw 78 81 79 82 # get margin in pixels = (margin in in) * (pixels/in) 80 top_margin 83 top_margin = int(self.margin * pph * page_scale) 81 84 left_margin = int(self.margin * ppw * page_scale) 82 85 83 86 # set scale so that width of output is self.width inches 84 87 # (assuming grw is size of graph in inches....) 85 user_scale = (self.width * fig_dpi * page_scale) /float(grw)88 user_scale = (self.width * fig_dpi * page_scale) / float(grw) 86 89 dc.SetDeviceOrigin(left_margin, top_margin) 87 90 dc.SetUserScale(user_scale, user_scale) … … 108 111 RendererBase.draw_image = draw_image 109 112 113 110 114 class FigureCanvas(FigureCanvasWxAgg): 111 115 """ 112 116 Add features to the wx agg canvas for better support of AUI and 113 117 faster plotting. 114 115 118 """ 116 119 … … 136 139 def set_panel(self, panel): 137 140 """ 138 Set axes 141 Set axes 139 142 """ 140 143 # set panel … … 158 161 if False and wx.GetApp().Pending(): 159 162 self.idletimer.Restart(5, *args, **kwargs) 160 else: 163 else: 161 164 # Draw plot, changes resizing too 162 165 self.draw(*args, **kwargs) 163 self.resizing = False 166 self.resizing = False 164 167 165 def _get_axes_switch(self): 168 def _get_axes_switch(self): 166 169 """ 167 170 """ … … 182 185 self.set_resizing(False) 183 186 184 def set_resizing(self, resizing=False): 185 """ 186 Setting the resizing 187 """ 187 def set_resizing(self, resizing=False): 188 """ 189 Setting the resizing 190 """ 188 191 self.resizing = resizing 189 192 self.panel.set_resizing(False) … … 222 225 223 226 # Convert delta/rotation/rate into a floating point step size 224 delta = evt.GetWheelDelta() 227 delta = evt.GetWheelDelta() 225 228 rotation = evt.GetWheelRotation() 226 229 rate = evt.GetLinesPerAction() … … 237 240 scroll wheel event. x,y are the canvas coords: 0,0 is lower, 238 241 left. button and key are as defined in MouseEvent 239 240 242 """ 241 243 button = 'up' if step >= 0 else 'down' … … 262 264 # This solves the focusing on rightclick. 263 265 # Todo: better design 264 self.panel.parent.set_plot_unfocus() 266 self.panel.parent.set_plot_unfocus() 265 267 self.panel.on_set_focus(None) 266 268 -
plottools/src/danse/common/plottools/config.py
rcd8d4a7 r10bfeb3 52 52 # if a backend has already been selected, make sure it is the correct one. 53 53 raise ImportError("Matplotlib not using backend " + plot_backend) 54 -
plottools/src/danse/common/plottools/fitDialog.py
r82a54b8 r10bfeb3 1 #!/usr/bin/python2 3 # fitDialog.py4 5 1 import wx 6 #from PlotPanel import PlotPanel7 2 from plottables import Theory1D 8 import math, numpy, fittings 3 import math 4 import numpy 5 import fittings 9 6 import transform 10 7 import sys … … 18 15 PNL_WIDTH = 450 19 16 17 20 18 def format_number(value, high=False): 21 19 """ 22 Return a float in a standardized, human-readable formatted string 20 Return a float in a standardized, human-readable formatted string 23 21 """ 24 try: 22 try: 25 23 value = float(value) 26 24 except: … … 36 34 37 35 38 39 36 class LinearFit(wx.Dialog): 40 def __init__(self, parent, plottable, push_data, transform, title):37 def __init__(self, parent, plottable, push_data, transform, title): 41 38 """ 42 39 Dialog window pops- up when select Linear fit on Context menu … … 107 104 108 105 # Intro 109 explanation 106 explanation = "Perform fit for y(x) = Ax + B" 110 107 vbox.Add(sizer) 111 108 ix = 0 … … 122 119 (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 123 120 ix += 1 124 sizer.Add(self.tcErrA, (iy, ix), (1, 1), 121 sizer.Add(self.tcErrA, (iy, ix), (1, 1), 125 122 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 126 123 iy += 1 … … 167 164 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 168 165 ix += 1 169 sizer.Add(self.xminFit, (iy, ix), (1,1),166 sizer.Add(self.xminFit, (iy, ix), (1, 1), 170 167 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 171 168 ix += 2 … … 179 176 sizer_button.Add(self.btFit, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 180 177 sizer_button.Add(self.btClose, 0, 181 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 178 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 182 179 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 183 180 … … 190 187 self.model = LineModel() 191 188 #Display the fittings values 192 self.default_A = self.model.getParam('A') 193 self.default_B = self.model.getParam('B') 189 self.default_A = self.model.getParam('A') 190 self.default_B = self.model.getParam('B') 194 191 self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 195 192 self.cstB = fittings.Parameter(self.model, 'B', self.default_B) … … 198 195 if self.Avalue == None: 199 196 self.tcA.SetValue(format_number(self.default_A)) 200 else 197 else: 201 198 self.tcA.SetLabel(format_number(self.Avalue)) 202 199 if self.Bvalue == None: … … 231 228 self.initXmin.SetValue(format_number(min(self.plottable.x))) 232 229 self.initXmax.SetValue(format_number(max(self.plottable.x))) 233 #self.xminFit.SetLabel(format_number(self.mini))234 #self.xmaxFit.SetLabel(format_number(self.maxi))235 230 self.mini = min(self.x) 236 231 self.maxi = max(self.x) … … 251 246 def _on_close(self, event): 252 247 """ 253 Close event. 248 Close event. 254 249 Notify registered owner if available. 255 250 """ … … 263 258 the button Fit.Computes chisqr , 264 259 A and B parameters of the best linear fit y=Ax +B 265 Push a plottable to 260 Push a plottable to 266 261 """ 267 262 tempx = [] … … 271 266 # Check if View contains a x array .we online fit when x exits 272 267 # makes transformation for y as a line to fit 273 if self.x != []: 268 if self.x != []: 274 269 if(self.checkFitValues(self.xminFit) == True): 275 270 #Check if the field of Fit Dialog contain values … … 278 273 #self.xmaxFit.GetValue()) 279 274 if not self._checkVal(self.xminFit, self.xmaxFit): 280 return 275 return 281 276 xminView = float(self.xminFit.GetValue()) 282 277 xmaxView = float(self.xmaxFit.GetValue()) … … 291 286 for i in range(len(self.x)): 292 287 if self.x[i] >= math.log10(xmin): 293 tempy.append(math.log10(self.y[i])) 288 tempy.append(math.log10(self.y[i])) 294 289 tempdy.append(transform.errToLogX(self.y[i], 295 290 0, self.dy[i], 0)) 296 291 else: 297 292 for i in range(len(self.y)): 298 tempy.append(math.log10(self.y[i])) 293 tempy.append(math.log10(self.y[i])) 299 294 tempdy.append(transform.errToLogX(self.y[i], 300 295 0, self.dy[i], 0)) … … 306 301 for x_i in self.x: 307 302 if x_i >= math.log10(xmin): 308 tempx.append(math.log10(x_i)) 303 tempx.append(math.log10(x_i)) 309 304 else: 310 305 tempx = self.x 311 306 312 307 #Find the fitting parameters 313 # Always use the same defaults, so that fit history 314 #doesn't play a role! 308 # Always use the same defaults, so that fit history 309 #doesn't play a role! 315 310 self.cstA = fittings.Parameter(self.model, 'A', self.default_A) 316 311 self.cstB = fittings.Parameter(self.model, 'B', self.default_B) … … 328 323 tempdy = numpy.asarray(tempdy) 329 324 tempdy[tempdy == 0] = 1 330 chisqr, out, cov = fittings.sansfit(self.model, 325 chisqr, out, cov = fittings.sansfit(self.model, 331 326 [self.cstA, self.cstB], 332 327 tempx, tempy, tempdy, … … 349 344 cstA = out[0] 350 345 cstB = out[1] 351 # Reset model with the right values of A and B 346 # Reset model with the right values of A and B 352 347 self.model.setParam('A', float(cstA)) 353 348 self.model.setParam('B', float(cstB)) … … 380 375 if self.yLabel == "log10(y)": 381 376 tempy.append(math.pow(10, y_model)) 382 else: 377 else: 383 378 tempy.append(y_model) 384 379 #Set the fit parameter display when FitDialog is opened again … … 396 391 def _onsetValues(self, cstA, cstB, errA, errB, Chi): 397 392 """ 398 Display the value on fit Dialog 399 393 Display the value on fit Dialog 400 394 """ 401 395 self.tcA.SetValue(format_number(cstA)) … … 407 401 def _ongetValues(self): 408 402 """ 409 Display the value on fit Dialog 403 Display the value on fit Dialog 410 404 """ 411 405 return self.Avalue, self.Bvalue, self.ErrAvalue, \ … … 414 408 def _checkVal(self, usermin, usermax): 415 409 """ 416 Ensure that fields parameter contains a min and a max value 410 Ensure that fields parameter contains a min and a max value 417 411 within x min and x max range 418 412 """ … … 420 414 self.maxi = float(self.xmaxFit.GetValue()) 421 415 flag = True 422 try: 416 try: 423 417 mini = float(usermin.GetValue()) 424 418 maxi = float(usermax.GetValue()) … … 446 440 if(self.xLabel == "x"): 447 441 return transform.toX(x) 448 if(self.xLabel == "x^(2)"): 442 if(self.xLabel == "x^(2)"): 449 443 return transform.toX2(x) 450 444 if(self.xLabel == "ln(x)"): … … 463 457 if(self.xLabel == "x"): 464 458 return transform.toX(x) 465 if(self.xLabel == "x^(2)"): 459 if(self.xLabel == "x^(2)"): 466 460 return transform.toX2(x) 467 461 if(self.xLabel == "ln(x)"): … … 471 465 return x 472 466 else: 473 raise ValueError, "cannot compute log of a negative number"467 raise ValueError, "cannot compute log of a negative number" 474 468 475 469 def floatInvTransform(self, x): 476 470 """ 477 transform a float.It is use to determine the x.View min and x.View 471 transform a float.It is use to determine the x.View min and x.View 478 472 max for values not in x 479 473 … … 482 476 # functionality work without rewritting the whole code 483 477 # with good design (which really should be done...). 484 if(self.xLabel == "x^(2)"): 478 if(self.xLabel == "x^(2)"): 485 479 return math.sqrt(x) 486 480 … … 488 482 return math.pow(10, x) 489 483 490 elif(self.xLabel == "ln(x)"): 484 elif(self.xLabel == "ln(x)"): 491 485 return math.exp(x) 492 486 return x … … 499 493 value = item.GetValue() 500 494 # Check for possible values entered 501 if (self.xLabel == "log10(x)") :#or self.xLabel=="ln(x)"):495 if (self.xLabel == "log10(x)"): #or self.xLabel=="ln(x)"): 502 496 if(float(value) > 0): 503 497 item.SetBackgroundColour(wx.WHITE) … … 520 514 Set the fit region 521 515 :param xmin: minimum x-value to be included in fit 522 :param xmax: maximum x-value to be included in fit 516 :param xmax: maximum x-value to be included in fit 523 517 """ 524 518 # Check values … … 532 526 self.xmaxFit.SetValue(format_number(xmax)) 533 527 528 534 529 class MyApp(wx.App): 535 530 """ … … 540 535 wx.InitAllImageHandlers() 541 536 plot = Theory1D([], []) 542 dialog = LinearFit(parent=None, plottable=plot, 537 dialog = LinearFit(parent=None, plottable=plot, 543 538 push_data=self.onFitDisplay, 544 transform=self.returnTrans, 539 transform=self.returnTrans, 545 540 title='Linear Fit') 546 541 if dialog.ShowModal() == wx.ID_OK: … … 558 553 """ 559 554 return '', '', 0, 0, 0, 0, 0 560 561 # end of class MyApp562 563 if __name__ == "__main__":564 app = MyApp(0)565 app.MainLoop() -
plottools/src/danse/common/plottools/fittings.py
rcfe1feb r10bfeb3 2 2 """ 3 3 from scipy import optimize 4 #from numpy import * 4 5 5 6 6 class Parameter: … … 21 21 22 22 def __call__(self): 23 """ 23 """ 24 24 Return the current value of the parameter 25 25 """ 26 26 return self.model.getParam(self.name) 27 27 28 28 29 def sansfit(model, pars, x, y, err_y , qmin=None, qmax=None): … … 34 35 :param x: vector of x data 35 36 :param y: vector of y data 36 :param err_y: vector of y errors 37 37 :param err_y: vector of y errors 38 38 """ 39 39 def f(params): 40 40 """ 41 Calculates the vector of residuals for each point 41 Calculates the vector of residuals for each point 42 42 in y for a given set of input parameters. 43 43 … … 79 79 chisqr = chi2([out]) 80 80 81 return chisqr, out, cov_x 81 return chisqr, out, cov_x 82 82 83 83 84 def calcCommandline(event): … … 85 86 # Fit a Line model 86 87 from LineModel import LineModel 87 line 88 line = LineModel() 88 89 cstA = Parameter(line, 'A', event.cstA) 89 cstB = Parameter(line, 'B', event.cstB)90 cstB = Parameter(line, 'B', event.cstB) 90 91 y = line.run() 91 chisqr, out, cov = sansfit(line, [cstA, cstB], event.x, y, 0)92 chisqr, out, cov = sansfit(line, [cstA, cstB], event.x, y, 0) 92 93 # print "Output parameters:", out 93 94 print "The right answer is [70.0, 1.0]" 94 95 print chisqr, out, cov 95 96 if __name__ == "__main__":97 calcCommandline()98 -
plottools/src/danse/common/plottools/plottable_interactor.py
r82a54b8 r10bfeb3 17 17 self.color = color 18 18 self.colorlist = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] 19 self.symbollist = ['o', 'x', '^', 'v', '<', '>', 20 '+', 's', 'd', 'D', 'h', 'H', 'p', '-']19 self.symbollist = ['o', 'x', '^', 'v', '<', '>', 20 '+', 's', 'd', 'D', 'h', 'H', 'p', '-'] 21 21 self.markersize = None 22 22 self.marker = None … … 35 35 return self.symbollist[s % len(self.symbollist)] 36 36 37 def points(self, x, y, dx=None, dy=None, color=0, symbol=0, markersize=5, label=None,38 hide_error=False):37 def points(self, x, y, dx=None, dy=None, color=0, symbol=0, markersize=5, 38 label=None, hide_error=False): 39 39 """ 40 40 """ … … 66 66 zorder = 1 67 67 self.marker = self.axes.plot(x, y, color=self.color, 68 marker=self._symbol(symbol),69 markersize=markersize,70 linestyle='', label=label,71 zorder=zorder)[0]68 marker=self._symbol(symbol), 69 markersize=markersize, 70 linestyle='', label=label, 71 zorder=zorder)[0] 72 72 else: 73 73 zorder = 2 74 74 self.marker = self.axes.errorbar(x, y, yerr=dy, 75 xerr=None, 76 ecolor=self.color, 77 color=self.color, 78 capsize=2, 79 linestyle='', 80 barsabove=False, 81 #mec=self.color, mfc=self.color, 82 marker=self._symbol(symbol), 83 markersize=markersize, 84 lolims=False, uplims=False, 85 xlolims=False, xuplims=False, 86 label=label, 87 zorder=zorder)[0] 75 xerr=None, 76 ecolor=self.color, 77 color=self.color, 78 capsize=2, 79 linestyle='', 80 barsabove=False, 81 marker=self._symbol(symbol), 82 markersize=markersize, 83 lolims=False, uplims=False, 84 xlolims=False, xuplims=False, 85 label=label, 86 zorder=zorder)[0] 88 87 89 88 self.connect_markers([self.marker]) … … 96 95 self.base.connect.clear([self.marker]) 97 96 self.color = self._color(color) 98 self.marker = self.axes.plot(x, y, color=self.color, lw =1.5,97 self.marker = self.axes.plot(x, y, color=self.color, lw=1.5, 99 98 marker='', linestyle='-', label=label)[0] 100 99 … … 112 111 connect('click', h, self._on_click) 113 112 connect('release', h, self._on_release) 114 #connect('drag', h, self._on_drag)115 113 connect('key', h, self.onKey) 116 114 … … 128 126 self._on_leave(evt) 129 127 130 def _on_release(self, evt): 128 def _on_release(self, evt): 131 129 """ 132 130 Called when a mouse button is released 133 131 within the boundaries of an artist 134 132 """ 135 # Check to see whether we are about to pop 133 # Check to see whether we are about to pop 136 134 # the context menu up 137 135 if evt.button == 3: … … 148 146 if evt.artist.get_color() == 'y': 149 147 try: 150 148 evt.artist.set_color('b') 151 149 except: 152 150 evt.artist.set_color_cycle('b') … … 157 155 else: 158 156 try: 159 157 evt.artist.set_color('y') 160 158 except: 161 159 evt.artist.set_color_cycle('y') … … 181 179 if hasattr(evt.artist, "set_facecolor"): 182 180 evt.artist.set_facecolor(self.color) 183 if hasattr(evt.artist, "set_edgecolor"): 181 if hasattr(evt.artist, "set_edgecolor"): 184 182 evt.artist.set_edgecolor(self.color) 185 183 self.axes.figure.canvas.draw_idle() … … 190 188 """ 191 189 pass 192 -
plottools/src/danse/common/plottools/plottables.py
r82a54b8 r10bfeb3 44 44 import copy 45 45 import numpy 46 import math47 46 import sys 48 47 … … 51 50 def any(L): 52 51 for cond in L: 53 if cond: return True 52 if cond: 53 return True 54 54 return False 55 55 56 def all(L): 56 57 for cond in L: … … 59 60 return True 60 61 61 # Graph structure for holding multiple plottables 62 62 63 class Graph: 63 64 """ … … 129 130 (as opposed to changing the basic properties) 130 131 """ 131 if units != "": 132 132 if units != "": 133 name = "%s (%s)" % (name, units) 133 134 self.prop["xlabel"] = name 134 135 self.prop["xunit"] = units … … 140 141 (as opposed to changing the basic properties) 141 142 """ 142 if units != "": 143 143 if units != "": 144 name = "%s (%s)" % (name, units) 144 145 self.prop["ylabel"] = name 145 146 self.prop["yunit"] = units … … 149 150 Properties of the x axis. 150 151 """ 151 if units != "": 152 152 if units != "": 153 name = "%s (%s)" % (name, units) 153 154 self.prop["xlabel"] = name 154 155 self.prop["xunit"] = units … … 160 161 Properties of the y axis. 161 162 """ 162 if units != "": 163 163 if units != "": 164 name = "%s (%s)" % (name, units) 164 165 self.prop["ylabel"] = name 165 166 self.prop["yunit"] = units … … 200 201 if plottable in self.plottables: 201 202 return True 202 return False 203 return False 203 204 204 205 def add(self, plottable, color=None): … … 211 212 self.color += plottable.colors() 212 213 self.plottables[plottable] = self.color 213 214 214 215 def changed(self): 215 216 """Detect if any graphed plottables have changed""" … … 250 251 if plottable in self.plottables: 251 252 del self.plottables[plottable] 252 self.color = len(self.plottables) 253 self.color = len(self.plottables) 253 254 254 255 def reset_scale(self): … … 263 264 self.color = -1 264 265 self.symbol = 0 265 self.prop = {"xlabel": "", "xunit":None,266 "ylabel": "","yunit":None,267 "title": ""}266 self.prop = {"xlabel": "", "xunit": None, 267 "ylabel": "", "yunit": None, 268 "title": ""} 268 269 self.plottables = {} 269 270 … … 297 298 """ 298 299 This method returns a dictionary of plottables contained in graph 299 It is just by Plotpanel to interact with the complete list of plottables 300 It is just by Plotpanel to interact with the complete list of plottables 300 301 inside the graph. 301 302 """ … … 310 311 for p in self.plottables: 311 312 if p.custom_color is not None: 312 p.render(plot, color=p.custom_color, symbol=0, 313 p.render(plot, color=p.custom_color, symbol=0, 313 314 markersize=p.markersize, label=labels[p]) 314 315 else: 315 p.render(plot, color=self.plottables[p], symbol=0, 316 p.render(plot, color=self.plottables[p], symbol=0, 316 317 markersize=p.markersize, label=labels[p]) 317 318 plot.render() … … 346 347 menu for the graph. 347 348 348 type: operational axis. This determines whether the 349 type: operational axis. This determines whether the 349 350 transform should appear on x,y or z axis context 350 351 menus, or if it should appear in the context menu for … … 353 354 inventory: (not implemented) 354 355 a dictionary of user settable parameter names and 355 their associated types. These should appear as keyword 356 arguments to the transform call. For example, Fresnel 356 their associated types. These should appear as keyword 357 arguments to the transform call. For example, Fresnel 357 358 reflectivity requires the substrate density: 358 359 { 'rho': type.Value(10e-6/units.angstrom**2) } 359 360 360 Supply reasonable defaults in the callback so that 361 limited plotting clients work even though they cannot 361 Supply reasonable defaults in the callback so that 362 limited plotting clients work even though they cannot 362 363 set the inventory. 363 364 … … 373 374 the standard x,dx,y,dy,z,dz attributes appropriately. 374 375 375 If the call raises a NotImplemented error the dataline 376 If the call raises a NotImplemented error the dataline 376 377 will not be plotted. The associated string will usually 377 378 be 'Not a valid transform', though other strings are possible. … … 380 381 381 382 """ 382 raise NotImplemented, "Not a valid transform"383 raise NotImplemented, "Not a valid transform" 383 384 384 385 # Related issues … … 387 388 # log scale: 388 389 # All axes have implicit log/linear scaling options. 389 # 390 # 390 391 # normalization: 391 392 # Want to display raw counts vs detector efficiency correction … … 401 402 # 402 403 # multiline graph: 403 # How do we show/hide data parts. E.g., data or theory, or 404 # How do we show/hide data parts. E.g., data or theory, or 404 405 # different polarization cross sections? One way is with 405 406 # tags: each plottable has a set of tags and the tags are … … 420 421 """ 421 422 """ 422 # Short ascii name to refer to the plottable in a menu 423 # Short ascii name to refer to the plottable in a menu 423 424 short_name = None 424 425 # Fancy name … … 434 435 interactive = True 435 436 custom_color = None 436 markersize = 5 #default marker size is 'size 5'437 markersize = 5 # default marker size is 'size 5' 437 438 438 439 def __init__(self): … … 441 442 self._xunit = "" 442 443 self._yaxis = "" 443 self._yunit = "" 444 self._yunit = "" 444 445 445 446 def __setattr__(self, name, value): … … 495 496 def labels(cls, collection): 496 497 """ 497 Construct a set of unique labels for a collection of plottables of 498 Construct a set of unique labels for a collection of plottables of 498 499 the same type. 499 500 … … 509 510 else: 510 511 for i in xrange(len(collection)): 511 map[collection[i]] = "%s %d" %(basename, i)512 map[collection[i]] = "%s %d" % (basename, i) 512 513 return map 514 513 515 ##Use the following if @classmethod doesn't work 514 516 # labels = classmethod(labels) … … 526 528 def set_View(self, x, y): 527 529 """Load View""" 528 self.x = x530 self.x = x 529 531 self.y = y 530 532 self.reset_view() … … 541 543 """ 542 544 The base class makes sure the correct units are being used for 543 subsequent plottable. 544 545 For now it is assumed that the graphs are commensurate, and if you 545 subsequent plottable. 546 547 For now it is assumed that the graphs are commensurate, and if you 546 548 put a Qx object on a Temperature graph then you had better hope 547 549 that it makes sense. … … 560 562 return False 561 563 562 563 564 def colors(self): 564 565 """Return the number of colors need to render the object""" … … 577 578 return self.view.returnXview() 578 579 579 def check_data_PlottableX(self): 580 """ 581 Since no transformation is made for log10(x), check that 580 def check_data_PlottableX(self): 581 """ 582 Since no transformation is made for log10(x), check that 582 583 no negative values is plot in log scale 583 584 """ 584 585 self.view.check_data_logX() 585 586 586 def check_data_PlottableY(self): 587 def check_data_PlottableY(self): 587 588 """ 588 589 Since no transformation is made for log10(y), check that 589 590 no negative values is plot in log scale 590 591 """ 591 self.view.check_data_logY() 592 self.view.check_data_logY() 592 593 593 594 def transformX(self, transx, transdx): 594 595 """ 595 Receive pointers to function that transform x and dx 596 Receive pointers to function that transform x and dx 596 597 and set corresponding View pointers 597 598 … … 604 605 def transformY(self, transy, transdy): 605 606 """ 606 Receive pointers to function that transform y and dy 607 Receive pointers to function that transform y and dy 607 608 and set corresponding View pointers 608 609 … … 628 629 """ 629 630 self.view.onFitRangeView(xmin, xmax) 630 631 632 631 633 class View: 632 634 """ … … 666 668 :param x: array of x values 667 669 :param y: array of y values 668 :param dx: array of errors values on x 670 :param dx: array of errors values on x 669 671 :param dy: array of error values on y 670 672 … … 675 677 has_err_y = not (dy == None or len(dy) == 0) 676 678 677 if(x != None) and (y != None): 678 if not dx == None and not len(dx) == 0 and not len(x) == len(dx):679 if(x != None) and (y != None): 680 if not dx == None and not len(dx) == 0 and not len(x) == len(dx): 679 681 msg = "Plottable.View: Given x and dx are not" 680 msg += " of the same length" 682 msg += " of the same length" 681 683 raise ValueError, msg 682 684 # Check length of y array … … 686 688 raise ValueError, msg 687 689 688 if not dy == None and not len(dy) == 0 and not len(y) ==len(dy):690 if not dy == None and not len(dy) == 0 and not len(y) == len(dy): 689 691 msg = "Plottable.View: Given y and dy are not of the same " 690 msg += "length: len(y)=%s, len(dy)=%s" % (len(y),len(dy))692 msg += "length: len(y)=%s, len(dy)=%s" % (len(y), len(dy)) 691 693 raise ValueError, msg 692 694 self.x = [] … … 708 710 for i in range(len(x)): 709 711 try: 710 tempx = self.funcx(x[i],y[i])711 tempy = self.funcy(y[i],x[i])712 tempx = self.funcx(x[i], y[i]) 713 tempy = self.funcy(y[i], x[i]) 712 714 if has_err_x: 713 715 tempdx = self.funcdx(x[i], y[i], dx[i], dy[i]) … … 727 729 if not len(self.x) == len(self.y): 728 730 msg = "Plottable.View: transformed x " 729 msg += "and y are not of the same length" 731 msg += "and y are not of the same length" 730 732 raise ValueError, msg 731 733 if has_err_x and not (len(self.x) and len(self.dx)): 732 734 msg = "Plottable.View: transformed x and dx" 733 msg += " are not of the same length" 735 msg += " are not of the same length" 734 736 raise ValueError, msg 735 737 if has_err_y and not (len(self.y) and len(self.dy)): 736 738 msg = "Plottable.View: transformed y" 737 msg += " and dy are not of the same length" 739 msg += " and dy are not of the same length" 738 740 raise ValueError, msg 739 741 # Check that negative values are not plot on x and y axis for … … 750 752 """ 751 753 Reset x,y,dx and y in their full range and in the initial scale 752 in case their previous range has changed 753 754 in case their previous range has changed 754 755 """ 755 756 self.x = self.Xreel … … 758 759 self.dy = self.DYreel 759 760 760 def setTransformX(self, funcx, funcdx): 761 """ 762 Receive pointers to function that transform x and dx 761 def setTransformX(self, funcx, funcdx): 762 """ 763 Receive pointers to function that transform x and dx 763 764 and set corresponding View pointers 764 765 765 766 :param transx: pointer to function that transforms x 766 767 :param transdx: pointer to function that transforms dx 767 768 768 """ 769 769 self.funcx = funcx … … 772 772 def setTransformY(self, funcy, funcdy): 773 773 """ 774 Receive pointers to function that transform y and dy 774 Receive pointers to function that transform y and dy 775 775 and set corresponding View pointers 776 776 777 777 :param transx: pointer to function that transforms y 778 778 :param transdx: pointer to function that transforms dy 779 780 """ 779 """ 781 780 self.funcy = funcy 782 781 self.funcdy = funcdy … … 788 787 return self.x, self.y, self.dx, self.dy 789 788 790 def check_data_logX(self): 789 def check_data_logX(self): 791 790 """ 792 791 Remove negative value in x vector to avoid plotting negative 793 792 value of Log10 794 795 793 """ 796 794 tempx = [] … … 802 800 if self.dy == None: 803 801 self.dy = numpy.zeros(len(self.y)) 804 if self.xLabel == "log10(x)" 802 if self.xLabel == "log10(x)": 805 803 for i in range(len(self.x)): 806 804 try: … … 812 810 except: 813 811 print "check_data_logX: skipping point x %g" % self.x[i] 814 print sys.exc_value 812 print sys.exc_value 815 813 pass 816 814 self.x = tempx … … 819 817 self.dy = tempdy 820 818 821 def check_data_logY(self): 822 """ 823 Remove negative value in y vector 819 def check_data_logY(self): 820 """ 821 Remove negative value in y vector 824 822 to avoid plotting negative value of Log10 825 823 … … 833 831 if self.dy == None: 834 832 self.dy = numpy.zeros(len(self.y)) 835 if (self.yLabel == "log10(y)" 833 if (self.yLabel == "log10(y)"): 836 834 for i in range(len(self.x)): 837 835 try: 838 836 if (self.y[i] > 0): 839 837 tempx.append(self.x[i]) … … 841 839 tempy.append(self.y[i]) 842 840 tempdy.append(self.dy[i]) 843 844 print "check_data_logY: skipping point %g" % self.y[i]845 print sys.exc_value 841 except: 842 print "check_data_logY: skipping point %g" % self.y[i] 843 print sys.exc_value 846 844 pass 847 845 self.x = tempx … … 865 863 self.dx = numpy.zeros(len(self.x)) 866 864 if self.dy == None: 867 self.dy =numpy.zeros(len(self.y))865 self.dy = numpy.zeros(len(self.y)) 868 866 if (xmin != None) and (xmax != None): 869 867 for i in range(len(self.x)): … … 876 874 self.y = tempy 877 875 self.dx = tempdx 878 self.dy = tempdy 879 876 self.dy = tempdy 877 878 880 879 class Data2D(Plottable): 881 880 """ … … 910 909 self._yunit = 'A^{-1}' 911 910 912 ### might remove that later 911 ### might remove that later 913 912 ## Vector of Q-values at the center of each bin in x 914 913 self.x_bins = [] … … 1003 1002 plot.image(self.data, self.qx_data, self.qy_data, 1004 1003 self.xmin, self.xmax, self.ymin, 1005 self.ymax, self.zmin, self.zmax, **kw) 1004 self.ymax, self.zmin, self.zmax, **kw) 1006 1005 1007 1006 def changed(self): … … 1021 1020 map[item] = item.label 1022 1021 return map 1022 1023 1023 1024 1024 class Data1D(Plottable): … … 1060 1060 if self.interactive == True: 1061 1061 kw['symbol'] = self.symbol 1062 kw['id'] = 1062 kw['id'] = self.id 1063 1063 kw['hide_error'] = self.hide_error 1064 1064 kw['markersize'] = self.markersize 1065 1065 plot.interactive_points(self.view.x, self.view.y, 1066 1066 dx=self.view.dx, dy=self.view.dy, 1067 name=self.name, **kw) 1067 name=self.name, **kw) 1068 1068 else: 1069 1069 kw['id'] = self.id … … 1072 1072 kw['color'] = self.custom_color 1073 1073 kw['markersize'] = self.markersize 1074 plot.points(self.view.x, self.view.y, dx=self.view.dx, 1074 plot.points(self.view.x, self.view.y, dx=self.view.dx, 1075 1075 dy=self.view.dy, marker=self.symbollist[self.symbol], **kw) 1076 1076 … … 1089 1089 map[item] = item.label 1090 1090 return map 1091 1091 1092 1092 1093 class Theory1D(Plottable): … … 1121 1122 """ 1122 1123 """ 1123 if self.interactive==True: 1124 1125 kw['id'] = self.id 1124 if self.interactive == True: 1125 kw['id'] = self.id 1126 1126 plot.interactive_curve(self.view.x, self.view.y, 1127 1127 dy=self.view.dy, 1128 1128 name=self.name, **kw) 1129 1129 else: 1130 kw['id'] = 1130 kw['id'] = self.id 1131 1131 plot.curve(self.view.x, self.view.y, dy=self.view.dy, **kw) 1132 1132 … … 1139 1139 map = {} 1140 1140 for item in collection: 1141 #map[item] = label(item, collection)1142 #map[item] = r"$\rm{%s}$" % item.name1143 1141 if item.label == "theory": 1144 1142 item.label = item.name … … 1175 1173 return self.data.changed() or self.theory.changed() 1176 1174 1175 1177 1176 # --------------------------------------------------------------- 1178 1177 class Text(Plottable): … … 1190 1189 self.ypos = ypos 1191 1190 1192 def render(self, plot,**kw):1191 def render(self, plot, **kw): 1193 1192 """ 1194 1193 """ 1195 1194 from matplotlib import transforms 1196 1195 1197 xcoords =transforms.blended_transform_factory(plot.subplot.transAxes,1198 plot.subplot.transAxes)1196 xcoords = transforms.blended_transform_factory(plot.subplot.transAxes, 1197 plot.subplot.transAxes) 1199 1198 plot.subplot.text(self.xpos, 1200 1199 self.ypos, … … 1206 1205 def setText(self, text): 1207 1206 """Set the text string.""" 1208 self.text = 1207 self.text = text 1209 1208 1210 1209 def getText(self, text): … … 1230 1229 class Chisq(Plottable): 1231 1230 """ 1232 Chisq plottable plots the chisq 1231 Chisq plottable plots the chisq 1233 1232 """ 1234 1233 def __init__(self, chisq=None): … … 1265 1264 Set the chisq value. 1266 1265 """ 1267 self._chisq = 1266 self._chisq = chisq 1268 1267 1269 1268 … … 1275 1274 # Construct a simple graph 1276 1275 if False: 1277 x = nx.array([1,2,3,4,5,6], 'd')1278 y = nx.array([4,5,6,5,4,5], 'd')1276 x = nx.array([1,2,3,4,5,6], 'd') 1277 y = nx.array([4,5,6,5,4,5], 'd') 1279 1278 dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 1280 1279 else: 1281 x = nx.linspace(0, 1.,10000)1280 x = nx.linspace(0, 1., 10000) 1282 1281 y = nx.sin(2 * nx.pi * x * 2.8) 1283 1282 dy = nx.sqrt(100 * nx.abs(y)) / 100 … … 1289 1288 graph.add(data) 1290 1289 graph.add(Theory1D(x, y, dy=dy)) 1291 return graph 1290 return graph 1291 1292 1292 1293 1293 def demo_plotter(graph): … … 1306 1306 1307 1307 class GraphUpdate: 1308 callnum=0 1308 callnum = 0 1309 1309 1310 def __init__(self, graph, plotter): 1310 1311 self.graph, self.plotter = graph, plotter 1312 1311 1313 def __call__(self): 1312 if self.graph.changed(): 1314 if self.graph.changed(): 1313 1315 self.graph.render(self.plotter) 1314 1316 return True 1315 1317 return False 1318 1316 1319 def onIdle(self, event): 1317 #print "On Idle checker %d"%(self.callnum)1318 1320 self.callnum = self.callnum + 1 1319 1321 if self.__call__(): 1320 pass # event.RequestMore()1322 pass # event.RequestMore() 1321 1323 update = GraphUpdate(graph, plotter) 1322 1324 frame.Bind(wx.EVT_IDLE, update.onIdle) 1323 1325 app.MainLoop() 1324 1325 import sys; print sys.version1326 if __name__ == "__main__":1327 demo_plotter(sample_graph())1328 -
plottools/src/danse/common/plottools/toolbar.py
r82a54b8 r10bfeb3 1 2 1 """ 3 this module overwrite matplotlib toolbar 4 2 This module overwrites matplotlib toolbar 5 3 """ 6 4 import wx 7 5 from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg 8 from matplotlib.backends.backend_wx import _load_bitmap9 6 10 7 class NavigationToolBar(NavigationToolbar2WxAgg): … … 28 25 """ 29 26 #delte reset button 30 self.DeleteToolByPos(0) 27 self.DeleteToolByPos(0) 31 28 #delete unwanted button that configures subplot parameters 32 self.DeleteToolByPos(5) 29 self.DeleteToolByPos(5) 33 30 34 31 def add_option(self): … … 41 38 context_tip += ' For more menu options, \n' 42 39 context_tip += ' right-click the data symbols.' 43 context = 44 self.InsertSimpleTool(0, id_context, context, 40 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 41 self.InsertSimpleTool(0, id_context, context, 45 42 context_tip, context_tip) 46 wx.EVT_TOOL(self, id_context, 43 wx.EVT_TOOL(self, id_context, self.on_menu) 47 44 self.InsertSeparator(1) 48 45 49 46 id_print = wx.NewId() 50 print_bmp = 47 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 51 48 self.AddSimpleTool(id_print, print_bmp, 52 49 'Print', 'Activate printing') … … 54 51 #add reset button 55 52 id_reset = wx.NewId() 56 reset_bmp = 53 reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR) 57 54 self.AddSimpleTool(id_reset, reset_bmp, 58 55 'Reset Graph Range', 'Reset graph range') … … 85 82 except: 86 83 pass 84 -
plottools/src/danse/common/plottools/transform.py
r8d27cac r10bfeb3 1 import math 1 import math 2 2 3 3 4 def toX(x, y=None): … … 12 13 return x 13 14 15 14 16 def toX_pos(x, y=None): 15 17 """ … … 26 28 return x 27 29 30 28 31 def toX2(x, y=None): 29 32 """ … … 37 40 return x * x 38 41 42 39 43 def fromX2(x, y=None): 40 44 """ … … 45 49 46 50 """ 47 if not x >= 0 51 if not x >= 0: 48 52 raise ValueError, "square root of a negative value " 49 53 else: 50 54 return math.sqrt(x) 51 55 56 52 57 def toX4(x, y=None): 53 58 """ … … 61 66 return x * x * x * x 62 67 68 63 69 def fromX4(x, y=None): 64 70 """ … … 69 75 70 76 """ 71 if not x >= 0 77 if not x >= 0: 72 78 raise ValueError, "double square root of a negative value " 73 79 else: 74 80 return math.sqrt(math.sqrt(x)) 75 81 82 76 83 def toLogX(x, y=None): 77 84 """ … … 93 100 return 1/x 94 101 else: 95 raise ValueError,"cannot divide by zero" 102 raise ValueError, "cannot divide by zero" 103 96 104 97 105 def toOneOverSqrtX(y, x=None): … … 101 109 return 1/math.sqrt(y) 102 110 else: 103 raise ValueError,"transform.toOneOverSqrtX: cannot be computed" 111 raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 112 104 113 105 114 def toLogYX2(y, x): 106 115 """ 107 116 """ 108 if (y * (x**2)) > 0:117 if (y * (x**2)) > 0: 109 118 return math.log(y * (x**2)) 110 119 else: 111 raise ValueError,"transform.toLogYX2: cannot be computed" 120 raise ValueError, "transform.toLogYX2: cannot be computed" 121 112 122 113 123 def toLogYX4(y, x): … … 117 127 return math.log(math.pow(x,4) * y) 118 128 else: 119 raise ValueError,"transform.toLogYX4: input error" 129 raise ValueError,"transform.toLogYX4: input error" 130 120 131 121 132 def toYX4(y, x): … … 123 134 """ 124 135 return math.pow(x, 4) * y 136 125 137 126 138 def toLogXY(y, x): … … 137 149 return math.log(x * y) 138 150 151 139 152 def errToX(x, y=None, dx=None, dy=None): 140 153 """ … … 149 162 return dx 150 163 164 151 165 def errToX_pos(x, y=None, dx=None, dy=None): 152 166 """ … … 158 172 """ 159 173 if dx == None: 160 dx = 0 174 dx = 0 161 175 return dx 176 162 177 163 178 def errToX2(x, y=None, dx=None, dy=None): … … 175 190 return 0.0 176 191 192 177 193 def errFromX2(x, y=None, dx=None, dy=None): 178 194 """ … … 185 201 if (x > 0): 186 202 if(dx != None): 187 err = dx /(2 * math.sqrt(x))203 err = dx / (2 * math.sqrt(x)) 188 204 else: 189 205 err = 0 … … 193 209 raise ValueError, msg 194 210 211 195 212 def errToX4(x, y=None, dx=None, dy=None): 196 213 """ … … 207 224 return 0.0 208 225 226 209 227 def errFromX4(x, y=None, dx=None, dy=None): 210 228 """ … … 217 235 if (x > 0): 218 236 if(dx != None): 219 err = dx /(4 * math.pow(x, 3/4))237 err = dx / (4 * math.pow(x, 3/4)) 220 238 else: 221 239 err = 0 … … 224 242 msg = "transform.errFromX4: can't compute error of negative x" 225 243 raise ValueError, msg 244 226 245 227 246 def errToLog10X(x, y=None, dx=None, dy=None): … … 243 262 raise ValueError, msg 244 263 if x != 0: 245 dx = dx / (x * math.log(10))264 dx = dx / (x * math.log(10)) 246 265 else: 247 266 raise ValueError, "errToLogX: divide by zero" 248 267 return dx 268 249 269 250 270 def errToLogX(x, y=None, dx=None, dy=None): … … 266 286 return dx 267 287 288 268 289 def errToYX2(x, y, dx=None, dy=None): 269 290 """ … … 274 295 dy = 0 275 296 err = math.sqrt((2 * x * y * dx)**2 + ((x**2) * dy)**2) 276 return err 297 return err 298 277 299 278 300 def errToLogXY(x, y, dx=None, dy=None): … … 298 320 return math.sqrt(math.fabs(err)) 299 321 322 300 323 def errToLogYX2(x, y, dx=None, dy=None): 301 324 """ … … 317 340 else: 318 341 raise ValueError, "cannot compute this error" 319 return math.sqrt(math.fabs(err)) 342 return math.sqrt(math.fabs(err)) 343 320 344 321 345 def errOneOverX(x, y=None, dx=None, dy=None): … … 329 353 err = dx/x**2 330 354 else: 331 raise ValueError, "Cannot compute this error"355 raise ValueError, "Cannot compute this error" 332 356 return math.fabs(err) 357 333 358 334 359 def errOneOverSqrtX(x, y=None, dx=None, dy=None): … … 344 369 raise ValueError, "Cannot compute this error" 345 370 return math.fabs(err) 371 346 372 347 373 def errToLogYX4(x, y=None, dx=None, dy=None): … … 363 389 dy = 0 364 390 err = math.sqrt((4.0 * dx/x)**2 + (dy/y)**2) 365 return err 391 return err 392 366 393 367 394 def errToYX4(x, y=None, dx=None, dy=None): … … 380 407 dy = 0 381 408 err = math.sqrt((dy * pow(x, 4))**2 + (4 * y * dx * math.pow(x, 3))**2) 382 return err 383 409 return err -
plottools/src/danse/common/plottools/unitConverter.py
r82a54b8 r10bfeb3 1 import re, string 1 import re 2 import string 2 3 #Input -> new scale -> Output 3 4 4 unit1 = "A^{-1} " #x A^{-1}5 unit1 = "A^{-1} " # x A^{-1} 5 6 unit2 = "A" # x A 6 unit3 = "A" # x^2 A^{2}7 unit3 = "A" # x^2 A^{2} 7 8 unit4 = "A " # 1/x A^{-1} 8 unit5 = "A^{0.5} " # x^2 A9 unit9 = "m^{1/2}" # x^2 m9 unit5 = "A^{0.5} " # x^2 A 10 unit9 = "m^{1/2}" # x^2 m 10 11 11 12 #If you don't recognize the pattern, give up … … 13 14 14 15 unit6 = "m/s" # x^2 (m/s)^{2} 15 unit7 = "m/s^{2}" # 1/x (m/s^{2})^{-1}16 unit8 = "m/s^{4}" # x^2 (m/s^{4})^{2}16 unit7 = "m/s^{2}" # 1/x (m/s^{2})^{-1} 17 unit8 = "m/s^{4}" # x^2 (m/s^{4})^{2} 17 18 18 19 … … 21 22 """ 22 23 if pow != 0: 23 if string.find(unit, "^") != -1: # if the unit contains a power ^24 if string.find(unit, "^") != -1: # if the unit contains a power ^ 24 25 unitSplitted = re.split("\^", unit) 25 if string.find(unitSplitted[0], "/") != -1 or\26 string.find(unitSplitted[0], "-") != -1 :# find slash /26 if string.find(unitSplitted[0], "/") != -1 or\ 27 string.find(unitSplitted[0], "-") != -1 : # find slash / 27 28 if pow == 1: 28 29 unit = unit … … 30 31 unit = "("+unit+")" + "^{"+ str(pow) + "}" 31 32 else: 32 if string.find(unitSplitted[1], "{") != -1:# if found a {33 findPower = re.split("{", unitSplitted[1])34 if string.find(findPower[1], "}") != -1:# found }33 if string.find(unitSplitted[1], "{") != -1: # if found a { 34 findPower = re.split("{", unitSplitted[1]) 35 if string.find(findPower[1], "}") != -1: # found } 35 36 unitPower = re.split("}", findPower[1]) 36 if(string.find(unitPower[0], ".") != -1):37 power = float(unitPower[0]) * pow 38 elif(string.find(unitPower[0], "/") != -1):37 if(string.find(unitPower[0], ".") != -1): 38 power = float(unitPower[0]) * pow 39 elif(string.find(unitPower[0], "/") != -1): 39 40 #power is a float 40 41 poweSplitted = re.split("/", unitPower[0]) 41 42 power = pow * int(poweSplitted[0])\ 42 /int(poweSplitted[1])43 /int(poweSplitted[1]) 43 44 else: 44 power = int(unitPower[0]) * pow 45 power = int(unitPower[0]) * pow 45 46 46 47 if power == 1.0: 47 unit = unitSplitted[0]48 unit = unitSplitted[0] 48 49 elif power == 0.5: 49 unit = unitSplitted[0] + "^{1/2}" 50 unit = unitSplitted[0] + "^{1/2}" 50 51 elif power == -0.5: 51 unit = unitSplitted[0] + "^{-1/2}" 52 unit = unitSplitted[0] + "^{-1/2}" 52 53 else: 53 unit = unitSplitted[0] + "^{" + str(power) + "}" 54 unit = unitSplitted[0] + "^{" + str(power) + "}" 54 55 else: 55 raise ValueError, "missing } in unit expression" 56 else: #no power56 raise ValueError, "missing } in unit expression" 57 else: # no power 57 58 if pow != 1: 58 59 unit = "(" + unit + ")" + "^{" + str(pow) + "}" … … 60 61 raise ValueError, "empty unit ,enter a power different from zero" 61 62 return unit 63 64 62 65 if __name__ == "__main__": 63 66 print "this unit1 %s ,its power %s , and value %s" % (unit1, 64 67 1, UnitConvertion(1, unit1)) 65 print "this unit2 %s ,its power %s , and value %s" % (unit2, 1,68 print "this unit2 %s ,its power %s , and value %s" % (unit2, 1, 66 69 UnitConvertion(1, unit2)) 67 print "this unit3 %s ,its power %s , and value %s" % (unit3, 2, 70 print "this unit3 %s ,its power %s , and value %s" % (unit3, 2, 68 71 UnitConvertion(2, unit3)) 69 print "this unit4 %s ,its power %s , and value %s" % (unit4, -1, 72 print "this unit4 %s ,its power %s , and value %s" % (unit4, -1, 70 73 UnitConvertion(-1, unit4)) 71 74 print "this unit5 %s ,its power %s , and value %s" % (unit5, 2, 72 75 UnitConvertion(2, unit5)) 73 print "this unit6 %s ,its power %s , and value %s" % (unit6, 2, 76 print "this unit6 %s ,its power %s , and value %s" % (unit6, 2, 74 77 UnitConvertion(2, unit6)) 75 print "this unit7 %s ,its power %s , and value %s" % (unit7, -1, 78 print "this unit7 %s ,its power %s , and value %s" % (unit7, -1, 76 79 UnitConvertion(-1, unit7)) 77 print "this unit8 %s ,its power %s , and value %s" % (unit8, 2, 80 print "this unit8 %s ,its power %s , and value %s" % (unit8, 2, 78 81 UnitConvertion(2, unit8)) 79 print "this unit9 %s ,its power %s , and value %s" % (unit9, 2, 82 print "this unit9 %s ,its power %s , and value %s" % (unit9, 2, 80 83 UnitConvertion(2, unit9)) 81
Note: See TracChangeset
for help on using the changeset viewer.