summaryrefslogtreecommitdiff
path: root/PyMca5/PyMcaGraph/PlotBackend.py
blob: ee7dad5315ca2ff55c6dab745d2bf13b9fcff894 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
#/*##########################################################################
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2015 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__author__ = "V.A. Sole - ESRF Data Analysis"
__contact__ = "sole@esrf.fr"
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__doc__ = """
This module can be used for testing purposes as well as an abstract class for
implementing Plot backends.

TODO: Still to be worked out: handling of the right vertical axis.

PlotBackend Functions (Functions marked by (*) only needed for handling images)

- addCurve
- addImage (*)
- addItem (*)
- clear
- clearCurves
- clearImages (*)
- clearMarkers
- enableActiveCurveHandling
- getDefaultColormap (*)
- getDrawMode
- getGraphXLabel
- getGraphXLimits
- getGraphYLabel
- getGraphYLimits
- getGraphTitle
- getSupportedColormaps (*)
- getWidgetHandle
- insertMarker
- insertXMarker
- insertYMarker
- invertYAxis
- isDrawModeEnabled
- isKeepDataAspectRatio
- isXAxisAutoScale
- isYAxisAutoScale
- keepDataAspectRatio(*)
- removeCurve
- removeImage (*)
- removeMarker
- resetZoom
- replot
- replot_
- saveGraph
- setActiveCurve
- setActiveImage (*)
- setCallback
- setDefaultColormap (*)
- setDrawModeEnabled
- setGraphTitle
- setGraphXLabel
- setGraphXLimits
- setGraphYLabel
- setGraphYLimits
- setLimits
- setXAxisAutoScale
- setXAxisLogarithmic
- setYAxisAutoScale
- setYAxisLogarithmic
- setZoomModeEnabled
- showGrid

PlotBackend "signals/events"

All the events pass via the callback_function supplied.

They consist on a dictionnary in which the 'event' key is mandatory.

The following keys will be present or not depending on the type of event, but
if present, their meaning should be:

KEY - Meaning

- button - "left", "right", "middle"
- label - The label or legend associated to the item associated to the event
- type - The type of item associated to event ('curve', 'marker', ...)
- x - Bottom axis value in graph coordenates
- y - Vertical axis value in graph coordenates
- xpixel - x position in pixel coordenates
- ypixel - y position in pixel coordenates
- xdata - Horizontal graph coordinate associated to the item
- ydata - Vertical graph coordinate associated to the item


drawingFinished

    It looks as it should export xdata, ydata and type.

    The information will depend on the type of item being drawn:

    - line - two points in graph and pixel coordinates
    - hline - one point in graph and pixel coordinates
    - vline - one point in graph and pixel coordinates
    - rectangle - four points in graph and pixel coordinates, x, y, width, height
    - polygone - n points in graph and pixel coordinates
    - ellipse - four points in graph and pixel coordinates?
    - circle - four points in graph and pixel coordinates, center and radius
    - parameters - Parameters passed to setDrawMode when enabling it

hover
    Emitted the mouse pass over an item with hover notification (markers)

imageClicked, curveClicked
    usefull for pop-up menus associated to the click using the xpixel, ypixel
    or to set a curve active using the label and type keys

markerMoving
    Additional keys:

    - draggable - True if it is a movable marker (it should be True)
    - selectable - True if the marker can be selected

markerMoved
    Additional keys:

    - draggable - True if it is a movable marker (it should be True)
    - selectable - True if the marker can be selected
    - xdata, ydata - Final position of the marker

markerClicked
    Additional keys:

    - draggable - True if it is a movable marker
    - selectable - True if the marker can be selected (it should be True)

mouseMoved
    Export the mouse position in pixel and graph coordenates

mouseClicked
    Emitted on mouse release when not zooming, nor drawing, nor picking

mouseDoubleClicked
    Emitted on mouse release when not zooming, nor drawing, nor picking

limitsChanged
    Emitted when limits of visible plot area are changed.
    This can results from user interaction or API calls.

    Keys:

    - source: id of the widget that emitted this event.
    - xdata: Range of X in graph coordinates: (xMin, xMax).
    - ydata: Range of Y in graph coordinates: (yMin, yMax).
    - y2data: Range of right axis in graph coordinates (y2Min, y2Max) or None.
"""

