Changes in src/sas/sasgui/plottools/PlotPanel.py [9305b46:75313af] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/plottools/PlotPanel.py
r9305b46 r75313af 6 6 import logging 7 7 import traceback 8 import math9 import os10 import operator11 import copy12 13 8 import wx 14 import numpy as np15 16 9 # Try a normal import first 17 10 # If it fails, try specifying a version … … 22 15 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 23 16 from matplotlib.figure import Figure 17 import os 18 import transform 19 #TODO: make the plottables interactive 20 from binder import BindArtist 24 21 from matplotlib.font_manager import FontProperties 22 DEBUG = False 23 24 from plottables import Graph 25 from TextDialog import TextDialog 26 from LabelDialog import LabelDialog 27 import operator 28 29 import math 25 30 import pylab 26 31 DEFAULT_CMAP = pylab.cm.jet 32 import copy 33 import numpy as np 27 34 28 35 from sas.sasgui.guiframe.events import StatusEvent 29 30 #TODO: make the plottables interactive31 from . import transform32 from .TextDialog import TextDialog33 from .LabelDialog import LabelDialog34 from .binder import BindArtist35 from .convert_units import convert_unit36 from .plottables import Graph37 36 from .toolbar import NavigationToolBar, PlotPrintout, bind 38 37 39 DEBUG = False40 38 logger = logging.getLogger(__name__) 41 39 … … 46 44 for a in obj.get_children(): show_tree(a, d + 1) 47 45 46 from convert_units import convert_unit 48 47 49 48 … … 117 116 self.figure = Figure(None, dpi, linewidth=2.0) 118 117 self.color = '#b3b3b3' 119 from .canvas import FigureCanvas118 from canvas import FigureCanvas 120 119 self.canvas = FigureCanvas(self, -1, self.figure) 121 120 self.SetColor(color) … … 339 338 # On Windows platform, default window size is incorrect, so set 340 339 # toolbar width to figure width. 341 tw, th = self.toolbar.GetSize ()342 fw, fh = self.canvas.GetSize ()340 tw, th = self.toolbar.GetSizeTuple() 341 fw, fh = self.canvas.GetSizeTuple() 343 342 # By adding toolbar in sizer, we are able to put it at the bottom 344 343 # of the frame - so appearance is closer to GTK version. … … 439 438 y = hi_y 440 439 # Move the legend from its previous location by that same amount 441 loc_in_canvas = (self.legend_x - mouse_diff_x,442 self.legend_y - mouse_diff_y)440 loc_in_canvas = self.legend_x - mouse_diff_x, \ 441 self.legend_y - mouse_diff_y 443 442 # Transform into legend coordinate system 444 443 trans_axes = self.legend.parent.transAxes.inverted() … … 630 629 Return values and labels used by Fit Dialog 631 630 """ 632 return (self.xLabel, self.yLabel, self.Avalue, self.Bvalue,633 self.ErrAvalue, self.ErrBvalue, self.Chivalue )631 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \ 632 self.ErrAvalue, self.ErrBvalue, self.Chivalue 634 633 635 634 def setTrans(self, xtrans, ytrans): … … 658 657 else: 659 658 plot_dict = plotlist 660 from .fitDialog import LinearFit659 from fitDialog import LinearFit 661 660 662 661 if len(plot_dict.keys()) > 0: 663 first_item = list(plot_dict.keys())[0]662 first_item = plot_dict.keys()[0] 664 663 dlg = LinearFit(parent=None, plottable=first_item, 665 664 push_data=self.onFitDisplay, … … 667 666 title='Linear Fit') 668 667 669 if ( (self.xmin != 0.0) and (self.xmax != 0.0)670 and (self.xminView != 0.0) and (self.xmaxView != 0.0)):668 if (self.xmin != 0.0)and (self.xmax != 0.0)\ 669 and(self.xminView != 0.0)and (self.xmaxView != 0.0): 671 670 dlg.setFitRange(self.xminView, self.xmaxView, 672 671 self.xmin, self.xmax) … … 704 703 705 704 """ 706 from .fitDialog import LinearFit705 from fitDialog import LinearFit 707 706 if self._fit_dialog is not None: 708 707 return … … 737 736 first_item = plot_list.keys()[0] 738 737 if first_item.x != []: 739 from .PropertyDialog import Properties738 from PropertyDialog import Properties 740 739 dial = Properties(self, -1, 'Properties') 741 740 dial.setValues(self.prevXtrans, self.prevYtrans, self.viewModel) … … 925 924 except: 926 925 # toolbar event 927 pos_x, pos_y = self.toolbar.GetPosition ()926 pos_x, pos_y = self.toolbar.GetPositionTuple() 928 927 pos = (pos_x, pos_y + 5) 929 928 … … 1002 1001 Remove legend for ax or the current axes. 1003 1002 """ 1003 from pylab import gca 1004 1004 if ax is None: 1005 ax = pylab.gca()1005 ax = gca() 1006 1006 ax.legend_ = None 1007 1007 … … 1059 1059 Allows you to add text to the plot 1060 1060 """ 1061 xaxis_label, xaxis_unit, xaxis_font, xaxis_color, is_ok, is_tick\1062 = self._on_axis_label(axis='x')1061 xaxis_label, xaxis_unit, xaxis_font, xaxis_color, \ 1062 is_ok, is_tick = self._on_axis_label(axis='x') 1063 1063 if not is_ok: 1064 1064 return … … 1073 1073 if self.data is not None: 1074 1074 # 2D 1075 self.xaxis(self.xaxis_label, self.xaxis_unit, 1076 self.xaxis_font, self.xaxis_color, self.xaxis_tick)1075 self.xaxis(self.xaxis_label, self.xaxis_unit, \ 1076 self.xaxis_font, self.xaxis_color, self.xaxis_tick) 1077 1077 self.subplot.figure.canvas.draw_idle() 1078 1078 else: … … 1106 1106 Allows you to add text to the plot 1107 1107 """ 1108 yaxis_label, yaxis_unit, yaxis_font, yaxis_color, is_ok, is_tick\1109 = self._on_axis_label(axis='y')1108 yaxis_label, yaxis_unit, yaxis_font, yaxis_color, \ 1109 is_ok, is_tick = self._on_axis_label(axis='y') 1110 1110 if not is_ok: 1111 1111 return … … 1120 1120 if self.data is not None: 1121 1121 # 2D 1122 self.yaxis(self.yaxis_label, self.yaxis_unit, 1122 self.yaxis(self.yaxis_label, self.yaxis_unit, \ 1123 1123 self.yaxis_font, self.yaxis_color, self.yaxis_tick) 1124 1124 self.subplot.figure.canvas.draw_idle() … … 1156 1156 is_tick = textdial.getTickLabel() 1157 1157 label_temp = textdial.getText() 1158 if r"\\" in label_temp: 1159 label = label_temp.replace(r"\\", r"??") 1158 if label_temp.count("\%s" % "\\") > 0: 1160 1159 if self.parent is not None: 1161 msg = r"Add Label error:Can not use double '\\' "1160 msg = "Add Label: Error. Can not use double '\\' " 1162 1161 msg += "characters..." 1163 1162 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1235 1234 # TODO: rather than redrawing on the fly. 1236 1235 self.subplot.clear() 1236 self.subplot.hold(True) 1237 1237 1238 1238 def render(self): … … 1327 1327 if id is None: 1328 1328 id = name 1329 from .plottable_interactor import PointInteractor1329 from plottable_interactor import PointInteractor 1330 1330 p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 1331 1331 if p.markersize is not None: … … 1344 1344 if id is None: 1345 1345 id = name 1346 from .plottable_interactor import PointInteractor1346 from plottable_interactor import PointInteractor 1347 1347 p = PointInteractor(self, self.subplot, zorder=zorder, id=id) 1348 1348 p.curve(x, y, dy=dy, color=color, symbol=symbol, zorder=zorder, … … 1533 1533 """ 1534 1534 # No qx or qy given in a vector format 1535 if (self.qx_data is None or self.qy_data is None1536 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1 ):1535 if self.qx_data is None or self.qy_data is None \ 1536 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1537 1537 # do we need deepcopy here? 1538 1538 return copy.deepcopy(self.data) … … 1593 1593 """ 1594 1594 # No qx or qy given in a vector format 1595 if (self.qx_data is None or self.qy_data is None1596 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1 ):1595 if self.qx_data is None or self.qy_data is None \ 1596 or self.qx_data.ndim != 1 or self.qy_data.ndim != 1: 1597 1597 # do we need deepcopy here? 1598 1598 return copy.deepcopy(self.data) … … 1644 1644 """ 1645 1645 # No image matrix given 1646 if (image is None or np.ndim(image) != 2 1647 or np.isfinite(image).all() or weights is None): 1646 if image is None or np.ndim(image) != 2 \ 1647 or np.isfinite(image).all() \ 1648 or weights is None: 1648 1649 return image 1649 1650 # Get bin size in y and x directions … … 1675 1676 # go 4 next nearest neighbors when no non-zero 1676 1677 # neighbor exists 1677 if (n_y != 0 and n_x != 01678 and np.isfinite(image[n_y - 1][n_x - 1])):1678 if n_y != 0 and n_x != 0 and \ 1679 np.isfinite(image[n_y - 1][n_x - 1]): 1679 1680 temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 1680 1681 weit[n_y][n_x] += 1 1681 if (n_y != len_y - 1 and n_x != 01682 and np.isfinite(image[n_y + 1][n_x - 1])):1682 if n_y != len_y - 1 and n_x != 0 and \ 1683 np.isfinite(image[n_y + 1][n_x - 1]): 1683 1684 temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 1684 1685 weit[n_y][n_x] += 1 1685 if (n_y != len_y and n_x != len_x - 11686 and np.isfinite(image[n_y - 1][n_x + 1])):1686 if n_y != len_y and n_x != len_x - 1 and \ 1687 np.isfinite(image[n_y - 1][n_x + 1]): 1687 1688 temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 1688 1689 weit[n_y][n_x] += 1 1689 if (n_y != len_y - 1 and n_x != len_x - 11690 and np.isfinite(image[n_y + 1][n_x + 1])):1690 if n_y != len_y - 1 and n_x != len_x - 1 and \ 1691 np.isfinite(image[n_y + 1][n_x + 1]): 1691 1692 temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 1692 1693 weit[n_y][n_x] += 1 … … 1743 1744 self.graph.delete(self.fit_result) 1744 1745 if hasattr(self, 'plots'): 1745 if 'fit' in self.plots :1746 if 'fit' in self.plots.keys(): 1746 1747 del self.plots['fit'] 1747 1748 self.ly = None … … 1783 1784 item.transformX(transform.toX2, transform.errToX2) 1784 1785 xunits = convert_unit(2, xunits) 1785 self.graph._xaxis_transformed("%s^ 2" % xname, "%s" % xunits)1786 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1786 1787 if self.xLabel == "x^(4)": 1787 1788 item.transformX(transform.toX4, transform.errToX4) 1788 1789 xunits = convert_unit(4, xunits) 1789 self.graph._xaxis_transformed("%s^ 4" % xname, "%s" % xunits)1790 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1790 1791 if self.xLabel == "ln(x)": 1791 1792 item.transformX(transform.toLogX, transform.errToLogX) 1792 self.graph._xaxis_transformed( r"\ln(%s)" % xname, "%s" % xunits)1793 self.graph._xaxis_transformed("\ln{(%s)}" % xname, "%s" % xunits) 1793 1794 if self.xLabel == "log10(x)": 1794 1795 item.transformX(transform.toX_pos, transform.errToX_pos) … … 1798 1799 item.transformX(transform.toX4, transform.errToX4) 1799 1800 xunits = convert_unit(4, xunits) 1800 self.graph._xaxis_transformed("%s^ 4" % xname, "%s" % xunits)1801 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1801 1802 _xscale = 'log' 1802 1803 if self.yLabel == "ln(y)": 1803 1804 item.transformY(transform.toLogX, transform.errToLogX) 1804 self.graph._yaxis_transformed( r"\ln(%s)" % yname, "%s" % yunits)1805 self.graph._yaxis_transformed("\ln{(%s)}" % yname, "%s" % yunits) 1805 1806 if self.yLabel == "y": 1806 1807 item.transformY(transform.toX, transform.errToX) … … 1821 1822 item.transformY(transform.toYX2, transform.errToYX2) 1822 1823 xunits = convert_unit(2, self.xaxis_unit) 1823 self.graph._yaxis_transformed( r"%s \ \ %s^2" % (yname, xname),1824 self.graph._yaxis_transformed("%s \ \ %s^{2}" % (yname, xname), 1824 1825 "%s%s" % (yunits, xunits)) 1825 1826 if self.yLabel == "y*x^(4)": 1826 1827 item.transformY(transform.toYX4, transform.errToYX4) 1827 1828 xunits = convert_unit(4, self.xaxis_unit) 1828 self.graph._yaxis_transformed( r"%s \ \ %s^4" % (yname, xname),1829 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1829 1830 "%s%s" % (yunits, xunits)) 1830 1831 if self.yLabel == "1/sqrt(y)": … … 1832 1833 transform.errOneOverSqrtX) 1833 1834 yunits = convert_unit(-0.5, yunits) 1834 self.graph._yaxis_transformed( r"1/\sqrt{%s}" % yname,1835 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 1835 1836 "%s" % yunits) 1836 1837 if self.yLabel == "ln(y*x)": 1837 1838 item.transformY(transform.toLogXY, transform.errToLogXY) 1838 self.graph._yaxis_transformed( r"\ln(%s \ \ %s)" % (yname, xname),1839 self.graph._yaxis_transformed("\ln{(%s \ \ %s)}" % (yname, xname), 1839 1840 "%s%s" % (yunits, self.xaxis_unit)) 1840 1841 if self.yLabel == "ln(y*x^(2))": 1841 1842 item.transformY(transform.toLogYX2, transform.errToLogYX2) 1842 1843 xunits = convert_unit(2, self.xaxis_unit) 1843 self.graph._yaxis_transformed( r"\ln(%s \ \ %s^2)" % (yname, xname),1844 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 1844 1845 "%s%s" % (yunits, xunits)) 1845 1846 if self.yLabel == "ln(y*x^(4))": 1846 1847 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1847 1848 xunits = convert_unit(4, self.xaxis_unit) 1848 self.graph._yaxis_transformed( r"\ln(%s \ \ %s^4)" % (yname, xname),1849 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 1849 1850 "%s%s" % (yunits, xunits)) 1850 1851 if self.yLabel == "log10(y*x^(4))": … … 1852 1853 xunits = convert_unit(4, self.xaxis_unit) 1853 1854 _yscale = 'log' 1854 self.graph._yaxis_transformed( r"%s \ \ %s^4" % (yname, xname),1855 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1855 1856 "%s%s" % (yunits, xunits)) 1856 1857 item.transformView() … … 1896 1897 # Saving value to redisplay in Fit Dialog when it is opened again 1897 1898 self.Avalue, self.Bvalue, self.ErrAvalue, \ 1898 self.ErrBvalue, self.Chivalue = func1899 self.ErrBvalue, self.Chivalue = func 1899 1900 self.xminView = xminView 1900 1901 self.xmaxView = xmaxView
Note: See TracChangeset
for help on using the changeset viewer.