Changeset 121f72c in sasview for src/sas/plottools
- Timestamp:
- Mar 3, 2015 2:20:19 PM (10 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:
- 26500ec
- Parents:
- d00294b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/PlotPanel.py
r79492222 r121f72c 1 1 """ 2 Plot panel. 2 3 """ 3 4 import logging … … 31 32 import numpy 32 33 34 from sas.guiframe.events import StatusEvent 33 35 34 36 def show_tree(obj, d=0): … … 36 38 print "%s%s" % ("-"*d, obj.__class__.__name__) 37 39 if 'get_children' in dir(obj): 38 for a in obj.get_children(): show_tree(a, d +1)39 40 for a in obj.get_children(): show_tree(a, d + 1) 41 40 42 from unitConverter import UnitConvertion as convertUnit 41 43 42 44 43 45 def _rescale(lo, hi, step, pt=None, bal=None, scale='linear'): 44 46 """ 45 47 Rescale (lo,hi) by step, returning the new (lo,hi) 46 48 The scaling is centered on pt, with positive values of step 47 49 driving lo/hi away from pt and negative values pulling them in. 48 50 If bal is given instead of point, it is already in [0,1] coordinates. 49 51 50 52 This is a helper function for step-based zooming. 51 52 """ 53 # Convert values into the correct scale for a linear transformation 54 # TODO: use proper scale transformers 55 loprev = lo 56 hiprev = hi 57 if scale == 'log': 58 assert lo > 0 59 if lo > 0: 60 lo = math.log10(lo) 61 if hi > 0: 62 hi = math.log10(hi) 63 if pt is not None: 64 pt = math.log10(pt) 65 66 # Compute delta from axis range * %, or 1-% if persent is negative 67 if step > 0: 68 delta = float(hi - lo) * step / 100 53 54 """ 55 # Convert values into the correct scale for a linear transformation 56 # TODO: use proper scale transformers 57 loprev = lo 58 hiprev = hi 59 if scale == 'log': 60 assert lo > 0 61 if lo > 0: 62 lo = math.log10(lo) 63 if hi > 0: 64 hi = math.log10(hi) 65 if pt is not None: 66 pt = math.log10(pt) 67 68 # Compute delta from axis range * %, or 1-% if persent is negative 69 if step > 0: 70 delta = float(hi - lo) * step / 100 71 else: 72 delta = float(hi - lo) * step / (100 - step) 73 74 # Add scale factor proportionally to the lo and hi values, 75 # preserving the 76 # point under the mouse 77 if bal is None: 78 bal = float(pt - lo) / (hi - lo) 79 lo = lo - (bal * delta) 80 hi = hi + (1 - bal) * delta 81 82 # Convert transformed values back to the original scale 83 if scale == 'log': 84 if (lo <= -250) or (hi >= 250): 85 lo = loprev 86 hi = hiprev 69 87 else: 70 delta = float(hi - lo) * step / (100 - step) 71 72 # Add scale factor proportionally to the lo and hi values, 73 # preserving the 74 # point under the mouse 75 if bal is None: 76 bal = float(pt - lo) / (hi - lo) 77 lo = lo - (bal * delta) 78 hi = hi + (1 - bal) * delta 79 80 # Convert transformed values back to the original scale 81 if scale == 'log': 82 if (lo <= -250) or (hi >= 250): 83 lo = loprev 84 hi = hiprev 85 else: 86 lo, hi = math.pow(10., lo), math.pow(10., hi) 87 return (lo, hi) 88 lo, hi = math.pow(10., lo), math.pow(10., hi) 89 return (lo, hi) 88 90 89 91 … … 96 98 bmp = wx.BitmapDataObject() 97 99 bmp.SetBitmap(canvas.bitmap) 98 100 99 101 wx.TheClipboard.Open() 100 102 wx.TheClipboard.SetData(bmp) … … 104 106 class PlotPanel(wx.Panel): 105 107 """ 106 The PlotPanel has a Figure and a Canvas. OnSize events simply set a 108 The PlotPanel has a Figure and a Canvas. OnSize events simply set a 107 109 flag, and the actually redrawing of the 108 110 figure is triggered by an Idle event. 109 110 111 """ 111 112 def __init__(self, parent, id=-1, xtransform=None, 112 113 113 ytransform=None, scale='log_{10}', 114 color=None, dpi=None, **kwargs): 114 115 """ 115 116 """ … … 128 129 self.canvas = FigureCanvas(self, -1, self.figure) 129 130 self.SetColor(color) 130 #self.SetBackgroundColour(parent.GetBackgroundColour())131 131 self._resizeflag = True 132 132 self._SetSize() … … 142 142 self.add_toolbar() 143 143 self.SetSizer(self.sizer) 144 144 145 145 # Graph object to manage the plottables 146 146 self.graph = Graph() 147 147 148 148 #Boolean value to keep track of whether current legend is 149 149 #visible or not … … 154 154 self.position = None 155 155 self._loc_labels = self.get_loc_label() 156 156 157 157 self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) 158 158 159 159 # Define some constants 160 self.colorlist = ['b', 'g','r','c','m','y','k']161 self.symbollist = ['o', 'x','^','v','<','>','+',162 's', 'd','D','h','H','p', '-']163 160 self.colorlist = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] 161 self.symbollist = ['o', 'x', '^', 'v', '<', '>', '+', 162 's', 'd', 'D', 'h', 'H', 'p', '-'] 163 164 164 #List of texts currently on the plot 165 165 self.textList = [] … … 180 180 self.scroll_id = self.canvas.mpl_connect('scroll_event', self.onWheel) 181 181 #taking care of dragging 182 self.motion_id = self.canvas.mpl_connect('motion_notify_event', 182 self.motion_id = self.canvas.mpl_connect('motion_notify_event', 183 183 self.onMouseMotion) 184 self.press_id = self.canvas.mpl_connect('button_press_event', 184 self.press_id = self.canvas.mpl_connect('button_press_event', 185 185 self.onLeftDown) 186 186 self.pick_id = self.canvas.mpl_connect('pick_event', self.onPick) 187 self.release_id = self.canvas.mpl_connect('button_release_event', 187 self.release_id = self.canvas.mpl_connect('button_release_event', 188 188 self.onLeftUp) 189 189 190 190 wx.EVT_RIGHT_DOWN(self, self.onLeftDown) 191 191 # to turn axis off whenn resizing the panel 192 192 self.resizing = False 193 193 194 194 self.leftdown = False 195 195 self.leftup = False … … 201 201 self.connect = BindArtist(self.subplot.figure) 202 202 #self.selected_plottable = None 203 203 204 204 # new data for the fit 205 205 self.fit_result = Data1D(x=[], y=[], dy=None) … … 221 221 self.ErrBvalue = None 222 222 self.Chivalue = None 223 223 224 224 # for 2D scale 225 225 if scale != 'linear': … … 237 237 self.zmin_2D = None 238 238 self.zmax_2D = None 239 239 240 240 #index array 241 241 self.index_x = None 242 242 self.index_y = None 243 243 244 244 #number of bins 245 245 self.x_bins = None 246 246 self.y_bins = None 247 247 248 248 ## default color map 249 249 self.cmap = DEFAULT_CMAP 250 250 251 251 # Dragging info 252 252 self.begDrag = False … … 255 255 self.xFinal = None 256 256 self.yFinal = None 257 257 258 258 #axes properties 259 259 self.xaxis_font = None … … 267 267 self.yaxis_color = 'black' 268 268 self.yaxis_tick = None 269 269 270 270 # check if zoomed. 271 271 self.is_zoomed = False 272 272 # Plottables 273 273 self.plots = {} 274 274 275 275 # Default locations 276 276 self._default_save_location = os.getcwd() … … 289 289 self.canvas.SetSize(pixels) 290 290 self.figure.set_size_inches(pixels[0] / self.figure.get_dpi(), 291 pixels[1] / self.figure.get_dpi(), forward=True)292 291 pixels[1] / self.figure.get_dpi(), forward=True) 292 293 293 def On_Paint(self, event): 294 294 """ … … 306 306 self.parent.send_focus_to_datapanel(self.window_caption) 307 307 self.draw() 308 308 309 309 def on_kill_focus(self, event): 310 310 """ … … 315 315 self.figure.set_edgecolor(self.color) 316 316 self.draw() 317 317 318 318 def set_resizing(self, resizing=False): 319 319 """ … … 321 321 """ 322 322 pass # Not implemented 323 323 324 324 def schedule_full_draw(self, func='append'): 325 325 """ … … 327 327 """ 328 328 pass # Not implemented 329 329 330 330 def add_toolbar(self): 331 331 """ … … 352 352 self.toolbar.SetSize(wx.Size(fw, th)) 353 353 self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 354 354 355 355 # update the axes menu on the toolbar 356 356 self.toolbar.update() 357 357 358 358 def onLeftDown(self, event): 359 359 """ 360 360 left button down and ready to drag 361 362 361 """ 363 362 # Check that the LEFT button was pressed … … 386 385 self.mousemotion = False 387 386 self.leftup = True 388 387 389 388 #release the legend 390 389 if self.gotLegend == 1: 391 390 self.gotLegend = 0 392 391 self.set_legend_alpha(1) 393 392 394 393 def set_legend_alpha(self, alpha=1): 395 394 """ … … 398 397 if self.legend != None: 399 398 self.legend.legendPatch.set_alpha(alpha) 400 399 401 400 def onPick(self, event): 402 401 """ … … 416 415 self.gotLegend = 1 417 416 self.set_legend_alpha(0.5) 418 417 419 418 def _on_legend_motion(self, event): 420 419 """ … … 450 449 self.canvas.set_resizing(self.resizing) 451 450 self.canvas.draw() 452 451 453 452 def onMouseMotion(self, event): 454 453 """ … … 456 455 computer delta for x and y coordinates and then calls draghelper 457 456 to perform the drag 458 459 457 """ 460 458 self.cusor_line(event) … … 474 472 self.xInit = self.xFinal 475 473 self.yInit = self.yFinal 476 474 477 475 xdelta = self.xFinal - self.xInit 478 476 ydelta = self.yFinal - self.yInit 479 477 480 478 if self.xscale == 'log': 481 479 xdelta = math.log10(self.xFinal) - math.log10(self.xInit) … … 500 498 if self._scale_yhi is not None and self._scale_ylo is not None: 501 499 ax.set_ylim(self._scale_ylo, self._scale_yhi) 502 500 503 501 def _dragHelper(self, xdelta, ydelta): 504 502 """ 505 503 dragging occurs here 506 507 504 """ 508 505 # Event occurred inside a plotting area 509 506 for ax in self.axes: 510 507 lo, hi = ax.get_xlim() 511 #print "x lo %f and x hi %f"%(lo,hi)512 508 newlo, newhi = lo - xdelta, hi - xdelta 513 509 if self.xscale == 'log': … … 524 520 self._scale_xhi = newhi 525 521 ax.set_xlim(newlo, newhi) 526 #print "new lo %f and new hi %f"%(newlo,newhi) 527 522 528 523 lo, hi = ax.get_ylim() 529 #print "y lo %f and y hi %f"%(lo,hi)530 524 newlo, newhi = lo - ydelta, hi - ydelta 531 525 if self.yscale == 'log': … … 534 528 if hi > 0: 535 529 newhi = math.log10(hi) - ydelta 536 #print "new lo %f and new hi %f"%(newlo,newhi)537 530 if self.yscale == 'log': 538 531 self._scale_ylo = math.pow(10, newlo) … … 548 541 """ 549 542 For fit Dialog initial display 550 551 543 """ 552 544 self.xmin = 0.0 … … 563 555 self.ErrBvalue = None 564 556 self.Chivalue = None 565 557 566 558 def onWheel(self, event): 567 559 """ 568 560 Process mouse wheel as zoom events 569 561 570 562 :param event: Wheel event 571 563 572 564 """ 573 565 ax = event.inaxes … … 578 570 lo, hi = ax.get_xlim() 579 571 lo, hi = _rescale(lo, hi, step, 580 pt=event.xdata, scale=ax.get_xscale())572 pt=event.xdata, scale=ax.get_xscale()) 581 573 if not self.xscale == 'log' or lo > 0: 582 574 self._scale_xlo = lo 583 575 self._scale_xhi = hi 584 ax.set_xlim((lo, hi))576 ax.set_xlim((lo, hi)) 585 577 586 578 lo, hi = ax.get_ylim() 587 579 lo, hi = _rescale(lo, hi, step, pt=event.ydata, 588 scale=ax.get_yscale())580 scale=ax.get_yscale()) 589 581 if not self.yscale == 'log' or lo > 0: 590 582 self._scale_ylo = lo … … 595 587 xdata, ydata = None, None 596 588 x, y = event.x, event.y 597 589 598 590 for ax in self.axes: 599 591 insidex, _ = ax.xaxis.contains(event) … … 625 617 Return values and labels used by Fit Dialog 626 618 """ 627 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \619 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 628 620 self.ErrAvalue, self.ErrBvalue, self.Chivalue 629 621 630 622 def setTrans(self, xtrans, ytrans): 631 623 """ 632 624 633 625 :param xtrans: set x transformation on Property dialog 634 626 :param ytrans: set y transformation on Property dialog 635 627 636 628 """ 637 629 self.prevXtrans = xtrans 638 630 self.prevYtrans = ytrans 639 631 640 632 def onFitting(self, event): 641 633 """ … … 654 646 list = plotlist 655 647 from fitDialog import LinearFit 656 648 657 649 if len(list.keys()) > 0: 658 650 first_item = list.keys()[0] … … 661 653 transform=self.returnTrans, 662 654 title='Linear Fit') 663 655 664 656 if (self.xmin != 0.0)and (self.xmax != 0.0)\ 665 657 and(self.xminView != 0.0)and (self.xmaxView != 0.0): … … 667 659 self.xmin, self.xmax) 668 660 dlg.ShowModal() 669 661 670 662 def set_selected_from_menu(self, menu, id): 671 663 """ 672 664 Set selected_plottable from context menu selection 673 665 674 666 :param menu: context menu item 675 667 :param id: menu item id … … 682 674 self.graph.selected_plottable = plot.id 683 675 break 684 676 685 677 def linear_plottable_fit(self, plot): 686 678 """ 687 679 when clicking on linear Fit on context menu, display Fitting Dialog 688 680 689 681 :param plot: PlotPanel owning the graph 690 682 691 683 """ 692 684 from fitDialog import LinearFit … … 694 686 return 695 687 self._fit_dialog = LinearFit(None, plot, self.onFitDisplay, 696 697 # Set the zoom area 688 self.returnTrans, -1, 'Linear Fit') 689 # Set the zoom area 698 690 if self._scale_xhi is not None and self._scale_xlo is not None: 699 691 self._fit_dialog.set_fit_region(self._scale_xlo, self._scale_xhi) … … 708 700 """ 709 701 self._fit_dialog = None 710 702 711 703 def _onProperties(self, event): 712 704 """ … … 719 711 self._fit_dialog.Destroy() 720 712 self._fit_dialog = None 721 list = [] 722 list = self.graph.returnPlottable() 723 if len(list.keys()) > 0: 724 first_item = list.keys()[0] 713 plot_list = self.graph.returnPlottable() 714 if len(plot_list.keys()) > 0: 715 first_item = plot_list.keys()[0] 725 716 if first_item.x != []: 726 717 from PropertyDialog import Properties … … 751 742 self._onEVT_FUNC_PROPERTY() 752 743 dial.Destroy() 753 744 754 745 def set_yscale(self, scale='linear'): 755 746 """ 756 747 Set the scale on Y-axis 757 748 758 749 :param scale: the scale of y-axis 759 750 760 751 """ 761 752 self.subplot.set_yscale(scale, nonposy='clip') 762 753 self.yscale = scale 763 754 764 755 def get_yscale(self): 765 756 """ 766 757 767 758 :return: Y-axis scale 768 759 769 760 """ 770 761 return self.yscale 771 762 772 763 def set_xscale(self, scale='linear'): 773 764 """ 774 765 Set the scale on x-axis 775 766 776 767 :param scale: the scale of x-axis 777 768 778 769 """ 779 770 self.subplot.set_xscale(scale) 780 771 self.xscale = scale 781 772 782 773 def get_xscale(self): 783 774 """ 784 775 785 776 :return: x-axis scale 786 777 787 778 """ 788 779 return self.xscale … … 791 782 """ 792 783 Set figure and canvas colours to be the same 793 784 794 785 """ 795 786 if not rgbtuple: 796 787 rgbtuple = wx.SystemSettings.GetColour(wx.SYS_COLOUR_BTNFACE).Get() 797 col = [c /255.0 for c in rgbtuple]788 col = [c / 255.0 for c in rgbtuple] 798 789 self.figure.set_facecolor(col) 799 790 self.figure.set_edgecolor(self.color) … … 817 808 This method can be called to force the Plot to be a desired size, 818 809 which defaults to the ClientSize of the panel 819 810 820 811 """ 821 812 if not pixels: … … 828 819 """ 829 820 Where the actual drawing happens 830 821 831 822 """ 832 823 self.figure.canvas.draw_idle() 833 824 834 825 def legend_picker(self, legend, event): 835 826 """ … … 837 828 """ 838 829 return self.legend.legendPatch.contains(event) 839 830 840 831 def get_loc_label(self): 841 832 """ … … 866 857 _labels['center'] = i 867 858 return _labels 868 859 869 860 def onSaveImage(self, evt): 870 861 """ … … 872 863 """ 873 864 self.toolbar.save(evt) 874 865 875 866 def onContextMenu(self, event): 876 867 """ 877 868 Default context menu for a plot panel 878 869 879 870 """ 880 871 # Slicer plot popup menu … … 883 874 slicerpop.Append(id, '&Save image', 'Save image as PNG') 884 875 wx.EVT_MENU(self, id, self.onSaveImage) 885 876 886 877 id = wx.NewId() 887 878 slicerpop.Append(id, '&Printer setup', 'Set image size') 888 879 wx.EVT_MENU(self, id, self.onPrinterSetup) 889 880 890 881 id = wx.NewId() 891 882 slicerpop.Append(id, '&Printer Preview', 'Set image size') 892 883 wx.EVT_MENU(self, id, self.onPrinterPreview) 893 884 894 885 id = wx.NewId() 895 886 slicerpop.Append(id, '&Print image', 'Print image ') 896 887 wx.EVT_MENU(self, id, self.onPrint) 897 888 898 889 id = wx.NewId() 899 890 slicerpop.Append(id, '&Copy', 'Copy to the clipboard') … … 903 894 #slicerpop.Append(id, '&Load 1D data file') 904 895 #wx.EVT_MENU(self, id, self._onLoad1DData) 905 896 906 897 id = wx.NewId() 907 898 slicerpop.AppendSeparator() 908 899 slicerpop.Append(id, '&Properties') 909 900 wx.EVT_MENU(self, id, self._onProperties) 910 901 911 902 id = wx.NewId() 912 903 slicerpop.AppendSeparator() 913 904 slicerpop.Append(id, '&Linear Fit') 914 905 wx.EVT_MENU(self, id, self.onFitting) 915 906 916 907 id = wx.NewId() 917 908 slicerpop.AppendSeparator() 918 909 slicerpop.Append(id, '&Toggle Legend On/Off', 'Toggle Legend On/Off') 919 910 wx.EVT_MENU(self, id, self.onLegend) 920 911 921 912 loc_menu = wx.Menu() 922 913 for label in self._loc_labels: … … 926 917 id = wx.NewId() 927 918 slicerpop.AppendMenu(id, '&Modify Legend Location', loc_menu) 928 919 929 920 id = wx.NewId() 930 921 slicerpop.Append(id, '&Modify Y Axis Label') … … 933 924 slicerpop.Append(id, '&Modify X Axis Label') 934 925 wx.EVT_MENU(self, id, self._on_xaxis_label) 935 926 936 927 try: 937 928 # mouse event … … 942 933 pos_x, pos_y = self.toolbar.GetPositionTuple() 943 934 pos = (pos_x, pos_y + 5) 944 935 945 936 self.PopupMenu(slicerpop, pos) 946 937 947 938 def onToolContextMenu(self, event): 948 939 """ 949 940 ContextMenu from toolbar 950 941 951 942 :param event: toolbar event 952 943 """ … … 955 946 if self.graph.selected_plottable != None: 956 947 self.graph.selected_plottable = None 957 948 958 949 self.onContextMenu(event) 959 950 960 951 # modified kieranrcampbell ILL june2012 961 def onLegend(self, legOnOff):952 def onLegend(self, legOnOff): 962 953 """ 963 954 Toggles whether legend is visible/not visible … … 975 966 self.line_collections_list = handles2 976 967 self.legend = self.subplot.legend(handles2, labels2, 977 prop=FontProperties(size=10),978 loc=self.legendLoc)968 prop=FontProperties(size=10), 969 loc=self.legendLoc) 979 970 if self.legend != None: 980 971 self.legend.set_picker(self.legend_picker) 981 972 self.legend.set_axes(self.subplot) 982 973 self.legend.set_zorder(20) 983 974 984 975 self.subplot.figure.canvas.draw_idle() 985 976 … … 989 980 """ 990 981 menu = event.GetEventObject() 991 id = event.GetId() 992 label = menu.GetLabel(id) 982 label = menu.GetLabel(event.GetId()) 993 983 self.ChangeLegendLoc(label) 994 984 … … 1006 996 self.line_collections_list = handles2 1007 997 self.legend = self.subplot.legend(handles2, labels2, 1008 prop=FontProperties(size=10),1009 loc=self.legendLoc)998 prop=FontProperties(size=10), 999 loc=self.legendLoc) 1010 1000 if self.legend != None: 1011 1001 self.legend.set_picker(self.legend_picker) … … 1022 1012 ax = gca() 1023 1013 ax.legend_ = None 1024 1014 1025 1015 def _on_addtext(self, event): 1026 1016 """ … … 1049 1039 if len(label) > 0 and xpos > 0 and ypos > 0: 1050 1040 new_text = self.subplot.text(str(xpos), str(ypos), label, 1051 1052 1041 fontproperties=font, 1042 color=colour) 1053 1043 self.textList.append(new_text) 1054 1044 self.subplot.figure.canvas.draw_idle() 1055 1045 except: 1056 1046 if self.parent != None: 1057 from sas.guiframe.events import StatusEvent1058 1047 msg = "Add Text: Error. Check your property values..." 1059 wx.PostEvent(self.parent, StatusEvent(status = msg))1048 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1060 1049 else: 1061 1050 raise … … 1065 1054 #based on this and plot it at user designated coordinates 1066 1055 1067 def onGridOnOff(self, gridon_off):1056 def onGridOnOff(self, gridon_off): 1068 1057 """ 1069 1058 Allows ON/OFF Grid … … 1072 1061 1073 1062 self.subplot.figure.canvas.draw_idle() 1074 1063 1075 1064 def _on_xaxis_label(self, event): 1076 1065 """ 1077 1066 Allows you to add text to the plot 1078 1067 """ 1079 xaxis_label, xaxis_unit, xaxis_font, xaxis_color, \1068 xaxis_label, xaxis_unit, xaxis_font, xaxis_color, \ 1080 1069 is_ok, is_tick = self._on_axis_label(axis='x') 1081 1070 if not is_ok: 1082 1071 return 1083 1072 1084 1073 self.xaxis_label = xaxis_label 1085 1074 self.xaxis_unit = xaxis_unit … … 1088 1077 if is_tick: 1089 1078 self.xaxis_tick = xaxis_font 1090 1079 1091 1080 if self.data != None: 1092 1081 # 2D 1093 self.xaxis(self.xaxis_label, self.xaxis_unit, \1082 self.xaxis(self.xaxis_label, self.xaxis_unit, \ 1094 1083 self.xaxis_font, self.xaxis_color, self.xaxis_tick) 1095 1084 self.subplot.figure.canvas.draw_idle() … … 1097 1086 # 1D 1098 1087 self._check_zoom_plot() 1099 1088 1100 1089 def _check_zoom_plot(self): 1101 1090 """ … … 1119 1108 def is_zoomed(self, value): 1120 1109 self._is_zoomed = value 1121 1110 1122 1111 def _on_yaxis_label(self, event): 1123 1112 """ 1124 1113 Allows you to add text to the plot 1125 1114 """ 1126 yaxis_label, yaxis_unit, yaxis_font, yaxis_color, \1115 yaxis_label, yaxis_unit, yaxis_font, yaxis_color, \ 1127 1116 is_ok, is_tick = self._on_axis_label(axis='y') 1128 1117 if not is_ok: … … 1138 1127 if self.data != None: 1139 1128 # 2D 1140 self.yaxis(self.yaxis_label, self.yaxis_unit, \1129 self.yaxis(self.yaxis_label, self.yaxis_unit, \ 1141 1130 self.yaxis_font, self.yaxis_color, self.yaxis_tick) 1142 1131 self.subplot.figure.canvas.draw_idle() … … 1144 1133 # 1D 1145 1134 self._check_zoom_plot() 1146 1135 1147 1136 def _on_axis_label(self, axis='x'): 1148 1137 """ 1149 1138 Modify axes labels 1150 1139 1151 1140 :param axis: x or y axis [string] 1152 1141 """ … … 1176 1165 if label_temp.count("\%s" % "\\") > 0: 1177 1166 if self.parent != None: 1178 from sas.guiframe.events import StatusEvent1179 1167 msg = "Add Label: Error. Can not use double '\\' " 1180 1168 msg += "characters..." … … 1184 1172 except: 1185 1173 if self.parent != None: 1186 from sas.guiframe.events import StatusEvent1187 1174 msg = "Add Label: Error. Check your property values..." 1188 1175 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1194 1181 textdial.Destroy() 1195 1182 return label, unit, font, colour, is_ok, is_tick 1196 1183 1197 1184 def _on_removetext(self, event): 1198 1185 """ … … 1203 1190 if num_text < 1: 1204 1191 if self.parent != None: 1205 from sas.guiframe.events import StatusEvent 1206 msg= "Remove Text: Nothing to remove. " 1192 msg = "Remove Text: Nothing to remove. " 1207 1193 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1208 1194 else: 1209 1195 raise 1210 1196 return 1211 txt = self.textList[num_text -1]1197 txt = self.textList[num_text - 1] 1212 1198 try: 1213 1199 text_remove = txt.get_text() 1214 1200 txt.remove() 1215 1201 if self.parent != None: 1216 from sas.guiframe.events import StatusEvent 1217 msg= "Removed Text: '%s'. " % text_remove 1202 msg = "Removed Text: '%s'. " % text_remove 1218 1203 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1219 1204 except: 1220 1205 if self.parent != None: 1221 from sas.guiframe.events import StatusEvent 1222 msg= "Remove Text: Error occurred. " 1206 msg = "Remove Text: Error occurred. " 1223 1207 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1224 1208 else: 1225 1209 raise 1226 1210 self.textList.remove(txt) 1227 1211 1228 1212 self.subplot.figure.canvas.draw_idle() 1229 1213 … … 1232 1216 Set some properties of the graph. 1233 1217 The set of properties is not yet determined. 1234 1218 1235 1219 """ 1236 1220 # The particulars of how they are stored and manipulated (e.g., do … … 1252 1236 self.subplot.clear() 1253 1237 self.subplot.hold(True) 1254 1238 1255 1239 def render(self): 1256 1240 """Commit the plot after all objects are drawn""" … … 1267 1251 self.line_collections_list = handles2 1268 1252 self.legend = ax.legend(handles2, labels2, 1269 prop=FontProperties(size=10),1270 loc=self.legendLoc)1253 prop=FontProperties(size=10), 1254 loc=self.legendLoc) 1271 1255 if self.legend != None: 1272 1256 self.legend.set_picker(self.legend_picker) 1273 1257 self.legend.set_axes(self.subplot) 1274 1258 self.legend.set_zorder(20) 1275 1259 1276 1260 except: 1277 1261 self.legend = ax.legend(prop=FontProperties(size=10), 1278 1262 loc=self.legendLoc) 1279 1263 1280 1264 def xaxis(self, label, units, font=None, color='black', t_font=None): 1281 1265 """xaxis label and units. 1282 1266 1283 1267 Axis labels know about units. 1284 1268 1285 1269 We need to do this so that we can detect when axes are not 1286 1270 commesurate. Currently this is ignored other than for formatting 1287 1271 purposes. 1288 1272 1289 1273 """ 1290 1274 … … 1307 1291 self.subplot.set_xlabel(label, color=color) 1308 1292 pass 1309 1293 1310 1294 def yaxis(self, label, units, font=None, color='black', t_font=None): 1311 1295 """yaxis label and units.""" … … 1337 1321 1338 1322 def interactive_points(self, x, y, dx=None, dy=None, name='', color=0, 1339 symbol=0, markersize=5, zorder=1, id=None, 1323 symbol=0, markersize=5, zorder=1, id=None, 1340 1324 label=None, hide_error=False): 1341 1325 """Draw markers with error bars""" … … 1348 1332 if p.markersize != None: 1349 1333 markersize = p.markersize 1350 p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, 1334 p.points(x, y, dx=dx, dy=dy, color=color, symbol=symbol, zorder=zorder, 1351 1335 markersize=markersize, label=label, hide_error=hide_error) 1352 1336 1353 1337 self.subplot.set_yscale(self.yscale, nonposy='clip') 1354 1338 self.subplot.set_xscale(self.xscale) 1355 1339 1356 1340 def interactive_curve(self, x, y, dy=None, name='', color=0, 1357 1341 symbol=0, zorder=1, id=None, label=None): … … 1364 1348 p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 1365 1349 p.curve(x, y, dy=dy, color=color, symbol=symbol, zorder=zorder, 1366 1367 1350 label=label) 1351 1368 1352 self.subplot.set_yscale(self.yscale, nonposy='clip') 1369 1353 self.subplot.set_xscale(self.xscale) 1370 1354 1371 1355 def plottable_selected(self, id): 1372 1356 """ … … 1380 1364 id=None, hide_error=False): 1381 1365 """Draw markers with error bars""" 1382 1366 1383 1367 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 1384 1368 if dx != None and type(dx) == type(()): 1385 dx = nx.vstack((x -dx[0], dx[1]-x)).transpose()1369 dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 1386 1370 if dy != None and type(dy) == type(()): 1387 dy = nx.vstack((y -dy[0], dy[1]-y)).transpose()1371 dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 1388 1372 if dx == None and dy == None: 1389 h = self.subplot.plot(x, y, color=self._color(color), 1390 marker=self._symbol(symbol), markersize=marker_size, 1391 linestyle='', 1392 label=label) 1373 self.subplot.plot(x, y, color=self._color(color), 1374 marker=self._symbol(symbol), 1375 markersize=marker_size, 1376 linestyle='', 1377 label=label) 1393 1378 else: 1394 1379 col = self._color(color) 1395 1380 if hide_error: 1396 h = self.subplot.plot(x, y, color=col, 1397 marker=self._symbol(symbol), 1398 markersize=marker_size, 1399 linestyle='', 1400 label=label) 1401 else: 1402 h = self.subplot.errorbar(x, y, yerr=dy, xerr=None, 1403 ecolor=col, capsize=2, linestyle='', 1404 barsabove=False, 1405 mec=col, mfc=col, 1381 self.subplot.plot(x, y, color=col, 1406 1382 marker=self._symbol(symbol), 1407 1383 markersize=marker_size, 1408 lolims=False, uplims=False, 1409 xlolims=False, xuplims=False, label=label) 1410 1384 linestyle='', 1385 label=label) 1386 else: 1387 self.subplot.errorbar(x, y, yerr=dy, xerr=None, 1388 ecolor=col, capsize=2, linestyle='', 1389 barsabove=False, 1390 mec=col, mfc=col, 1391 marker=self._symbol(symbol), 1392 markersize=marker_size, 1393 lolims=False, uplims=False, 1394 xlolims=False, xuplims=False, label=label) 1395 1411 1396 self.subplot.set_yscale(self.yscale, nonposy='clip') 1412 1397 self.subplot.set_xscale(self.xscale) 1413 1398 1414 1399 def _onToggleScale(self, event): 1415 1400 """ 1416 1401 toggle axis and replot image 1417 1402 1418 1403 """ 1419 1404 zmin_2D_temp = self.zmin_2D … … 1435 1420 if not self.zmax_2D is None: 1436 1421 zmax_2D_temp = math.log10(self.zmax_2D) 1437 1422 1438 1423 self.image(data=self.data, qx_data=self.qx_data, 1439 1424 qy_data=self.qy_data, xmin=self.xmin_2D, … … 1442 1427 cmap=self.cmap, zmin=zmin_2D_temp, 1443 1428 zmax=zmax_2D_temp) 1444 1429 1445 1430 def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, 1446 1431 zmin, zmax, color=0, symbol=0, markersize=0, … … 1448 1433 """ 1449 1434 Render the current data 1450 1435 1451 1436 """ 1452 1437 self.data = data … … 1472 1457 if self.zmin_2D <= 0 and len(output[output > 0]) > 0: 1473 1458 zmin_temp = self.zmin_2D 1474 output[output >0] = numpy.log10(output[output>0])1459 output[output > 0] = numpy.log10(output[output > 0]) 1475 1460 #In log scale Negative values are not correct in general 1476 1461 #output[output<=0] = math.log(numpy.min(output[output>0])) 1477 1462 elif self.zmin_2D <= 0: 1478 1463 zmin_temp = self.zmin_2D 1479 output[output >0] = numpy.zeros(len(output))1480 output[output <=0] = -321481 else: 1464 output[output > 0] = numpy.zeros(len(output)) 1465 output[output <= 0] = -32 1466 else: 1482 1467 zmin_temp = self.zmin_2D 1483 output[output >0] = numpy.log10(output[output>0])1468 output[output > 0] = numpy.log10(output[output > 0]) 1484 1469 #In log scale Negative values are not correct in general 1485 1470 #output[output<=0] = math.log(numpy.min(output[output>0])) … … 1487 1472 #Too many problems in 2D plot with scale 1488 1473 pass 1489 1474 1490 1475 else: 1491 1476 zmin_temp = self.zmin_2D … … 1494 1479 #Re-adjust colorbar 1495 1480 self.subplot.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 1496 1481 1497 1482 im = self.subplot.imshow(output, interpolation='nearest', 1498 1483 origin='lower', … … 1500 1485 cmap=self.cmap, 1501 1486 extent=(self.xmin_2D, self.xmax_2D, 1502 1503 1504 cbax = self.subplot.figure.add_axes([0.84, 0.2,0.02,0.7])1487 self.ymin_2D, self.ymax_2D)) 1488 1489 cbax = self.subplot.figure.add_axes([0.84, 0.2, 0.02, 0.7]) 1505 1490 else: 1506 1491 # clear the previous 2D from memory … … 1513 1498 Y = self.y_bins[0:-1] 1514 1499 X, Y = numpy.meshgrid(X, Y) 1515 1500 1516 1501 try: 1517 1502 # mpl >= 1.0.0 1518 1503 ax = self.subplot.figure.gca(projection='3d') 1519 1504 #ax.disable_mouse_rotation() 1520 cbax = self.subplot.figure.add_axes([0.84, 0.1,0.02,0.8])1505 cbax = self.subplot.figure.add_axes([0.84, 0.1, 0.02, 0.8]) 1521 1506 if len(X) > 60: 1522 1507 ax.disable_mouse_rotation() … … 1534 1519 self.subplot.figure.canvas.resizing = False 1535 1520 im = ax.plot_surface(X, Y, output, rstride=1, cstride=1, cmap=cmap, 1536 1521 linewidth=0, antialiased=False) 1537 1522 self.subplot.set_axis_off() 1538 1523 1539 1524 if cbax == None: 1540 1525 ax.set_frame_on(False) … … 1548 1533 else: 1549 1534 self.figure.canvas.draw() 1550 1535 1551 1536 def _build_matrix(self): 1552 1537 """ … … 1556 1541 self.data, self.qx_data, and self.qy_data 1557 1542 where each one corresponds to z, x, or y axis values 1558 1543 1559 1544 """ 1560 1545 # No qx or qy given in a vector format … … 1563 1548 # do we need deepcopy here? 1564 1549 return copy.deepcopy(self.data) 1565 1550 1566 1551 # maximum # of loops to fillup_pixels 1567 1552 # otherwise, loop could never stop depending on data … … 1570 1555 self._get_bins() 1571 1556 # set zero to None 1572 1557 1573 1558 #Note: Can not use scipy.interpolate.Rbf: 1574 1559 # 'cause too many data points (>10000)<=JHC. … … 1580 1565 weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1581 1566 y=self.qx_data, 1582 bins=[self.y_bins, self.x_bins],1583 weights=weights_data)1567 bins=[self.y_bins, self.x_bins], 1568 weights=weights_data) 1584 1569 # get histogram of data, all points into a bin in a way of summing 1585 1570 image, xedges, yedges = numpy.histogram2d(x=self.qy_data, 1586 1571 y=self.qx_data, 1587 bins=[self.y_bins, self.x_bins],1588 weights=self.data)1572 bins=[self.y_bins, self.x_bins], 1573 weights=self.data) 1589 1574 # Now, normalize the image by weights only for weights>1: 1590 1575 # If weight == 1, there is only one data point in the bin so 1591 1576 # that no normalization is required. 1592 image[weights > 1] = image[weights >1]/weights[weights>1]1577 image[weights > 1] = image[weights > 1] / weights[weights > 1] 1593 1578 # Set image bins w/o a data point (weight==0) as None (was set to zero 1594 1579 # by histogram2d.) … … 1598 1583 #one None point exists 1599 1584 loop = 0 1600 1585 1601 1586 # do while loop until all vacant bins are filled up up 1602 1587 #to loop = max_loop 1603 while (not(numpy.isfinite(image[weights == 0])).all()):1588 while not(numpy.isfinite(image[weights == 0])).all(): 1604 1589 if loop >= max_loop: # this protects never-ending loop 1605 1590 break 1606 1591 image = self._fillup_pixels(image=image, weights=weights) 1607 1592 loop += 1 1608 1593 1609 1594 return image 1610 1595 1611 1596 def _get_bins(self): 1612 1597 """ … … 1623 1608 # do we need deepcopy here? 1624 1609 return copy.deepcopy(self.data) 1625 1610 1626 1611 # find max and min values of qx and qy 1627 1612 xmax = self.qx_data.max() … … 1629 1614 ymax = self.qy_data.max() 1630 1615 ymin = self.qy_data.min() 1631 1616 1632 1617 # calculate the range of qx and qy: this way, it is a little 1633 1618 # more independent 1634 1619 x_size = xmax - xmin 1635 1620 y_size = ymax - ymin 1636 1621 1637 1622 # estimate the # of pixels on each axes 1638 1623 npix_y = int(math.floor(math.sqrt(len(self.qy_data)))) … … 1648 1633 ymax = ymax + ystep / 2.0 1649 1634 ymin = ymin - ystep / 2.0 1650 1635 1651 1636 # store x and y bin centers in q space 1652 1637 x_bins = numpy.linspace(xmin, xmax, npix_x) 1653 1638 y_bins = numpy.linspace(ymin, ymax, npix_y) 1654 #x_bins = numpy.arange(xmin, xmax + xstep / 10.0, xstep) 1655 #y_bins = numpy.arange(ymin, ymax + ystep / 10.0, ystep) 1656 1639 1657 1640 #set x_bins and y_bins 1658 1641 self.x_bins = x_bins … … 1663 1646 Fill z values of the empty cells of 2d image matrix 1664 1647 with the average over up-to next nearest neighbor points 1665 1648 1666 1649 :param image: (2d matrix with some zi = None) 1667 1650 1668 1651 :return: image (2d array ) 1669 1652 1670 1653 :TODO: Find better way to do for-loop below 1671 1654 1672 1655 """ 1673 1656 # No image matrix given … … 1690 1673 # find 4 nearest neighbors 1691 1674 # check where or not it is at the corner 1692 if n_y != 0 and numpy.isfinite(image[n_y -1][n_x]):1693 temp_image[n_y][n_x] += image[n_y -1][n_x]1675 if n_y != 0 and numpy.isfinite(image[n_y - 1][n_x]): 1676 temp_image[n_y][n_x] += image[n_y - 1][n_x] 1694 1677 weit[n_y][n_x] += 1 1695 if n_x != 0 and numpy.isfinite(image[n_y][n_x -1]):1696 temp_image[n_y][n_x] += image[n_y][n_x -1]1678 if n_x != 0 and numpy.isfinite(image[n_y][n_x - 1]): 1679 temp_image[n_y][n_x] += image[n_y][n_x - 1] 1697 1680 weit[n_y][n_x] += 1 1698 if n_y != len_y - 1 and numpy.isfinite(image[n_y+1][n_x]):1699 temp_image[n_y][n_x] += image[n_y +1][n_x]1681 if n_y != len_y - 1 and numpy.isfinite(image[n_y + 1][n_x]): 1682 temp_image[n_y][n_x] += image[n_y + 1][n_x] 1700 1683 weit[n_y][n_x] += 1 1701 if n_x != len_x - 1 and numpy.isfinite(image[n_y][n_x+1]):1702 temp_image[n_y][n_x] += image[n_y][n_x +1]1684 if n_x != len_x - 1 and numpy.isfinite(image[n_y][n_x + 1]): 1685 temp_image[n_y][n_x] += image[n_y][n_x + 1] 1703 1686 weit[n_y][n_x] += 1 1704 1687 # go 4 next nearest neighbors when no non-zero 1705 1688 # neighbor exists 1706 1689 if n_y != 0 and n_x != 0 and\ 1707 numpy.isfinite(image[n_y -1][n_x-1]):1708 temp_image[n_y][n_x] += image[n_y -1][n_x-1]1690 numpy.isfinite(image[n_y - 1][n_x - 1]): 1691 temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 1709 1692 weit[n_y][n_x] += 1 1710 if n_y != len_y - 1 and n_x != 0 and \1711 numpy.isfinite(image[n_y +1][n_x-1]):1712 temp_image[n_y][n_x] += image[n_y +1][n_x-1]1693 if n_y != len_y - 1 and n_x != 0 and \ 1694 numpy.isfinite(image[n_y + 1][n_x - 1]): 1695 temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 1713 1696 weit[n_y][n_x] += 1 1714 if n_y != len_y and n_x != len_x - 1 and \1715 numpy.isfinite(image[n_y -1][n_x+1]):1716 temp_image[n_y][n_x] += image[n_y -1][n_x+1]1697 if n_y != len_y and n_x != len_x - 1 and \ 1698 numpy.isfinite(image[n_y - 1][n_x + 1]): 1699 temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 1717 1700 weit[n_y][n_x] += 1 1718 if n_y != len_y - 1 and n_x != len_x -1 and \1719 numpy.isfinite(image[n_y +1][n_x+1]):1720 temp_image[n_y][n_x] += image[n_y +1][n_x+1]1701 if n_y != len_y - 1 and n_x != len_x - 1 and \ 1702 numpy.isfinite(image[n_y + 1][n_x + 1]): 1703 temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 1721 1704 weit[n_y][n_x] += 1 1722 1705 … … 1724 1707 ind = (weit > 0) 1725 1708 image[ind] = temp_image[ind] / weit[ind] 1726 1709 1727 1710 return image 1728 1711 1729 1712 def curve(self, x, y, dy=None, color=0, symbol=0, label=None): 1730 1713 """Draw a line on a graph, possibly with confidence intervals.""" … … 1732 1715 self.subplot.set_yscale('linear') 1733 1716 self.subplot.set_xscale('linear') 1734 1717 1735 1718 self.subplot.plot(x, y, color=c, marker='', 1736 1719 linestyle='-', label=label) … … 1745 1728 """Return a particular symbol""" 1746 1729 return self.symbollist[s % len(self.symbollist)] 1747 1730 1748 1731 def _replot(self, remove_fit=False): 1749 1732 """ 1750 1733 Rescale the plottables according to the latest 1751 1734 user selection and update the plot 1752 1735 1753 1736 :param remove_fit: Fit line will be removed if True 1754 1737 1755 1738 """ 1756 1739 self.graph.reset_scale() … … 1760 1743 self.graph.render(self) 1761 1744 self.subplot.figure.canvas.draw_idle() 1762 1745 1763 1746 def _onEVT_FUNC_PROPERTY(self, remove_fit=True, show=True): 1764 1747 """ … … 1771 1754 if remove_fit: 1772 1755 self.graph.delete(self.fit_result) 1773 self.ly = None 1774 self.q_ctrl = None 1775 list = [] 1756 self.ly = None 1757 self.q_ctrl = None 1776 1758 list = self.graph.returnPlottable() 1777 1759 # Changing the scale might be incompatible with … … 1786 1768 for item in list: 1787 1769 item.setLabel(self.xLabel, self.yLabel) 1788 1770 1789 1771 # control axis labels from the panel itself 1790 1772 yname, yunits = item.get_yaxis() … … 1803 1785 self.xaxis_unit = xunits 1804 1786 # Goes through all possible scales 1805 if (self.xLabel == "x"):1787 if self.xLabel == "x": 1806 1788 item.transformX(transform.toX, transform.errToX) 1807 1789 self.graph._xaxis_transformed("%s" % xname, "%s" % xunits) 1808 if (self.xLabel == "x^(2)"):1790 if self.xLabel == "x^(2)": 1809 1791 item.transformX(transform.toX2, transform.errToX2) 1810 1792 xunits = convertUnit(2, xunits) 1811 1793 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1812 if (self.xLabel == "x^(4)"):1794 if self.xLabel == "x^(4)": 1813 1795 item.transformX(transform.toX4, transform.errToX4) 1814 1796 xunits = convertUnit(4, xunits) 1815 1797 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1816 if (self.xLabel == "ln(x)"):1798 if self.xLabel == "ln(x)": 1817 1799 item.transformX(transform.toLogX, transform.errToLogX) 1818 1800 self.graph._xaxis_transformed("\ln\\ %s" % xname, "%s" % xunits) 1819 if (self.xLabel == "log10(x)"):1801 if self.xLabel == "log10(x)": 1820 1802 item.transformX(transform.toX_pos, transform.errToX_pos) 1821 1803 _xscale = 'log' 1822 1804 self.graph._xaxis_transformed("%s" % xname, "%s" % xunits) 1823 if (self.xLabel == "log10(x^(4))"):1805 if self.xLabel == "log10(x^(4))": 1824 1806 item.transformX(transform.toX4, transform.errToX4) 1825 1807 xunits = convertUnit(4, xunits) 1826 1808 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1827 1809 _xscale = 'log' 1828 if (self.yLabel == "ln(y)"):1810 if self.yLabel == "ln(y)": 1829 1811 item.transformY(transform.toLogX, transform.errToLogX) 1830 1812 self.graph._yaxis_transformed("\ln\\ %s" % yname, "%s" % yunits) 1831 if (self.yLabel == "y"):1813 if self.yLabel == "y": 1832 1814 item.transformY(transform.toX, transform.errToX) 1833 1815 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits) 1834 if (self.yLabel == "log10(y)"):1816 if self.yLabel == "log10(y)": 1835 1817 item.transformY(transform.toX_pos, transform.errToX_pos) 1836 1818 _yscale = 'log' 1837 1819 self.graph._yaxis_transformed("%s" % yname, "%s" % yunits) 1838 if (self.yLabel == "y^(2)"):1820 if self.yLabel == "y^(2)": 1839 1821 item.transformY(transform.toX2, transform.errToX2) 1840 1822 yunits = convertUnit(2, yunits) 1841 1823 self.graph._yaxis_transformed("%s^{2}" % yname, "%s" % yunits) 1842 if (self.yLabel == "1/y"):1824 if self.yLabel == "1/y": 1843 1825 item.transformY(transform.toOneOverX, transform.errOneOverX) 1844 1826 yunits = convertUnit(-1, yunits) 1845 1827 self.graph._yaxis_transformed("1/%s" % yname, "%s" % yunits) 1846 if (self.yLabel == "y*x^(4)"):1828 if self.yLabel == "y*x^(4)": 1847 1829 item.transformY(transform.toYX4, transform.errToYX4) 1848 1830 xunits = convertUnit(4, self.xaxis_unit) 1849 1831 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1850 1851 if (self.yLabel == "1/sqrt(y)"):1832 "%s%s" % (yunits, xunits)) 1833 if self.yLabel == "1/sqrt(y)": 1852 1834 item.transformY(transform.toOneOverSqrtX, 1853 1835 transform.errOneOverSqrtX) … … 1855 1837 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 1856 1838 "%s" % yunits) 1857 if (self.yLabel == "ln(y*x)"):1839 if self.yLabel == "ln(y*x)": 1858 1840 item.transformY(transform.toLogXY, transform.errToLogXY) 1859 1841 self.graph._yaxis_transformed("\ln (%s \ \ %s)" % (yname, xname), 1860 "%s%s" % (yunits, self.xaxis_unit))1861 if (self.yLabel == "ln(y*x^(2))"):1862 item.transformY( transform.toLogYX2, transform.errToLogYX2)1842 "%s%s" % (yunits, self.xaxis_unit)) 1843 if self.yLabel == "ln(y*x^(2))": 1844 item.transformY(transform.toLogYX2, transform.errToLogYX2) 1863 1845 xunits = convertUnit(2, self.xaxis_unit) 1864 1846 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 1865 1866 if (self.yLabel == "ln(y*x^(4))"):1847 "%s%s" % (yunits, xunits)) 1848 if self.yLabel == "ln(y*x^(4))": 1867 1849 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1868 1850 xunits = convertUnit(4, self.xaxis_unit) 1869 1851 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 1870 1871 if (self.yLabel == "log10(y*x^(4))"):1852 "%s%s" % (yunits, xunits)) 1853 if self.yLabel == "log10(y*x^(4))": 1872 1854 item.transformY(transform.toYX4, transform.errToYX4) 1873 1855 xunits = convertUnit(4, self.xaxis_unit) 1874 1856 _yscale = 'log' 1875 1857 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1876 1877 if (self.viewModel == "Guinier lny vs x^(2)"):1858 "%s%s" % (yunits, xunits)) 1859 if self.viewModel == "Guinier lny vs x^(2)": 1878 1860 item.transformX(transform.toX2, transform.errToX2) 1879 1861 xunits = convertUnit(2, xunits) 1880 1862 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1881 item.transformY(transform.toLogX, transform.errToLogX)1863 item.transformY(transform.toLogX, transform.errToLogX) 1882 1864 self.graph._yaxis_transformed("\ln\ \ %s" % yname, "%s" % yunits) 1883 if (self.viewModel == "Porod y*x^(4) vs x^(4)"):1865 if self.viewModel == "Porod y*x^(4) vs x^(4)": 1884 1866 item.transformX(transform.toX4, transform.errToX4) 1885 1867 xunits = convertUnit(4, self.xaxis_unit) … … 1887 1869 item.transformY(transform.toYX4, transform.errToYX4) 1888 1870 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1889 1871 "%s%s" % (yunits, xunits)) 1890 1872 item.transformView() 1891 1873 1892 1874 # set new label and units 1893 1875 yname = self.graph.prop["ylabel"] … … 1895 1877 xname = self.graph.prop["xlabel"] 1896 1878 xunits = '' 1897 1879 1898 1880 self.resetFitView() 1899 1881 self.prevXtrans = self.xLabel … … 1902 1884 self.set_xscale(_xscale) 1903 1885 self.set_yscale(_yscale) 1904 1886 1905 1887 self.xaxis(xname, xunits, self.xaxis_font, 1906 1888 self.xaxis_color, self.xaxis_tick) … … 1910 1892 if show: 1911 1893 self.subplot.figure.canvas.draw_idle() 1912 1894 1913 1895 def onFitDisplay(self, tempx, tempy, xminView, 1914 1896 xmaxView, xmin, xmax, func): … … 1916 1898 Add a new plottable into the graph .In this case this plottable 1917 1899 will be used to fit some data 1918 1900 1919 1901 :param tempx: The x data of fit line 1920 1902 :param tempy: The y data of fit line … … 1923 1905 :param xmin: the lowest value of data to fit to the line 1924 1906 :param xmax: the highest value of data to fit to the line 1925 1907 1926 1908 """ 1927 1909 # Saving value to redisplay in Fit Dialog when it is opened again … … 1964 1946 if dial.ShowModal() == wx.ID_OK: 1965 1947 new_caption = dial.getText() 1966 1948 1967 1949 # send to guiframe to change the panel caption 1968 1950 caption = self.parent.on_change_caption(self.window_name, 1969 1951 old_caption, new_caption) 1970 1952 1971 1953 # also set new caption in plot_panels list 1972 1954 self.parent.plot_panels[self.uid].window_caption = caption 1973 1955 # set new caption 1974 1956 self.window_caption = caption 1975 1957 1976 1958 dial.Destroy() 1977 1959 1978 1960 def onResetGraph(self, event): 1979 1961 """ … … 1988 1970 self.is_zoomed = False 1989 1971 self.toolbar.update() 1990 1972 1991 1973 def onPrinterSetup(self, event=None): 1992 1974 """ … … 2003 1985 except: 2004 1986 pass 2005 1987 2006 1988 def onPrint(self, event=None): 2007 1989 """ … … 2012 1994 except: 2013 1995 pass 2014 1996 2015 1997 def OnCopyFigureMenu(self, evt): 2016 1998 """ … … 2022 2004 print "Error in copy Image" 2023 2005 2024 2006 2025 2007 #--------------------------------------------------------------- 2026 2008 class NoRepaintCanvas(FigureCanvasWxAgg): … … 2029 2011 the draw method is only called for the first two paint events. After that, 2030 2012 the canvas will only be redrawn when it is resized. 2031 2013 2032 2014 """ 2033 2015 def __init__(self, *args, **kwargs): … … 2040 2022 """ 2041 2023 Called when wxPaintEvt is generated 2042 2024 2043 2025 """ 2044 2026 if not self._isRealized:
Note: See TracChangeset
for help on using the changeset viewer.