Changes in src/sas/sasgui/plottools/PlotPanel.py [75313af:9305b46] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/plottools/PlotPanel.py
r75313af r9305b46 6 6 import logging 7 7 import traceback 8 import math 9 import os 10 import operator 11 import copy 12 8 13 import wx 14 import numpy as np 15 9 16 # Try a normal import first 10 17 # If it fails, try specifying a version … … 15 22 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg 16 23 from matplotlib.figure import Figure 17 import os18 import transform19 #TODO: make the plottables interactive20 from binder import BindArtist21 24 from matplotlib.font_manager import FontProperties 22 DEBUG = False23 24 from plottables import Graph25 from TextDialog import TextDialog26 from LabelDialog import LabelDialog27 import operator28 29 import math30 25 import pylab 31 26 DEFAULT_CMAP = pylab.cm.jet 32 import copy33 import numpy as np34 27 35 28 from sas.sasgui.guiframe.events import StatusEvent 29 30 #TODO: make the plottables interactive 31 from . import transform 32 from .TextDialog import TextDialog 33 from .LabelDialog import LabelDialog 34 from .binder import BindArtist 35 from .convert_units import convert_unit 36 from .plottables import Graph 36 37 from .toolbar import NavigationToolBar, PlotPrintout, bind 37 38 39 DEBUG = False 38 40 logger = logging.getLogger(__name__) 39 41 … … 44 46 for a in obj.get_children(): show_tree(a, d + 1) 45 47 46 from convert_units import convert_unit47 48 48 49 … … 116 117 self.figure = Figure(None, dpi, linewidth=2.0) 117 118 self.color = '#b3b3b3' 118 from canvas import FigureCanvas119 from .canvas import FigureCanvas 119 120 self.canvas = FigureCanvas(self, -1, self.figure) 120 121 self.SetColor(color) … … 338 339 # On Windows platform, default window size is incorrect, so set 339 340 # toolbar width to figure width. 340 tw, th = self.toolbar.GetSize Tuple()341 fw, fh = self.canvas.GetSize Tuple()341 tw, th = self.toolbar.GetSize() 342 fw, fh = self.canvas.GetSize() 342 343 # By adding toolbar in sizer, we are able to put it at the bottom 343 344 # of the frame - so appearance is closer to GTK version. … … 438 439 y = hi_y 439 440 # Move the legend from its previous location by that same amount 440 loc_in_canvas = self.legend_x - mouse_diff_x, \441 self.legend_y - mouse_diff_y441 loc_in_canvas = (self.legend_x - mouse_diff_x, 442 self.legend_y - mouse_diff_y) 442 443 # Transform into legend coordinate system 443 444 trans_axes = self.legend.parent.transAxes.inverted() … … 629 630 Return values and labels used by Fit Dialog 630 631 """ 631 return self.xLabel, self.yLabel, self.Avalue, self.Bvalue, \632 self.ErrAvalue, self.ErrBvalue, self.Chivalue 632 return (self.xLabel, self.yLabel, self.Avalue, self.Bvalue, 633 self.ErrAvalue, self.ErrBvalue, self.Chivalue) 633 634 634 635 def setTrans(self, xtrans, ytrans): … … 657 658 else: 658 659 plot_dict = plotlist 659 from fitDialog import LinearFit660 from .fitDialog import LinearFit 660 661 661 662 if len(plot_dict.keys()) > 0: 662 first_item = plot_dict.keys()[0]663 first_item = list(plot_dict.keys())[0] 663 664 dlg = LinearFit(parent=None, plottable=first_item, 664 665 push_data=self.onFitDisplay, … … 666 667 title='Linear Fit') 667 668 668 if ( self.xmin != 0.0)and (self.xmax != 0.0)\669 and(self.xminView != 0.0)and (self.xmaxView != 0.0):669 if ((self.xmin != 0.0) and (self.xmax != 0.0) 670 and (self.xminView != 0.0) and (self.xmaxView != 0.0)): 670 671 dlg.setFitRange(self.xminView, self.xmaxView, 671 672 self.xmin, self.xmax) … … 703 704 704 705 """ 705 from fitDialog import LinearFit706 from .fitDialog import LinearFit 706 707 if self._fit_dialog is not None: 707 708 return … … 736 737 first_item = plot_list.keys()[0] 737 738 if first_item.x != []: 738 from PropertyDialog import Properties739 from .PropertyDialog import Properties 739 740 dial = Properties(self, -1, 'Properties') 740 741 dial.setValues(self.prevXtrans, self.prevYtrans, self.viewModel) … … 924 925 except: 925 926 # toolbar event 926 pos_x, pos_y = self.toolbar.GetPosition Tuple()927 pos_x, pos_y = self.toolbar.GetPosition() 927 928 pos = (pos_x, pos_y + 5) 928 929 … … 1001 1002 Remove legend for ax or the current axes. 1002 1003 """ 1003 from pylab import gca1004 1004 if ax is None: 1005 ax = gca()1005 ax = pylab.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, \1062 is_ok, is_tick= self._on_axis_label(axis='x')1061 xaxis_label, xaxis_unit, xaxis_font, xaxis_color, is_ok, is_tick \ 1062 = 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 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, \1109 is_ok, is_tick= self._on_axis_label(axis='y')1108 yaxis_label, yaxis_unit, yaxis_font, yaxis_color, is_ok, is_tick \ 1109 = 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 label_temp.count("\%s" % "\\") > 0: 1158 if r"\\" in label_temp: 1159 label = label_temp.replace(r"\\", r"??") 1159 1160 if self.parent is not None: 1160 msg = "Add Label: Error.Can not use double '\\' "1161 msg = r"Add Label error: Can not use double '\\' " 1161 1162 msg += "characters..." 1162 1163 wx.PostEvent(self.parent, StatusEvent(status=msg)) … … 1234 1235 # TODO: rather than redrawing on the fly. 1235 1236 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 None \1536 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 None \1596 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() \ 1648 or weights is None: 1646 if (image is None or np.ndim(image) != 2 1647 or np.isfinite(image).all() or weights is None): 1649 1648 return image 1650 1649 # Get bin size in y and x directions … … 1676 1675 # go 4 next nearest neighbors when no non-zero 1677 1676 # neighbor exists 1678 if n_y != 0 and n_x != 0 and \1679 np.isfinite(image[n_y - 1][n_x - 1]):1677 if (n_y != 0 and n_x != 0 1678 and np.isfinite(image[n_y - 1][n_x - 1])): 1680 1679 temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] 1681 1680 weit[n_y][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]):1681 if (n_y != len_y - 1 and n_x != 0 1682 and np.isfinite(image[n_y + 1][n_x - 1])): 1684 1683 temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] 1685 1684 weit[n_y][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]):1685 if (n_y != len_y and n_x != len_x - 1 1686 and np.isfinite(image[n_y - 1][n_x + 1])): 1688 1687 temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] 1689 1688 weit[n_y][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]):1689 if (n_y != len_y - 1 and n_x != len_x - 1 1690 and np.isfinite(image[n_y + 1][n_x + 1])): 1692 1691 temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] 1693 1692 weit[n_y][n_x] += 1 … … 1744 1743 self.graph.delete(self.fit_result) 1745 1744 if hasattr(self, 'plots'): 1746 if 'fit' in self.plots .keys():1745 if 'fit' in self.plots: 1747 1746 del self.plots['fit'] 1748 1747 self.ly = None … … 1784 1783 item.transformX(transform.toX2, transform.errToX2) 1785 1784 xunits = convert_unit(2, xunits) 1786 self.graph._xaxis_transformed("%s^ {2}" % xname, "%s" % xunits)1785 self.graph._xaxis_transformed("%s^2" % xname, "%s" % xunits) 1787 1786 if self.xLabel == "x^(4)": 1788 1787 item.transformX(transform.toX4, transform.errToX4) 1789 1788 xunits = convert_unit(4, xunits) 1790 self.graph._xaxis_transformed("%s^ {4}" % xname, "%s" % xunits)1789 self.graph._xaxis_transformed("%s^4" % xname, "%s" % xunits) 1791 1790 if self.xLabel == "ln(x)": 1792 1791 item.transformX(transform.toLogX, transform.errToLogX) 1793 self.graph._xaxis_transformed( "\ln{(%s)}" % xname, "%s" % xunits)1792 self.graph._xaxis_transformed(r"\ln(%s)" % xname, "%s" % xunits) 1794 1793 if self.xLabel == "log10(x)": 1795 1794 item.transformX(transform.toX_pos, transform.errToX_pos) … … 1799 1798 item.transformX(transform.toX4, transform.errToX4) 1800 1799 xunits = convert_unit(4, xunits) 1801 self.graph._xaxis_transformed("%s^ {4}" % xname, "%s" % xunits)1800 self.graph._xaxis_transformed("%s^4" % xname, "%s" % xunits) 1802 1801 _xscale = 'log' 1803 1802 if self.yLabel == "ln(y)": 1804 1803 item.transformY(transform.toLogX, transform.errToLogX) 1805 self.graph._yaxis_transformed( "\ln{(%s)}" % yname, "%s" % yunits)1804 self.graph._yaxis_transformed(r"\ln(%s)" % yname, "%s" % yunits) 1806 1805 if self.yLabel == "y": 1807 1806 item.transformY(transform.toX, transform.errToX) … … 1822 1821 item.transformY(transform.toYX2, transform.errToYX2) 1823 1822 xunits = convert_unit(2, self.xaxis_unit) 1824 self.graph._yaxis_transformed( "%s \ \ %s^{2}" % (yname, xname),1823 self.graph._yaxis_transformed(r"%s \ \ %s^2" % (yname, xname), 1825 1824 "%s%s" % (yunits, xunits)) 1826 1825 if self.yLabel == "y*x^(4)": 1827 1826 item.transformY(transform.toYX4, transform.errToYX4) 1828 1827 xunits = convert_unit(4, self.xaxis_unit) 1829 self.graph._yaxis_transformed( "%s \ \ %s^{4}" % (yname, xname),1828 self.graph._yaxis_transformed(r"%s \ \ %s^4" % (yname, xname), 1830 1829 "%s%s" % (yunits, xunits)) 1831 1830 if self.yLabel == "1/sqrt(y)": … … 1833 1832 transform.errOneOverSqrtX) 1834 1833 yunits = convert_unit(-0.5, yunits) 1835 self.graph._yaxis_transformed( "1/\sqrt{%s}" % yname,1834 self.graph._yaxis_transformed(r"1/\sqrt{%s}" % yname, 1836 1835 "%s" % yunits) 1837 1836 if self.yLabel == "ln(y*x)": 1838 1837 item.transformY(transform.toLogXY, transform.errToLogXY) 1839 self.graph._yaxis_transformed( "\ln{(%s \ \ %s)}" % (yname, xname),1838 self.graph._yaxis_transformed(r"\ln(%s \ \ %s)" % (yname, xname), 1840 1839 "%s%s" % (yunits, self.xaxis_unit)) 1841 1840 if self.yLabel == "ln(y*x^(2))": 1842 1841 item.transformY(transform.toLogYX2, transform.errToLogYX2) 1843 1842 xunits = convert_unit(2, self.xaxis_unit) 1844 self.graph._yaxis_transformed( "\ln (%s \ \ %s^{2})" % (yname, xname),1843 self.graph._yaxis_transformed(r"\ln(%s \ \ %s^2)" % (yname, xname), 1845 1844 "%s%s" % (yunits, xunits)) 1846 1845 if self.yLabel == "ln(y*x^(4))": 1847 1846 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1848 1847 xunits = convert_unit(4, self.xaxis_unit) 1849 self.graph._yaxis_transformed( "\ln (%s \ \ %s^{4})" % (yname, xname),1848 self.graph._yaxis_transformed(r"\ln(%s \ \ %s^4)" % (yname, xname), 1850 1849 "%s%s" % (yunits, xunits)) 1851 1850 if self.yLabel == "log10(y*x^(4))": … … 1853 1852 xunits = convert_unit(4, self.xaxis_unit) 1854 1853 _yscale = 'log' 1855 self.graph._yaxis_transformed( "%s \ \ %s^{4}" % (yname, xname),1854 self.graph._yaxis_transformed(r"%s \ \ %s^4" % (yname, xname), 1856 1855 "%s%s" % (yunits, xunits)) 1857 1856 item.transformView() … … 1897 1896 # Saving value to redisplay in Fit Dialog when it is opened again 1898 1897 self.Avalue, self.Bvalue, self.ErrAvalue, \ 1899 1898 self.ErrBvalue, self.Chivalue = func 1900 1899 self.xminView = xminView 1901 1900 self.xmaxView = xmaxView
Note: See TracChangeset
for help on using the changeset viewer.