Changeset 8628:08cc79435200 in orange


Ignore:
Timestamp:
08/07/11 19:03:24 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
8445fff49c08bd4d798e3254e006381e193c49b9
Message:

Add more documentation for the plot module.

Location:
orange/OrangeWidgets/plot
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/plot/owcurve.py

    r8626 r8628  
    1010    .. method:: attach(plot) 
    1111     
    12         Attaches this item to ``plot``.  
     12        Attaches this item to ``plot``. The Plot takes the ownership of this item.  
    1313     
    1414        :param plot: the plot to which to add this item 
     
    1919    .. method:: detach() 
    2020         
    21         Remove this item from its plot 
     21        Removes this item from its plot. The item's ownership is returned to Python.  
     22         
     23    .. method:: plot() 
     24     
     25        :returns: The plot this item is attached to. If the item is not attached to any plot, ``None`` is returned.  
     26        :rtype: :obj:`.OWPlot` 
    2227         
    2328    .. method:: data_rect() 
     
    2934        :param rect: The new bounding rectangle in data coordinates 
    3035        :type rect: :obj:`.QRectF` 
    31  
     36         
     37    .. method:: set_graph_transform(transform) 
     38     
     39        Sets the graph transform (the transformation that maps from data to plot coordinates) for this item. 
     40         
     41    .. method:: graph_transform() 
     42     
     43        :returns: The current graph transformation. 
     44        :rtype: QTransform 
     45         
     46    .. method:: set_zoom_transform(transform) 
     47     
     48        Sets the zoom transform (the transformation that maps from plot to scene coordinates) for this item. 
     49         
     50    .. method:: zoom_transform() 
     51     
     52        :returns: The current zoom transformation. 
     53        :rtype: QTransform 
     54         
     55    .. method:: set_axes(x_axis, y_axis) 
     56     
     57        Sets the pair of axes used for positioning this item.  
     58         
     59    .. method:: axes() 
     60         
     61        :returns: The item's pair of axes 
     62        :rtype: tuple of int int 
     63         
     64    .. method:: update_properties() 
     65     
     66        Called by the plot, this function is supposed to updates the item's internal state to match its settings.  
     67         
     68        The default implementation does nothing and shold be reimplemented by subclasses.  
     69         
     70    .. method:: register_points() 
     71         
     72        If this item constains any points (of type :obj:`OWPoint`), add them to the plot in this function. 
     73         
     74        The default implementation does nothing.  
     75         
     76    .. method:: set_in_background(background) 
     77     
     78        If ``background`` is ``True``, the item is moved to be background of this plot, behind other items and axes.  
     79        Otherwise, it's brought to the front, in front of axes.  
     80         
     81        The default in ``False``, so that items apper in front of axes.  
     82         
     83    .. method:: is_in_background() 
     84     
     85        Returns if item is in the background, set with :meth:`set_in_background`.  
     86         
    3287.. autoclass:: OWCurve 
    3388    :members: 
     
    83138            :type: str 
    84139 
    85             The name of the curve, used in the legend or in tooltips 
    86              
    87         .. method:: update_properties() 
    88          
    89             Called by the plot, this function updates the curve's internal state to match its settings.  
    90              
    91             The default implementation moves creates the points and sets their position, size, shape and color.  
     140            The name of the curve, used in the legend or in tooltips.  
    92141             
    93142        .. method:: set_data(x_data, y_data) 
  • orange/OrangeWidgets/plot/owplot.py

    r8626 r8628  
    11''' 
    22 
    3 .. index:: plot 
    4  
    5 ############################## 
     3################# 
    64Plot (``owplot``) 
    7 ############################## 
     5################# 
    86 
    97.. autoclass:: OrangeWidgets.plot.OWPlot 
     
    358356            :type point: tuple or QPointF 
    359357             
    360             :param axes: The pair of axes along which to transform the point. If none are specified, (xBottom, yLeft) will be used.  
     358            :param axes: The pair of axes along which to transform the point.  
     359                         If none are specified, (xBottom, yLeft) will be used.  
    361360            :type axes: tuple of float float 
    362361             
     
    787786         
    788787    def update_axes(self, zoom_only=False): 
     788        """ 
     789            Updates the axes.  
     790             
     791            If ``zoom_only`` is ``True``, only the positions of the axes and their labels are recalculated.  
     792            Otherwise, all their labels are updated.  
     793        """ 
    789794        for id, item in self.axes.iteritems(): 
    790795            if item.scale is None and item.labels is None: 
     
    10421047    @staticmethod 
    10431048    def transform_from_rects(r1, r2): 
     1049        """ 
     1050            Returns a QTransform that maps from rectangle ``r1`` to ``r2``.  
     1051        """ 
    10441052        if r1 is None or r2 is None: 
    10451053            return QTransform() 
     
    10891097         
    10901098    def add_selection(self, reg): 
     1099        """ 
     1100            Selects all points in the region ``reg`` using the current :attr: `selection_behavior`.  
     1101        """ 
    10911102        self.select_points(reg, self.selection_behavior) 
    10921103        self.viewport().update() 
     
    11041115         
    11051116    def data_rect_for_axes(self, x_axis = xBottom, y_axis = yLeft): 
     1117        """ 
     1118            Calculates the bounding rectangle in data coordinates for the axes ``x_axis`` and ``y_axis``.  
     1119        """ 
    11061120        if x_axis in self.axes and y_axis in self.axes: 
    11071121            x_min, x_max = self.bounds_for_axis(x_axis, try_auto_scale=False) 
     
    11211135         
    11221136    def transform_for_axes(self, x_axis = xBottom, y_axis = yLeft): 
     1137        """ 
     1138            Returns the graph transform that maps from data to scene coordinates using axes ``x_axis`` and ``y_axis``.  
     1139        """ 
    11231140        if not (x_axis, y_axis) in self._transform_cache: 
    11241141            # We must flip the graph area, becase Qt coordinates start from top left, while graph coordinates start from bottom left 
  • orange/OrangeWidgets/plot/owtools.py

    r8620 r8628  
    5252         
    5353        :param lst: The list to be resized 
    54         :type lst: List of QGraphicsItems 
     54        :type lst: list of QGraphicsItem 
    5555         
    5656        :param size: The needed size of the list 
     
    6363        :type parent: QGraphicsItem 
    6464         
    65         :rtype: List of QGraphicsItems 
     65        :rtype: list of QGraphicsItem 
    6666        :returns: The resized list 
    6767    """ 
     
    114114    move_item(item, QPointF(x, y), duration) 
    115115         
    116 #A dynamic tool tip class 
    117116class TooltipManager: 
    118     # Creates a new dynamic tool tip. 
    119     # The second argument is a OWGraph instance 
    120     def __init__(self, graph): 
    121         self.graph = graph 
     117    """ 
     118        A dynamic tool tip manager.  
     119         
     120        :param plot: The plot used for transforming the coordinates 
     121        :type plot: :obj:`.OWPlot` 
     122    """ 
     123    def __init__(self, plot): 
     124        self.graph = plot 
    122125        self.positions=[] 
    123126        self.texts=[] 
    124127 
    125     # Adds a tool tip. If a tooltip with the same name already exists, it updates it instead of adding a new one. 
    126128    def addToolTip(self, x, y, text, customX = 0, customY = 0): 
     129        """ 
     130            Adds a tool tip. If a tooltip with the same name already exists, it updates it instead of adding a new one. 
     131             
     132            :param x: The x coordinate of the tip, in data coordinates.  
     133            :type x: float 
     134             
     135            :param y: The y coordinate of the tip, in data coordinates.  
     136            :type y: float 
     137             
     138            :param text: The text to show in the tip.  
     139            :type text: str or int 
     140             
     141            :param customX: The maximum horizontal distance in pixels from the point (x,y) at which to show the tooltip.  
     142            :type customX: float 
     143             
     144            :param customY: The maximum vertical distance in pixels from the point (x,y) at which to show the tooltip.  
     145            :type customY: float 
     146             
     147            If ``customX`` and ``customY`` are omitted, a default of 6 pixels is used.  
     148        """ 
    127149        self.positions.append((x,y, customX, customY)) 
    128150        self.texts.append(text) 
     
    130152    #Decides whether to pop up a tool tip and which text to pop up 
    131153    def maybeTip(self, x, y): 
     154        """ 
     155            Decides whether to pop up a tool tip and which text to show in it. 
     156             
     157            :param x: the x coordinate of the mouse in data coordinates.  
     158            :type x: float 
     159             
     160            :param y: the y coordinate of the mouse in data coordinates.  
     161            :type y: float 
     162             
     163            :returns: A tuple consisting of the ``text``, ``x`` and ``y`` arguments to :meth:`addToolTip` of the 
     164                      closest point.  
     165            :rtype: tuple of (int or str), float, float 
     166        """ 
    132167        if len(self.positions) == 0: return ("", -1, -1) 
    133168        dists = [max(abs(x-position[0])- position[2],0) + max(abs(y-position[1])-position[3], 0) for position in self.positions] 
     
    146181 
    147182    def removeAll(self): 
     183        """ 
     184            Removes all tips 
     185        """ 
    148186        self.positions = [] 
    149187        self.texts = [] 
    150188 
    151 # Convenience curve classes 
    152189class PolygonCurve(OWCurve): 
     190    """ 
     191        A plot item that shows a filled or empty polygon.  
     192         
     193        :param pen: The pen used to draw the polygon's outline 
     194        :type pen: :obj:`.QPen` 
     195         
     196        :param brush: The brush used to paint the polygon's inside 
     197        :type brush: :obj:`.QBrush 
     198         
     199        :param xData: The list of x coordinates 
     200        :type xData: list of float 
     201 
     202        :param yData: The list of y coordinates 
     203        :type yData: list of float 
     204         
     205        :param tooltip: The tool tip shown when hovering over this curve 
     206        :type tooltip: str 
     207    """ 
    153208    def __init__(self, pen = QPen(Qt.black), brush = QBrush(Qt.white), xData = [], yData = [], tooltip = None): 
    154209        OWCurve.__init__(self, xData, yData, tooltip=tooltip) 
     
    165220    @staticmethod 
    166221    def polygon_from_data(xData, yData): 
     222        """ 
     223            Creates a polygon from a list of x and y coordinates.  
     224             
     225            :returns: A polygon with point corresponding to ``xData`` and ``yData``. 
     226            :rtype: QPolygonF 
     227        """ 
    167228        if xData and yData: 
    168229            n = min(len(xData), len(yData)) 
     
    180241            
    181242class RectangleCurve(OWCurve): 
     243    """ 
     244        A plot item that shows a rectangle.  
     245         
     246        This class accepts the same options as :obj:`.PolygonCurve`.  
     247        The rectangle is calculated as the smallest rectangle that contains all points in ``xData`` and ``yData``.  
     248    """ 
    182249    def __init__(self, pen = QPen(Qt.black), brush = QBrush(Qt.white), xData = None, yData = None, tooltip = None): 
    183250        OWCurve.__init__(self, xData, yData, tooltip=tooltip) 
     
    192259         
    193260class UnconnectedLinesCurve(orangeplot.UnconnectedLinesCurve): 
     261    """ 
     262        A plot item that shows a series of unconnected straight lines.  
     263         
     264        :param name: The name of this curve. :seealso: :attr:`.OWCurve.name` 
     265        :type name: str 
     266         
     267        :param pen: The pen used to draw the lines 
     268        :type pen: QPen 
     269         
     270        :param xData: The list of x coordinates 
     271        :type xData: list of float 
     272 
     273        :param yData: The list of y coordinates 
     274        :type yData: list of float 
     275         
     276        The data should contain an even number of elements. Lines are drawn between the `n`-th and  
     277        `(n+1)`-th point for each even `n`.  
     278    """ 
    194279    def __init__(self, name, pen = QPen(Qt.black), xData = None, yData = None): 
    195280        orangeplot.UnconnectedLinesCurve.__init__(self, xData, yData) 
     
    199284         
    200285class CircleCurve(OWCurve): 
     286    """ 
     287        Displays a circle on the plot 
     288         
     289        :param pen: The pen used to draw the outline of the circle 
     290        :type pen: QPen 
     291         
     292        :param brush: The brush used to paint the inside of the circle 
     293        :type brush: QBrush 
     294         
     295        :param xCenter: The x coordinate of the circle's center 
     296        :type xCenter: float 
     297         
     298        :param yCenter: The y coordinate of the circle's center 
     299        :type yCenter: float 
     300         
     301        :param radius: The circle's radius 
     302        :type radius: float 
     303    """ 
    201304    def __init__(self, pen = QPen(Qt.black), brush = QBrush(Qt.NoBrush), xCenter = 0.0, yCenter = 0.0, radius = 1.0): 
    202305        OWCurve.__init__(self) 
     
    219322         
    220323class Marker(orangeplot.PlotItem): 
     324    """ 
     325        Displays a text marker on the plot.  
     326         
     327        :param text: The text to display. It can be HTML-formatted 
     328        :type tex: str 
     329         
     330        :param x: The x coordinate of the marker's position 
     331        :type x: float 
     332         
     333        :param y: The y coordinate of the marker's position 
     334        :type y: float 
     335         
     336        :param align: The text alignment 
     337        :type align:  
     338         
     339        :param bold: If ``True``, the text will be show bold.  
     340        :type bold: int 
     341         
     342        :param color: The text color 
     343        :type color: QColor 
     344         
     345        :param brushColor: The color of the brush user to paint the background 
     346        :type color: QColor 
     347         
     348        :param size: Font size 
     349        :type size: int 
     350    """ 
    221351    def __init__(self, text, x, y, align, bold = 0, color = None, brushColor = None, size=None): 
    222352        orangeplot.PlotItem.__init__(self) 
     
    234364 
    235365class ProbabilitiesItem(orangeplot.PlotItem): 
     366    """ 
     367        Displays class probabilities in the background 
     368         
     369        :param classifier: The classifier for which the probabilities are calculated 
     370        :type classifier: orange.P2NN 
     371         
     372        :param granularity: The size of individual cells 
     373        :type granularity: int 
     374         
     375        :param scale: The data scale factor 
     376        :type scale: float 
     377         
     378        :param spacing: The space between cells 
     379        :param spacing: int 
     380         
     381        :param rect: The rectangle into which to draw the probabilities. If unspecified, the entire plot is used.  
     382        :type rect: QRectF 
     383    """ 
    236384    def __init__(self, classifier, granularity, scale, spacing, rect=None): 
    237385        orangeplot.PlotItem.__init__(self) 
     
    300448    }) 
    301449class PlotGrid(orangeplot.PlotItem): 
    302     def __init__(self, plot): 
     450    """ 
     451        Draws a grid onto the plot 
     452         
     453        :param plot: If specified, the grid will be attached to the ``plot``.  
     454        :type plot: :obj:`.OWPlot` 
     455    """ 
     456    def __init__(self, plot = None): 
    303457        orangeplot.PlotItem.__init__(self) 
    304458        self._x_enabled = True 
     
    306460        self._path_item = QGraphicsPathItem(self) 
    307461        self.set_in_background(True) 
    308         self.attach(plot) 
    309          
     462        if plot: 
     463            self.attach(plot) 
     464             
    310465    def set_x_enabled(self, b): 
     466        """ 
     467            Enables or disabled vertial grid lines 
     468        """ 
    311469        if b < 0: 
    312470            b = not self._x_enabled 
     
    315473         
    316474    def is_x_enabled(self): 
     475        """ 
     476            Returns whether vertical grid lines are enabled 
     477        """ 
    317478        return self._x_enabled 
    318479         
    319480    def set_y_enabled(self, b): 
     481        """ 
     482            Enables or disabled horizontal grid lines 
     483        """ 
    320484        if b < 0: 
    321485            b = not self._y_enabled 
     
    324488         
    325489    def is_y_enabled(self): 
     490        """ 
     491            Returns whether horizontal grid lines are enabled 
     492        """ 
    326493        return self._y_enabled 
    327494         
    328495    def set_pen(self, pen): 
     496        """ 
     497            Sets the pen used for drawing the grid lines 
     498        """ 
    329499        self._path_item.setPen(pen) 
    330500         
Note: See TracChangeset for help on using the changeset viewer.