Changeset 8526:e8729aed2593 in orange


Ignore:
Timestamp:
07/29/11 14:36:46 (3 years ago)
Author:
Noughmad <Noughmad@…>
Branch:
default
Convert:
b44851a2e0f64cca2b958a961a0baee3fe4c144d
Message:

Start writing documentation for the OWPlot class

Location:
orange
Files:
3 edited

Legend:

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

    r8374 r8526  
    1 __all__ = [ "owcurve", "owpoint", "owlegend", "owaxis", "owtools" ] 
     1""" 
     2 
     3************************* 
     4Plot classes and tools for use in Orange widgets 
     5************************* 
     6 
     7The main class of this module is :obj:`OrangeWidgets.plot.OWPlot`, from which all plots  
     8in visualization widgets should inherit.  
     9 
     10This module also contains plot elements, which are normally use by the :obj:`OrangeWidgets.plot.OWPlot`, but can  
     11be either subclassed or used directly from outside. These elements are: 
     12* :obj: `OrangeWidgets.plot.OWCurve` 
     13* :obj: `OrangeWidgets.plot.OWPoint` 
     14* :obj: `OrangeWidgets.plot.OWAxis` 
     15* :obj: `OrangeWidgets.plot.OWLegend` 
     16""" 
     17 
     18from owcurve import * 
     19from owpoint import * 
     20from owlegend import * 
     21from owaxis import * 
     22from owplot import * 
     23from owtools import * 
  • orange/OrangeWidgets/plot/owplot.py

    r8523 r8526  
    1 """ 
    2     .. class:: OWPlot 
    3         The base class for all graphs in Orange. It is written in Qt with QGraphicsItems 
    4          
    5     .. attribute:: show_legend 
    6         A boolean controlling whether the legend is displayed or not 
    7          
    8     .. attribute:: legend_position 
    9         Determines where the legend is positions, if ``show_legend`` is True. 
    10          
    11     .. atribute:: palette 
    12         Chooses which palette is used by this graph. By default, this is `shared_palette`.  
    13          
    14     .. method map_to_graph(axis_ids, point) 
    15         Maps the ``point`` in data coordinates to graph (scene) coordinates 
    16         This method has to be reimplemented in graphs with special axes (RadViz, PolyViz) 
    17          
    18     .. method map_from_graph(axis_ids, point) 
    19         Maps the ``point`` from scene coordinates to data coordinates 
    20         This method has to be reimplemented in graphs with special axes (RadViz, PolyViz) 
    21          
    22     .. method activateZooming() 
    23         Activates zoom 
    24          
    25     .. method clear() 
    26         Removes all curves from the graph 
    27          
    28     .. method graph_area_rect() 
    29         Return the QRectF of the area where data is plotted (without axes) 
    30          
    31     .. method send_data(): 
    32         This method is not defined here, it is up to subclasses to implement it.  
    33         It should send selected examples to the next widget 
    34          
    35     .. method add_curve(name, attributes, ...) 
    36         Attributes is a map of { point_property: ("data_property", value) }, for example  
    37             { PointColor : ("building_type", "house"), PointSize : ("age", 20) } 
    38 """ 
     1''' 
     2############################## 
     3Plot (``owplot``) 
     4############################## 
     5 
     6.. autoclass:: OWPlot 
     7    :members: 
     8    :show-inheritance: 
     9     
     10''' 
    3911 
    4012NOTHING = 0 
     
    10173 
    10274@deprecated_members(name_map, wrap_methods=name_map.keys()) 
    103 class OWPlot(orangeplot.Plot): 
     75class OWPlot(orangeplot.Plot):  
     76    """ 
     77    The base class for all plots in Orange. It uses the Qt Graphics View Framework 
     78    to draw elements on a graph.  
     79         
     80    .. attribute:: show_legend 
     81     
     82        A boolean controlling whether the legend is displayed or not 
     83         
     84    .. attribute:: show_main_title 
     85     
     86        Controls whether or not the main plot title is displayed 
     87         
     88    .. attribute:: main_title 
     89     
     90        The plot title, usually show on top of the plot 
     91         
     92    .. attribute:: zoom_transform 
     93         
     94        Contains the current zoom transformation  
     95    """ 
    10496    def __init__(self, parent = None,  name = "None",  show_legend = 1, axes = [xBottom, yLeft] ): 
     97        """ 
     98            Creates a new graph 
     99             
     100            If your visualization uses axes other than ``xBottom`` and ``yLeft``, specify them in the 
     101            ``axes`` parameter. To use non-cartesian axes, set ``axes`` to an empty list 
     102            and add custom axes with :meth:`add_axis` or :meth:`add_custom_axis` 
     103        """ 
    105104        orangeplot.Plot.__init__(self, parent) 
    106105        self.parent_name = name 
     
    206205    useAntialiasing = deprecated_attribute("useAntialiasing", "use_antialiasing") 
    207206    showFilledSymbols = deprecated_attribute("showFilledSymbols", "show_filled_symbols") 
     207    mainTitle = deprecated_attribute("mainTitle", "main_title") 
     208    showMainTitle = deprecated_attribute("showMainTitle", "show_main_title") 
    208209     
    209210    def __setattr__(self, name, value): 
     
    219220         
    220221    def map_to_graph(self, point, axes = None, zoom = False): 
     222        ''' 
     223            Maps ``point``, which can be ether a tuple of (x,y), a QPoint or a QPointF, from data coordinates 
     224            to scene coordinates.  
     225             
     226            If ``zoom`` is ``True``, the point is additionally transformed with :attr:`zoom_transform` 
     227        ''' 
    221228        if type(point) == tuple: 
    222229            (x, y) = point 
     
    232239         
    233240    def map_from_graph(self, point, axes = None, zoom = False): 
     241        ''' 
     242            Maps ``point``, which can be ether a tuple of (x,y), a QPoint or a QPointF, from scene coordinates 
     243            to data coordinates.  
     244             
     245            If ``zoom`` is ``True``, the point is additionally transformed with :attr:`zoom_transform` 
     246        ''' 
    234247        if type(point) == tuple: 
    235248            (x, y) = point 
     
    255268         
    256269    def activate_zooming(self): 
     270        ''' 
     271            Activates the zooming mode, where the user can zoom in and out with a single mouse click  
     272            or by dragging the mouse to form a rectangular area 
     273        ''' 
    257274        self.state = ZOOMING 
    258275         
    259276    def activate_rectangle_selection(self): 
     277        ''' 
     278            Activates the rectangle selection mode, where the user can select points in a rectangular area 
     279            by dragging the mouse over them 
     280        ''' 
    260281        self.state = SELECT_RECTANGLE 
    261282         
    262283    def activate_selection(self): 
     284        ''' 
     285            Activates the point selection mode, where the user can select points by clicking on them 
     286        ''' 
    263287        self.state = SELECT 
    264288         
    265289    def activate_polygon_selection(self): 
     290        ''' 
     291            Activates the polygon selection mode, where the user can select points by drawing a polygon around them 
     292        ''' 
    266293        self.state = SELECT_POLYGON 
    267294         
    268295    def setShowMainTitle(self, b): 
     296        ''' 
     297            Shows the main title if ``b`` is ``True``, and hides it otherwise.  
     298        ''' 
    269299        self.showMainTitle = b 
    270300        self.replot() 
    271301 
    272302    def setMainTitle(self, t): 
     303        ''' 
     304            Sets the main title to ``t`` 
     305        ''' 
    273306        self.mainTitle = t 
    274307        self.replot() 
     
    319352         
    320353    def set_axis_labels(self, axis_id, labels): 
     354        ''' 
     355            Sets the labels of axis ``axis_id`` to ``labels``. This changes the axis scale and removes any previous scale 
     356            set with :meth: `set_axis_scale`.  
     357        ''' 
    321358        if axis_id in self._bounds_cache: 
    322359            del self._bounds_cache[axis_id] 
     
    325362     
    326363    def set_axis_scale(self, axis_id, min, max, step_size=0): 
     364        ''' 
     365            Sets the labels of axis ``axis_id`` to ``labels``. This changes the axis scale and removes any previous labels 
     366            set with :meth: `set_axis_labels`.  
     367        ''' 
    327368        qDebug('Setting axis scale for ' + str(axis_id) + ' with axes ' + ' '.join(str(i) for i in self.axes)) 
    328369        if axis_id in self._bounds_cache: 
     
    357398         
    358399    def add_custom_curve(self, curve, enableLegend = False): 
     400        ''' 
     401            Adds a custom PlotItem ``curve`` to the plot.  
     402            If ``enableLegend`` is ``True``, a curve symbol defined by  
     403            :meth:`OrangeWidgets.plot.OWCurve.point_item` and the ``curve``'s name 
     404            :obj:`OrangeWidgets.plot.OWCurve.name` is added to the legend.  
     405        ''' 
    359406        self.add_item(curve) 
    360407        if enableLegend: 
     
    374421                 lineWidth = 1, pen = None, autoScale = 0, antiAlias = None, penAlpha = 255, brushAlpha = 255,  
    375422                 x_axis_key = xBottom, y_axis_key = yLeft): 
     423        ''' 
     424            Creates a new :obj:`OrangeWidgets.plot.OWCurve` with the specified parameters and adds it to the graph.  
     425            If ``enableLegend`` is ``True``, a curve symbol is added to the legend.  
     426        ''' 
    376427        c = OWCurve(xData, yData, x_axis_key, y_axis_key, tooltip=name, parent=self.graph_item) 
    377428        c.set_zoom_factor(self._zoom_factor) 
     
    401452         
    402453    def remove_curve(self, item): 
     454        ''' 
     455            Removes ``item`` from the plot 
     456        ''' 
    403457        self.remove_item(item) 
    404458        self.legend().remove_curve(item) 
     
    408462         
    409463    def add_axis(self, axis_id, title = '', title_above = False, title_location = AxisMiddle, line = None, arrows = AxisEnd, zoomable = False): 
     464        ''' 
     465            Creates an :obj:`OrangeWidgets.plot.OWAxis` with the specified ``axis_id`` and ``title``.  
     466        ''' 
    410467        qDebug('Adding axis with id ' + str(axis_id) + ' and title ' + title) 
    411468        a = OWAxis(axis_id, title, title_above, title_location, line, arrows, scene=self.scene()) 
     
    418475         
    419476    def remove_all_axes(self, user_only = True): 
     477        ''' 
     478            Removes all axes from the plot 
     479        ''' 
    420480        ids = [] 
    421481        for id,item in self.axes.iteritems(): 
     
    427487         
    428488    def add_custom_axis(self, axis_id, axis): 
     489        ''' 
     490            Adds a custom ``axis`` with id ``axis_id`` to the plot 
     491        ''' 
    429492        self.axes[axis_id] = axis 
    430493         
     
    442505         
    443506    def clear(self): 
     507        ''' 
     508            Clears the plot, removing all curves, markers and tooltips.  
     509            Axes are not removed 
     510        ''' 
    444511        for i in self.plot_items(): 
    445512            self.remove_item(i) 
     
    451518         
    452519    def clear_markers(self): 
     520        ''' 
     521            Removes all markers added with :meth:`add_marker` from the plot 
     522        ''' 
    453523        for item,x,y,x_axis,y_axis in self._marker_items: 
    454524            item.detach() 
     
    456526         
    457527    def update_layout(self): 
     528        ''' 
     529            Updates the plot layout.  
     530             
     531            This function recalculates the position of titles, axes, the legend and the main plot area.  
     532            It does not update the curve or the other plot items.  
     533        ''' 
    458534        graph_rect = QRectF(self.contentsRect()) 
    459535        self.centerOn(graph_rect.center()) 
     
    537613             
    538614    def update_zoom(self): 
     615        ''' 
     616            Updates the zoom transformation of the plot items.  
     617        ''' 
    539618        self.zoom_transform = self.transform_for_zoom(self._zoom_factor, self._zoom_point, self.graph_area) 
    540619        self.zoom_rect = self.zoom_transform.mapRect(self.graph_area) 
     
    597676         
    598677    def replot(self): 
     678        ''' 
     679            Replot the entire graph.  
     680             
     681            This functions redraws everything on the graph, so it can be very slow 
     682        ''' 
    599683        if self.is_dirty(): 
    600684            self._bounds_cache = {} 
     
    622706         
    623707    def legend(self): 
     708        ''' 
     709            Returns the plot's legend, which is a :obj:`OrangeWidgets.plot.OWLegend` 
     710        ''' 
    624711        return self._legend 
    625712         
  • orange/doc/Orange/rst/index.rst

    r8378 r8526  
    4141   Orange.misc 
    4242 
     43   OrangeWidgets.plot 
     44 
    4345**************** 
    4446Index and search 
Note: See TracChangeset for help on using the changeset viewer.