DEBUG = 0

from . import Colors

class PlotBackend(object):

    COLORDICT = Colors.COLORDICT
    """
    Dictionnary of predefined colors
    """

    def __init__(self, parent=None):
        self._callback = self._dummyCallback
        self._parent = parent
        self._zoomEnabled = True
        self._drawModeEnabled = False
        self._xAutoScale = True
        self._yAutoScale = True
        self.setGraphXLimits(0., 100.)
        self.setGraphYLimits(0., 100.)
        self._activeCurveHandling = False
        self.setActiveCurveColor("#000000")

    def addCurve(self, x, y, legend=None, info=None, replace=False, replot=True,
                 color=None, symbol=None, linewidth=None, linestyle=None,
                 xlabel=None, ylabel=None, yaxis=None,
                 xerror=None, yerror=None, z=1, selectable=True, **kw):
        """
        Add the 1D curve given by x an y to the graph.

        :param x: The data corresponding to the x axis
        :type x: list or numpy.ndarray
        :param y: The data corresponding to the y axis
        :type y: list or numpy.ndarray
        :param legend: The legend to be associated to the curve
        :type legend: string or None
        :param info: Dictionary of information associated to the curve
        :type info: dict or None
        :param replace: Flag to indicate if already existing curves are to be deleted
        :type replace: boolean default False
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        :param color: color(s) to be used
        :type color: string ("#RRGGBB") or (npoints, 4) unsigned byte array or
                     one of the predefined color names defined in Colors.py
        :param symbol: Symbol to be drawn at each (x, y) position::

            - 'o' circle
            - '.' point
            - ',' pixel
            - '+' cross
            - 'x' x-cross
            - 'd' diamond
            - 's' square

        :type symbol: None or one of the predefined symbols
        :param linewidth: The width of the curve in pixels (Default: 1).
        :type linewidth: None or float.
        :param linestyle: Type of line::

            - ' '  no line
            - '-'  solid line
            - '--' dashed line
            - '-.' dash-dot line
            - ':'  dotted line

        :type linestyle: None or one of the predefined styles.

        :param xlabel: Label associated to the X axis when the curve is active
        :type xlabel: string
        :param ylabel: Label associated to the Y axis when the curve is active
        :type ylabel: string
        :param yaxis: Anything different from "right" is equivalent to "left"
        :type yaxis: string or None
        :param xerror: Values with the uncertainties on the x values
        :type xlabel: array
        :param yerror: Values with the uncertainties on the y values
        :type ylabel: array
        :param z: level at which the curve is to be located (to allow overlays).
        :type z: A number bigger than or equal to zero (default: one)
        :param selectable: indicate if the curve can be picked.
        :type selectable: boolean default: True
        :returns: The legend/handle used by the backend to univocally access it.
        """
        print("PlotBackend addCurve not implemented")
        return legend

    def addImage(self, data, legend=None, info=None,
                    replace=True, replot=True,
                    xScale=None, yScale=None, z=0,
                    selectable=False, draggable=False,
                    colormap=None, **kw):
        """
        :param data: (nrows, ncolumns) data or (nrows, ncolumns, RGBA) ubyte array
        :type data: numpy.ndarray
        :param legend: The legend to be associated to the curve
        :type legend: string or None
        :param info: Dictionary of information associated to the image
        :type info: dict or None
        :param replace: Flag to indicate if already existing images are to be deleted
        :type replace: boolean default True
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        :param xScale: Two floats defining the x scale
        :type xScale: list or numpy.ndarray
        :param yScale: Two floats defining the y scale
        :type yScale: list or numpy.ndarray
        :param z: level at which the image is to be located (to allow overlays).
        :type z: A number bigger than or equal to zero (default)
        :param selectable: Flag to indicate if the image can be selected
        :type selectable: boolean, default False
        :param draggable: Flag to indicate if the image can be moved
        :type draggable: boolean, default False
        :param colormap: Dictionary describing the colormap to use (or None)
        :type colormap: Dictionnary or None (default). Ignored if data is RGB(A)
        :returns: The legend/handle used by the backend to univocally access it.
        """
        print("PlotBackend addImage not implemented")
        return legend

    def addItem(self, xList, yList, legend=None, info=None,
                                 replace=False, replot=True,
                                shape="polygon", fill=True, **kw):
        """
        :param shape: Type of item to be drawn
        :type shape: string, default polygon
        """
        print("PlotBackend addItem not implemented")
        return legend

    def clear(self):
        """
        Clear all curvers and other items from the plot
        """
        print("PlotBackend clear not implemented")
        return

    def clearCurves(self):
        """
        Clear all curves from the plot. Not the markers!!
        """
        print("PlotBackend clearCurves not implemented")
        return

    def clearImages(self):
        """
        Clear all images from the plot. Not the curves or markers.
        """
        print("PlotBackend clearImages not implemented")
        return

    def clearMarkers(self):
        """
        Clear all markers from the plot. Not the curves!!
        """
        print("PlotBackend clearMarkers not implemented")
        return

    def _dummyCallback(self, ddict):
        """
        Default callback
        """
        print("PlotBackend default callback called")
        print(ddict)

    def dataToPixel(self, x=None, y=None, axis="left"):
        """
        Convert a position in data space to a position in pixels in the widget.

        :param float x: The X coordinate in data space. If None (default)
                            the middle position of the displayed data is used.
        :param float y: The Y coordinate in data space. If None (default)
                            the middle position of the displayed data is used.
        :param str axis: The Y axis to use for the conversion
                         ('left' or 'right').
        :returns: The corresponding position in pixels or
                  None if the data position is not in the displayed area.
        :rtype: A tuple of 2 floats: (xPixel, yPixel) or None.
        """
        assert axis in ("left", "right")
        print("PlotBackend dataToPixel not implemented")
        return

    def enableActiveCurveHandling(self, flag=True):
        if flag:
            self._activeCurveHandling = True
        else:
            self._activeCurveHandling = False

    def getBaseVectors(self):
        """Returns the coordinate in the orthogonal plot of the X and Y unit
        vectors of the data.

        :return: X and Y data unit vectors in orthogonal plot coordinates
        :rtype: 2-tuple of 2-tuple of float: (xx, xy), (yx, yy)
        """
        print("PlotBackend getBaseVectors not implemented")

    def getGraphCursor(self):
        """
        Returns the current state of the crosshair cursor.

        :return: None if the crosshair cursor is not active,
                 else a tuple (color, linewidth, linestyle).
        """
        print("PlotBackend getGraphCursor not implemented")
        return None

    def getDefaultColormap(self):
        """
        Return the colormap that will be applied by the backend to an image
        if no colormap is applied to it.

        A colormap is a dictionnary with the keys:

        - name: string
        - normalization: string (linear, log)
        - autoscale: boolean
        - vmin: float, minimum value
        - vmax: float, maximum value
        - colors: integer (typically 256)
        """
        print("PlotBackend getDefaultColormap called")
        return {'name': 'gray', 'normalization':'linear',
                'autoscale':True, 'vmin':0.0, 'vmax':1.0,
                'colors':256}

    def getDrawMode(self):
        """
        Return a dictionnary (or None) with the parameters passed when setting
        the draw mode.

        - shape: The shape being drawn
        - label: Associated text (or None)

        and any other info passed to setDrawMode
        """
        print("PlotBackend getDrawMode not implemented")
        return None

    def getGraphTitle(self):
        """
        Get the graph title.
        :return:  string
        """
        print("PlotBackend getGraphTitle not implemented")
        return ""

    def getGraphXLimits(self):
        """
        Get the graph X (bottom) limits.
        :return:  Minimum and maximum values of the X axis
        """
        print("Get the graph X (bottom) limits")
        return self._xMin, self._xMax

    def getGraphXLabel(self):
        """
        Get the graph X (bottom) label.
        :return:  string
        """
        print("PlotBackend getGraphXLabel not implemented")
        return "X"

    def getGraphYLimits(self, axis="left"):
        """
        Get the graph Y (left) limits.

        :param axis: The axis for which to get the limits
        :type axis: str, either "left" (default) or "right"
        :return:  Minimum and maximum values of the Y axis
        """
        print("Get the graph Y (left) limits")
        assert axis in ("left", "right")
        if axis == "left":
            return self._yMin, self._yMax
        else:
            return self._yRightMin, self._yRightMax

    def getGraphYLabel(self):
        """
        Get the graph Y (left) label.
        :return:  string
        """
        print("PlotBackend getGraphYLabel not implemented")
        return "Y"

    def getSupportedColormaps(self):
        """
        Get a list of strings with the colormap names supported by the backend.
        The list should at least contain and start by:
        ['gray', 'reversed gray', 'temperature', 'red', 'green', 'blue']
        """
        return ['gray', 'reversed gray', 'temperature', 'red', 'green', 'blue']

    def getWidgetHandle(self):
        """
        :return: Backend widget or None if the backend inherits from widget.
        """
        return None

    def insertMarker(self, x, y, legend=None, text=None, color='k',
                      selectable=False, draggable=False, replot=True,
                      symbol=None, constraint=None,
                      **kw):
        """
        :param x: Horizontal position of the marker in graph coordenates
        :type x: float
        :param y: Vertical position of the marker in graph coordenates
        :type y: float
        :param legend: Legend associated to the marker to identify it
        :type legend: string
        :param text: Text associated to the marker
        :type text: string or None
        :param color: Color to be used for instance 'blue', 'b', '#FF0000'
        :type color: string, default 'k' (black)
        :param selectable: Flag to indicate if the marker can be selected
        :type selectable: boolean, default False
        :param draggable: Flag to indicate if the marker can be moved
        :type draggable: boolean, default False
        :param replot: Flag to indicate if the plot is to be updated
        :type replot: boolean, default True
        :param str symbol: Symbol representing the marker in:

            - 'o' circle
            - '.' point
            - ',' pixel
            - '+' cross
            - 'x' x-cross
            - 'd' diamond
            - 's' square

        :param constraint: A function filtering marker displacement by
                           dragging operations or None for no filter.
                           This function is called each time a marker is
                           moved.
                           This parameter is only used if draggable is True.
        :type constraint: None or a callable that takes the coordinates of
                          the current cursor position in the plot as input
                          and that returns the filtered coordinates.
        :return: Handle used by the backend to univocally access the marker
        """
        print("PlotBackend insertMarker not implemented")
        return legend

    def insertXMarker(self, x, legend=None, text=None, color='k',
                      selectable=False, draggable=False, replot=True,
                      **kw):
        """
        :param x: Horizontal position of the marker in graph coordenates
        :type x: float
        :param legend: Legend associated to the marker to identify it
        :type legend: string
        :param text: Text associated to the marker
        :type text: string or None
        :param color: Color to be used for instance 'blue', 'b', '#FF0000'
        :type color: string, default 'k' (black)
        :param selectable: Flag to indicate if the marker can be selected
        :type selectable: boolean, default False
        :param draggable: Flag to indicate if the marker can be moved
        :type draggable: boolean, default False
        :param replot: Flag to indicate if the plot is to be updated
        :type replot: boolean, default True
        :return: Handle used by the backend to univocally access the marker
        """
        print("PlotBackend insertXMarker not implemented")
        return legend

    def insertYMarker(self, y, legend=None, text=None, color='k',
                      selectable=False, draggable=False, replot=True,
                      **kw):
        """
        :param y: Vertical position of the marker in graph coordenates
        :type y: float
        :param legend: Legend associated to the marker to identify it
        :type legend: string
        :param text: Text associated to the marker
        :type text: string or None
        :param color: Color to be used for instance 'blue', 'b', '#FF0000'
        :type color: string, default 'k' (black)
        :param selectable: Flag to indicate if the marker can be selected
        :type selectable: boolean, default False
        :param draggable: Flag to indicate if the marker can be moved
        :type draggable: boolean, default False
        :param replot: Flag to indicate if the plot is to be updated
        :type replot: boolean, default True
        :return: Handle used by the backend to univocally access the marker
        """
        print("PlotBackend insertYMarker not implemented")
        return legend

    def invertYAxis(self, flag=True):
        """
        :param flag: If True, put the vertical axis origin on plot top left
        :type flag: boolean
        """
        print("PlotBackend invertYAxis not implemented")

    def isDefaultBaseVectors(self):
        """Returns True if axes have the default basis, False otherwise.

        The default basis is x horizontal, y vertical.
        """
        return True

    def isDrawModeEnabled(self):
        """
        :return: True if user can draw
        """
        print("PlotBackend isDrawModeEnabled not implemented")
        return False

    def isKeepDataAspectRatio(self):
        """Returns whether the plot is keeping data aspect ratio or not.

        :return: True if keeping data aspect ratio else False.
        """
        print("PlotBackend isKeepDataAspectRatio not implemented")
        return False

    def isXAxisAutoScale(self):
        """
        :return: True if bottom axis is automatically adjusting the scale
        """
        print("PlotBackend isXAxisAutoScale not implemented")
        return True

    def isYAxisAutoScale(self):
        """
        :return: True if left axis is automatically adjusting the scale
        """
        print("PlotBackend isYAxisAutoScale not implemented")
        return True

    def isYAxisInverted(self):
        """
        :return: True if left axis is inverted
        """
        print("PlotBackend isYAxisInverted not implemented")

    def isZoomModeEnabled(self):
        """
        :return: True if user can zoom
        """
        print("PlotBackend isZoomModeEnabled not implemented")
        return True


    def keepDataAspectRatio(self, flag=True):
        """
        :param flag:  True to respect data aspect ratio
        :type flag: Boolean, default True
        """
        print("PlotBackend keepDataAspectRatio not implemented")

    def pixelToData(self, x=None, y=None, axis="left"):
        """
        Convert a position in pixels in the widget to a position in
        the data space.

        :param float x: The X coordinate in pixels. If None (default)
                            the center of the widget is used.
        :param float y: The Y coordinate in pixels. If None (default)
                            the center of the widget is used.
        :param str axis: The Y axis to use for the conversion
                         ('left' or 'right').
        :returns: The corresponding position in data space or
                  None if the pixel position is not in the plot area.
        :rtype: A tuple of 2 floats: (xData, yData) or None.
        """
        assert axis in ("left", "right")
        print("PlotBackend pixelToData not implemented")
        return

    def removeCurve(self, legend, replot=True):
        """
        Remove the curve associated to the supplied legend from the graph.
        The graph will be updated if replot is true.

        :param legend: The legend associated to the curve to be deleted
        :type legend: string or handle
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        """
        print("PlotBackend removeCurve not implemented")
        return

    def removeImage(self, legend, replot=True):
        """
        Remove the image associated to the supplied legend from the graph.
        The graph will be updated if replot is true.

        :param legend: The legend associated to the image to be deleted
        :type legend: string or handle
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        """
        print("PlotBackend removeImage not implemented")
        return

    def removeItem(self, legend, replot=True):
        print("PlotBackend removeItem not implemented")
        return

    def removeMarker(self, label, replot=True):
        """
        Remove the marker associated to the supplied handle from the graph.
        The graph will be updated if replot is true.

        :param label: The handle/label associated to the curve to be deleted
        :type label: string or handle
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        """
        print("PlotBackend removeMarker not implemented")

    def resetZoom(self, dataMargins=None):
        """
        Autoscale any axis that is in autoscale mode.
        Keep current limits on axes not in autoscale mode

        Extra margins can be added around the data inside the plot area.
        Margins are given as one ratio of the data range per limit of the
        data (xMin, xMax, yMin and yMax limits).
        For log scale, extra margins are applied in log10 of the data.

        :param dataMargins: Ratios of margins to add around the data inside
                            the plot area for each side (Default: no margins).
        :type dataMargins: A 4-tuple of float as (xMin, xMax, yMin, yMax).
        """
        print("PlotBackend resetZoom not implemented")

    def replot(self):
        """
        Update plot. If replot is a reserved word of the used backend, it can
        be implemented as replot_
        """
        print("PlotBackend replot not implemented")

    def saveGraph(self, fileName, fileFormat='svg', dpi=None, **kw):
        """
        :param fileName: Destination
        :type fileName: String or StringIO or BytesIO
        :param fileFormat:  String specifying the format
        :type fileFormat: String (default 'svg')
        """
        print("PlotBackend saveGraph not implemented")

    def setActiveCurve(self, legend, replot=True):
        """
        Make the curve identified by the supplied legend active curve.

        :param legend: The legend associated to the curve
        :type legend: string
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        """
        print("PlotBackend setActiveCurve not implemented")
        return

    def setActiveCurveColor(self, color="#000000"):
        self._activeCurveColor = color

    def setActiveImage(self, legend, replot=True):
        """
        Make the image identified by the supplied legend active.

        :param legend: The legend associated to the image
        :type legend: string
        :param replot: Flag to indicate plot is to be immediately updated
        :type replot: boolean default True
        """
        if DEBUG:
            print("PlotBackend setActiveImage not implemented")
        return

    def setBaseVectors(self, x=(1., 0.), y=(0., 1.)):
        """Set the data coordinates relative to the orthogonal plot area.

        Useful for non-orthogonal axes.

        :param x: (x, y) coords on the X data base vector in orthogonal coords.
        :type x: 2-tuple of float
        :param y: (x, y) coords of the Y data base vector in orthogonal coords.
        :type y: 2-tuple of float
        """
        print("PlotBackend setBaseVectors not implemented")

    def setCallback(self, callback_function):
        """
        :param callback_function: function accepting a dictionnary as input to handle the graph events
        :type callback_function: callable
        """
        self._callback = callback_function

    def setGraphCursor(self, flag=None, color=None,
                       linewidth=None, linestyle=None):
        """
        Toggle the display of a crosshair cursor and set its attributes.

        :param bool flag: Toggle the display of a crosshair cursor.
                          The crosshair cursor is hidden by default.
        :param color: The color to use for the crosshair.
        :type color: A string (either a predefined color name in Colors.py
                     or "#RRGGBB")) or a 4 columns unsigned byte array.
                     Default is black.
        :param int linewidth: The width of the lines of the crosshair.
                              Default is 1.
        :param linestyle: Type of line::

            - ' '  no line
            - '-'  solid line
            - '--' dashed line
            - '-.' dash-dot line
            - ':'  dotted line

        :type linestyle: None or one of the predefined styles.
        """
        print("PlotBackend setGraphCursor not implemented")

    def setDefaultColormap(self, colormap=None):
        """
        Sets the colormap that will be applied by the backend to an image
        if no colormap is applied to it.

        A colormap is a dictionnary with the keys:

        :type name: string
        :type normalization: string (linear, log)
        :type autoscale: boolean
        :type vmin: float, minimum value
        :type vmax: float, maximum value
        :type colors: integer (typically 256)

        If None is passed, the backend will reset to its default colormap.
        """
        print("PlotBackend setDefaultColormap not implemented")
        return

    def setDrawModeEnabled(self, flag=True, shape="polygon", label=None,
                           color=None, **kw):
        """
        Zoom and drawing are not compatible and cannot be enabled simultanelously

        :param flag: Enable drawing mode disabling zoom and picking mode
        :type flag: boolean, default True
        :param shape: Type of item to be drawn (line, hline, vline, rectangle...)
        :type shape: string (default polygon)
        :param label: Associated text (for identifying the signals)
        :type label: string, default None
        :param color: The color to use to draw the selection area
        :type color: string ("#RRGGBB") or 4 column unsigned byte array or
                     one of the predefined color names defined in Colors.py
        """
        if flag:
            self._drawModeEnabled = True
            #cannot draw and zoom simultaneously
            self.setZoomModeEnabled(False)
        else:
            self._drawModeEnabled = False
        print("PlotBackend setDrawModeEnabled not implemented")

    def setGraphTitle(self, title=""):
        """
        :param title: Title associated to the plot
        :type title: string, default is an empty string
        """
        print("PlotBackend setTitle not implemented")

    def setGraphXLabel(self, label="X"):
        """
        :param label: label associated to the plot bottom axis
        :type label: string, default is 'X'
        """
        print("PlotBackend setGraphXLabel not implemented")

    def setGraphXLimits(self, xmin, xmax):
        """
        :param xmin: minimum bottom axis value
        :type xmin: float
        :param xmax: maximum bottom axis value
        :type xmax: float
        """
        self._xMin = xmin
        self._xMax = xmax
        print("PlotBackend setGraphXLimits not implemented")

    def setGraphYLabel(self, label="Y"):
        """
        :param label: label associated to the plot left axis
        :type label: string, default is 'Y'
        """
        print("PlotBackend setGraphYLabel not implemented")

    def setGraphYLimits(self, ymin, ymax, axis="left"):
        """
        :param ymin: minimum left axis value
        :type ymin: float
        :param ymax: maximum left axis value
        :type ymax: float
        :param axis: The axis for which to set the limits
        :type axis: str, either "left" (default) or "right"
        """
        assert axis in ("left", "right")
        if axis == "left":
            self._yMin = ymin
            self._yMax = ymax
        else:
            self._yRightMin = ymin
            self._yRightMax = ymax
        print("PlotBackend setGraphYLimits not implemented")

    def setLimits(self, xmin, xmax, ymin, ymax):
        """
        Convenience method

        :param xmin: minimum bottom axis value
        :type xmin: float
        :param xmax: maximum bottom axis value
        :type xmax: float
        :param ymin: minimum left axis value
        :type ymin: float
        :param ymax: maximum left axis value
        :type ymax: float
        """
        self.setGraphXLimits(xmin, xmax)
        self.setGraphYLimits(ymin, ymax)

    def setXAxisAutoScale(self, flag=True):
        """
        :param flag: If True, the bottom axis will adjust scale on zomm reset
        :type flag: boolean, default True
        """
        if flag:
            self._xAutoScale = True
        else:
            self._xAutoScale = False
        print("PlotBackend setXAxisAutoScale not implemented")

    def setXAxisLogarithmic(self, flag=True):
        """
        :param flag: If True, the bottom axis will use a log scale
        :type flag: boolean, default True
        """
        print("PlotBackend setXAxisLogarithmic not implemented")

    def setYAxisAutoScale(self, flag=True):
        """
        :param flag: If True, the left axis will adjust scale on zomm reset
        :type flag: boolean, default True
        """
        if flag:
            self._yAutoScale = True
        else:
            self._yAutoScale = False
        print("PlotBackend setYAxisAutoScale not implemented")

    def setYAxisLogarithmic(self, flag):
        """
        :param flag: If True, the left axis will use a log scale
        :type flag: boolean
        """
        print("PlotBackend setYAxisLogarithmic not implemented")

    def setZoomModeEnabled(self, flag=True, color=None):
        """
        Zoom and drawing cannot be simultaneously enabled.

        :param flag: If True, the user can zoom.
        :type flag: boolean, default True
        :param color: The color to use to draw the selection area.
                      Default 'black"
        :param color: The (optional) color to use to draw the selection area.
        :type color: string ("#RRGGBB") or 4 column unsigned byte array or
                     one of the predefined color names defined in Colors.py
        """
        if flag:
            self._zoomEnabled = True
            #cannot draw and zoom simultaneously
            self.setDrawModeEnabled(False)
        else:
            self._zoomEnabled = True
        print("PlotBackend setZoomModeEnabled not implemented")

    def showGrid(self, flag=True):
        """
        :param flag: If True, the grid will be shown.
        :type flag: boolean, default True
        """
        print("PlotBackend showGrid not implemented")

def main():
    import numpy
    from .Plot1D import Plot1D
    x = numpy.arange(100.)
    y = x * x
    plot = Plot1D()
    plot.addCurve(x, y, "dummy")
    plot.addCurve(x + 100, -x * x)
    print("X Limits = ", plot.getGraphXLimits())
    print("Y Limits = ", plot.getGraphYLimits())
    print("All curves = ", plot.getAllCurves())
    plot.removeCurve("dummy")
    print("All curves = ", plot.getAllCurves())

if __name__ == "__main__":
    main()