File: demo.py

package info (click to toggle)
wxpython4.0 4.2.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 232,540 kB
  • sloc: cpp: 958,937; python: 233,059; ansic: 150,441; makefile: 51,662; sh: 8,687; perl: 1,563; javascript: 584; php: 326; xml: 200
file content (1006 lines) | stat: -rw-r--r-- 38,574 bytes parent folder | download
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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
# -*- coding: utf-8 -*-
# pylint: disable=E1101, C0330, C0103
#   E1101: Module X has no Y member
#   C0330: Wrong continued indentation
#   C0103: Invalid attribute/variable/method name
"""
demo.py
=======

This is a demo showing some of the capabilities of the :mod:`wx.lib.plot`
package. It is intended to be run as a standalone script via::

  user@host:.../site-packages/wx/lib/plot$ python examples/demo.py

"""
__docformat__ = "restructuredtext en"

# Third Party
import wx
from wx.lib import plot as wxplot

# Needs NumPy
try:
    import numpy as np
except ImportError:
    msg = """
    This module requires the NumPy module, which could not be
    imported.  It probably is not installed (it's not part of the
    standard Python distribution). See the Numeric Python site
    (http://numpy.scipy.org) for information on downloading source or
    binaries, or just try `pip install numpy` and it will probably
    work."""
    raise ImportError("NumPy not found.\n" + msg)


# ---------------------------------------------------------------------------
### Drawing Functions
# ---------------------------------------------------------------------------
def _draw1Objects():
    """Sin, Cos, and Points"""
    # 100 points sin function, plotted as green circles
    data1 = 2. * np.pi * np.arange(-200, 200) / 200.
    data1.shape = (200, 2)
    data1[:, 1] = np.sin(data1[:, 0])
    markers1 = wxplot.PolyMarker(data1,
                                 legend='Green Markers',
                                 colour='green',
                                 marker='circle',
                                 size=1,
                                 )

    # 50 points cos function, plotted as red line and markers
    data1 = 2. * np.pi * np.arange(-100, 100) / 100.
    data1.shape = (100, 2)
    data1[:, 1] = np.cos(data1[:, 0])
    lines = wxplot.PolySpline(data1, legend='Red Line', colour='red')
    markers3 = wxplot.PolyMarker(data1,
                                 legend='Red Dot',
                                 colour='red',
                                 marker='circle',
                                 size=1,
                                 )

    # A few more points...
    pi = np.pi
    pts = [(0., 0.), (pi / 4., 1.), (pi / 2, 0.), (3. * pi / 4., -1)]
    markers2 = wxplot.PolyMarker(pts,
                                 legend='Cross Legend',
                                 colour='blue',
                                 marker='cross',
                                 )
    line2 = wxplot.PolyLine(pts, drawstyle='steps-post')

    return wxplot.PlotGraphics([markers1, lines, markers3, markers2, line2],
                               "Graph Title",
                               "X Axis",
                               "Y Axis",
                               )


def _draw2Objects():
    """Sin, Cos, Points, and lines between points"""
    # 100 points sin function, plotted as green dots
    data1 = 2. * np.pi * np.arange(200) / 200.
    data1.shape = (100, 2)
    data1[:, 1] = np.sin(data1[:, 0])
    line1 = wxplot.PolySpline(data1,
                              legend='Green Line',
                              colour='green',
                              width=6,
                              style=wx.PENSTYLE_DOT)

    # 25 points cos function, plotted as red dot-dash with steps.
    data1 = 2. * np.pi * np.arange(50) / 50.
    data1.shape = (25, 2)
    data1[:, 1] = np.cos(data1[:, 0])
    line2 = wxplot.PolyLine(data1,
                            legend='Red Line',
                            colour='red',
                            width=2,
                            style=wx.PENSTYLE_DOT_DASH,
                            drawstyle='steps-post',
                            )

    # data points for the 25pt cos function.
    pts2 = wxplot.PolyMarker(data1,
                             legend='Red Points',
                             colour='red',
                             size=1.5,
                             )

    # A few more points...
    pi = np.pi
    pts = [(0., 0.), (pi / 4., 1.), (pi / 2, 0.), (3. * pi / 4., -1)]
    markers1 = wxplot.PolyMarker(pts,
                                 legend='Cross Hatch Square',
                                 colour='blue',
                                 width=3,
                                 size=6,
                                 fillcolour='red',
                                 fillstyle=wx.CROSSDIAG_HATCH,
                                 marker='square',
                                 )
    marker_line = wxplot.PolyLine(pts,
                                  legend='Cross Hatch Square',
                                  colour='blue',
                                  width=3,
                                  )

    return wxplot.PlotGraphics([markers1, line1, line2, pts2, marker_line],
                               "Big Markers with Different Line Styles")


def _draw3Objects():
    """Various Marker Types"""
    markerList = ['circle', 'dot', 'square', 'triangle', 'triangle_down',
                  'cross', 'plus', 'circle']
    m = []
    for i in range(len(markerList)):
        m.append(wxplot.PolyMarker([(2 * i + .5, i + .5)],
                                   legend=markerList[i],
                                   colour='blue',
                                   marker=markerList[i])
                                   )
    return wxplot.PlotGraphics(m,
                               title="Selection of Markers",
                               xLabel="Minimal Axis",
                               yLabel="No Axis")


def _draw4Objects():
    """25,000 point line and markers"""
    # Points
    data1 = np.random.normal(loc=7.5e5, scale=70000, size=50000)
    data1.shape = (25000, 2)
    markers2 = wxplot.PolyMarker(data1,
                                 legend='Dots',
                                 colour='blue',
                                 marker='square',
                                 size=1,
                                 )

    # Line
    data1 = np.arange(5e5, 1e6, 10)
    data1.shape = (25000, 2)
    line1 = wxplot.PolyLine(data1, legend='Wide Line', colour='green', width=4)

    return wxplot.PlotGraphics([markers2, line1],
                               "25,000 Points",
                               "Value X",
                               "")


def _draw5Objects():
    """Empty graph with axes but no points"""
    points = []
    line1 = wxplot.PolyLine(points,
                            legend='Wide Line',
                            colour='green',
                            width=5)
    return wxplot.PlotGraphics([line1],
                               "Empty Plot With Just Axes",
                               "Value X",
                               "Value Y")


def _draw6Objects():
    """Faking a Bar graph"""
    points1 = [(1, 0), (1, 10)]
    line1 = wxplot.PolyLine(points1, colour='green', legend='Feb.', width=10)
    points1g = [(2, 0), (2, 4)]
    line1g = wxplot.PolyLine(points1g, colour='red', legend='Mar.', width=10)
    points1b = [(3, 0), (3, 6)]
    line1b = wxplot.PolyLine(points1b, colour='blue', legend='Apr.', width=10)

    points2 = [(4, 0), (4, 12)]
    line2 = wxplot.PolyLine(points2, colour='Yellow', legend='May', width=10)
    points2g = [(5, 0), (5, 8)]
    line2g = wxplot.PolyLine(points2g,
                             colour='orange',
                             legend='June',
                             width=10)
    points2b = [(6, 0), (6, 4)]
    line2b = wxplot.PolyLine(points2b, colour='brown', legend='July', width=10)

    return wxplot.PlotGraphics([line1, line1g, line1b, line2, line2g, line2b],
                               "Bar Graph - (Turn on Grid, Legend)",
                               "Months",
                               "Number of Students")


def _draw7Objects():
    """Log10 on both axes"""
    x = np.arange(-1000, 1000, 1)
    y1 = 4.5 * x ** 2
    y2 = 2.2 * x ** 3
    points1 = np.transpose([x, y1])
    points2 = np.transpose([x, y2])
    line1 = wxplot.PolyLine(points1,
                            legend='quadratic',
                            colour='blue',
                            width=1)
    line2 = wxplot.PolyLine(points2, legend='cubic', colour='red', width=1)
    return wxplot.PlotGraphics([line1, line2],
                               "double log plot",
                               "Value X",
                               "Value Y")


def _draw8Objects():
    """
    Box plot
    """
    data1 = np.array([np.NaN, 337, 607, 583, 512, 531, 558, 381, 621, 574,
                      538, 577, 679, 415, 454, 417, 635, 319, 350, 183,
                      863, 337, 607, 583, 512, 531, 558, 381, 621, 574,
                      538, 577, 679, 415, 454, 417, 635, 319, 350, 97])
    data2 = np.array([912, 337, 607, 583, 512, 531, 558, 381, 621, 574,
                      538, 532, 829, 82, 454, 417, 635, 319, 350, 183,
                      863, 337, 607, 583, 512, 531, 558, 866, 621, 574,
                      538, 577, 679, 415, 326, 417, 635, 319, 350, 97])

    data2 = data2 * 0.9

    data1 = np.array([(0, x) for x in data1])
    data2 = np.array([(1, x) for x in data2])

    data3 = np.random.gamma(2, 2, 500) * 30 + 100
    data3 = np.array([(2, x) for x in data3])

    boxplot = wxplot.BoxPlot(data1, legend="0.0: Weights")
    boxplot2 = wxplot.BoxPlot(data2, legend="1.0: Heights")
    boxplot3 = wxplot.BoxPlot(data3, legend="2.0: GammaDistribution")
    return wxplot.PlotGraphics([boxplot, boxplot2, boxplot3],
                               "Box Plot",
                               "",
                               "Value")

def _draw9Objects():
    """
    Histogram

    The following must be true:
    len(bspec) = len(hist_data) + 1
    """

    data = 2.25 * np.random.randn(50) + 3
    heights, bins = np.histogram(data, bins=10)

    hist_fixed_binsize = wxplot.PolyHistogram(heights, bins)

    # Bins can also be arbitrary widths:
    hist_variable_binsize = wxplot.PolyHistogram(
        [2, 3, 4, 6, 3],
        [18, 19, 22, 25, 26, 27],
        fillcolour=wx.BLUE,
        edgewidth=2,
        edgecolour=wx.RED,
    )

    return wxplot.PlotGraphics(
        [hist_fixed_binsize, hist_variable_binsize],
        "Histogram with fixed binsize (left) and variable binsize (right)",
        "Value",
        "Count",
    )


def _draw10Objects():
    """
    A real bar graph
    """
    bar_height = np.array([1, 5, 8, 16, 12, 15, 18, 23, 4, 7, 9, 6])
    bar_location = np.array([0, 2, 4, 6, 8, 10, 11, 12, 16, 20, 30])
    data = list(zip(bar_location, bar_height))
    bars = [wxplot.PolyBars(data)]

    return wxplot.PlotGraphics(bars, "Histogram", "XValue", "Count")


# ---------------------------------------------------------------------------
### Demo Application
# ---------------------------------------------------------------------------
class PlotDemoApp(object):
    def __init__(self):
        self.app = wx.App()
        self.frame = PlotDemoMainFrame(None, -1, "PlotCanvas")
        self.frame.Show(True)
        self.app.MainLoop()


class PlotDemoMainFrame(wx.Frame):
    # -----------------------------------------------------------------------
    ### UI Initialization
    # -----------------------------------------------------------------------
    def __init__(self, parent, wxid, title):
        wx.Frame.__init__(self, parent, wxid, title,
                          wx.DefaultPosition, (800, 600))

        # Now Create the menu bar and items
        self.mainmenu = wx.MenuBar()

        self._init_file_menu()
        self._init_plot_menu()
        self._init_options_menu()
        self._init_help_menu()

        self.SetMenuBar(self.mainmenu)

        # A status bar to tell people what's happening
        self.CreateStatusBar(1)

        self.client = wxplot.PlotCanvas(self)
        # define the function for drawing pointLabels
#        self.client.SetPointLabelFunc(self.DrawPointLabel)
        self.client.pointLabelFunc = self.DrawPointLabel
        # Create mouse event for showing cursor coords in status bar
        self.client.canvas.Bind(wx.EVT_LEFT_DOWN, self.OnMouseLeftDown)
        # Show closest point when enabled
        self.client.canvas.Bind(wx.EVT_MOTION, self.OnMotion)

        self.OnPlotDraw1(None)

        wx.CallAfter(wx.MessageBox,
                     "Various plot types can be shown using the Plot menu. " +
                     "Check out the Options menu too.",
                     "wx.lib.plot Demo")


    def _init_file_menu(self):
        """ Create the "File" menu items. """
        menu = wx.Menu()
        menu.Append(200, 'Page Setup...', 'Setup the printer page')
        self.Bind(wx.EVT_MENU, self.OnFilePageSetup, id=200)
        menu.Append(201, 'Print Preview...', 'Show the current plot on page')
        self.Bind(wx.EVT_MENU, self.OnFilePrintPreview, id=201)
        menu.Append(202, 'Print...', 'Print the current plot')
        self.Bind(wx.EVT_MENU, self.OnFilePrint, id=202)
        menu.Append(203, 'Save Plot...', 'Save current plot')
        self.Bind(wx.EVT_MENU, self.OnSaveFile, id=203)
        menu.Append(wx.ID_EXIT, 'E&xit', 'Enough of this already!')
        self.Bind(wx.EVT_MENU, self.OnFileExit, id=wx.ID_EXIT)
        self.mainmenu.Append(menu, '&File')

    def _init_plot_menu(self):
        """ Create the "Plot" menu items. """
        menu = wx.Menu()
        menu.Append(206, 'Draw1 - sin, cos',
                    'Draw Sin and Cos curves')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw1, id=206)
        menu.Append(207, 'Draw2 - sin, cos, large joined markers',
                    'Draw Sin and Cos curves with some large joined makers')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw2, id=207)
        menu.Append(208, 'Draw3 - various markers',
                    'Demo various markers')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw3, id=208)
        menu.Append(209, 'Draw4 - 25k pts',
                    'Example of drawing many points quickly')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw4, id=209)
        menu.Append(210, 'Draw5 - empty plot',
                    'An empty plot')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw5, id=210)
        menu.Append(260, 'Draw6 - fake bar graph via lines',
                    'Fake a bar graph by using lines.')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw6, id=260)
        menu.Append(261, 'Draw7 - log-log',
                    'Plot a Log-Log graph')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw7, id=261)
        menu.Append(262, 'Draw8 - Box Plots',
                    'Show off some box plots')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw8, id=262)
        menu.Append(263, 'Draw9 - Histogram',
                    'Plot a histogram')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw9, id=263)
        menu.Append(264, 'Draw10 - real bar graph',
                    'Plot a real bar chart (not faked with lines)')
        self.Bind(wx.EVT_MENU, self.OnPlotDraw10, id=264)

        menu.AppendSeparator()

        menu.Append(211, '&Redraw', 'Redraw plots')
        self.Bind(wx.EVT_MENU, self.OnPlotRedraw, id=211)
        menu.Append(212, '&Clear', 'Clear canvas')
        self.Bind(wx.EVT_MENU, self.OnPlotClear, id=212)
        menu.Append(213, '&Scale', 'Scale canvas')
        self.Bind(wx.EVT_MENU, self.OnPlotScale, id=213)

        menu.AppendSeparator()

        menu.Append(225, 'Scroll Up 1', 'Move View Up 1 Unit')
        self.Bind(wx.EVT_MENU, self.OnScrUp, id=225)
        menu.Append(230, 'Scroll Rt 2', 'Move View Right 2 Units')
        self.Bind(wx.EVT_MENU, self.OnScrRt, id=230)
        menu.Append(235, '&Plot Reset', 'Reset to original plot')
        self.Bind(wx.EVT_MENU, self.OnReset, id=235)

        self.mainmenu.Append(menu, '&Plot')


    def _init_options_menu(self):
        """ Create the "Options" menu items. """
        menu = wx.Menu()

        menu.Append(214, 'Enable &Zoom',
                    'Enable Mouse Zoom', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableZoom, id=214)

        menu.Append(217, 'Enable &Drag',
                    'Activates dragging mode', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableDrag, id=217)

        item = menu.Append(-1, 'Enable &Scrollbars (if needed)',
                    'Enable Scrollbars (if needed)', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableScrollbars, item)

        menu.Append(222, 'Enable &Point Label',
                    'Show Closest Point', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnablePointLabel, id=222)

        menu.Append(223, 'Enable &Anti-Aliasing',
                    'Smooth output', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableAntiAliasing, id=223)

        menu.Append(224, 'Enable &High-Resolution AA',
                    'Draw in higher resolution', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableHiRes, id=224)

        menu.AppendSeparator()

        menu.Append(226, 'Enable Center Lines',
                    'Draw center lines', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableCenterLines, id=226)

        menu.Append(227, 'Enable Diagonal Lines',
                    'Draw diagonal lines', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableDiagonals, id=227)

        menu.Append(220, 'Enable &Legend',
                    'Turn on Legend', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableLegend, id=220)

        ### SubMenu for Grid
        submenu = wx.Menu()
        self.gridSubMenu = submenu

        submenu.AppendCheckItem(2151, "X Gridlines", "Enable X gridlines")
        submenu.AppendCheckItem(2152, "Y Gridlines", "Enable Y gridlines")
        submenu.AppendCheckItem(2153, "All Gridlines", "Enable All gridlines")
        submenu.Check(2151, True)
        submenu.Check(2152, True)
        submenu.Check(2153, True)

        self.Bind(wx.EVT_MENU, self.OnEnableGridX, id=2151)
        self.Bind(wx.EVT_MENU, self.OnEnableGridY, id=2152)
        self.Bind(wx.EVT_MENU, self.OnEnableGridAll, id=2153)

        menu.AppendSubMenu(submenu, 'Enable Grid', 'Turn on Grid')

        ### SubMenu for Axes
        submenu = wx.Menu()
        submenu_items = ("Bottom", "Left", "Top", "Right",
                         "Bottom+Left", "All")
        self.axesSubMenu = submenu
        for _i, item in enumerate(submenu_items, 2401):
            submenu.AppendCheckItem(_i, item, "Enables {} axis".format(item))
            submenu.Check(_i, True)

        self.Bind(wx.EVT_MENU, self.OnEnableAxesBottom, id=2401)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesLeft, id=2402)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesTop, id=2403)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesRight, id=2404)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesBottomLeft, id=2405)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesAll, id=2406)

        menu.AppendSubMenu(submenu, 'Enable Axes', 'Enables the display of the Axes')

        submenu = wx.Menu()
        submenu_items = ("Bottom", "Left", "Top", "Right")
        help_txt = "Enables {} axis values"
        self.axesValuesSubMenu = submenu
        for _i, item in enumerate(submenu_items, 2451):
            submenu.AppendCheckItem(_i, item, help_txt.format(item))

        submenu.Check(2451, True)
        submenu.Check(2452, True)
        submenu.Check(2453, False)
        submenu.Check(2454, False)

        self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesBottom, id=2451)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesLeft, id=2452)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesTop, id=2453)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesValuesRight, id=2454)

        menu.AppendSubMenu(submenu, 'Enable Axes Values', 'Enables the display of the axes values')

        submenu = wx.Menu()
        submenu_items = ("Bottom", "Left", "Top", "Right",
                         "Bottom+Left", "All")
        help_txt = "Enables {} ticks"
        self.ticksSubMenu = submenu
        for _i, item in enumerate(submenu_items, 2501):
            submenu.AppendCheckItem(_i, item, help_txt.format(item))

        submenu.Check(2501, False)
        submenu.Check(2502, False)
        submenu.Check(2503, False)
        submenu.Check(2504, False)

        self.Bind(wx.EVT_MENU, self.OnEnableTicksBottom, id=2501)
        self.Bind(wx.EVT_MENU, self.OnEnableTicksLeft, id=2502)
        self.Bind(wx.EVT_MENU, self.OnEnableTicksTop, id=2503)
        self.Bind(wx.EVT_MENU, self.OnEnableTicksRight, id=2504)
        self.Bind(wx.EVT_MENU, self.OnEnableTicksBottomLeft, id=2505)
        self.Bind(wx.EVT_MENU, self.OnEnableTicksAll, id=2506)

        menu.AppendSubMenu(submenu, 'Enable Ticks','Enables the display of the ticks')

        menu.Append(255, 'Enable Plot Title',
                    'Enables the plot title', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnablePlotTitle, id=255)
        menu.Check(255, True)

        menu.Append(270, 'Enable Axes Labels',
                    'Enables the X and Y axes labels', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnEnableAxesLabels, id=270)
        menu.Check(270, True)

        menu.Append(271, 'Enable Log-Y',
                    'Changes the Y axis to log10 scale', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnLogY, id=271)
        menu.Append(272, 'Enable Log-X',
                    'Changes the X axis to log10 scale', kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnLogX, id=272)

        menu.Append(273, 'Enable Abs(X)',
                    'Applies absolute value transform to X axis',
                    kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnAbsX, id=273)
        menu.Append(274, 'Enable Abs(Y)',
                    'Applies absolute value transform to Y axis',
                    kind=wx.ITEM_CHECK)
        self.Bind(wx.EVT_MENU, self.OnAbsY, id=274)

        menu.AppendSeparator()

        menu.Append(231, 'Set Gray Background',
                    'Change background colour to gray')
        self.Bind(wx.EVT_MENU, self.OnBackgroundGray, id=231)
        menu.Append(232, 'Set &White Background',
                    'Change background colour to white')
        self.Bind(wx.EVT_MENU, self.OnBackgroundWhite, id=232)
        menu.Append(233, 'Set Red Label Text',
                    'Change label text colour to red')
        self.Bind(wx.EVT_MENU, self.OnForegroundRed, id=233)
        menu.Append(234, 'Set &Black Label Text',
                    'Change label text colour to black')
        self.Bind(wx.EVT_MENU, self.OnForegroundBlack, id=234)

        self.mainmenu.Append(menu, '&Options')

        self.plot_options_menu = menu

    def _init_help_menu(self):
        """ Create the "Help" menu items. """
        menu = wx.Menu()
        menu.Append(wx.ID_ABOUT, '&About', 'About this thing...')
        self.Bind(wx.EVT_MENU, self.OnHelpAbout, id=wx.ID_ABOUT)
        self.mainmenu.Append(menu, '&Help')

    # -----------------------------------------------------------------------
    ### Event Handling
    # -----------------------------------------------------------------------


    def OnMouseLeftDown(self, event):
        s = "Left Mouse Down at Point: (%.4f, %.4f)" % self.client.GetXY(
            event)
        self.SetStatusText(s)
        event.Skip()  # allows plotCanvas OnMouseLeftDown to be called

    def OnMotion(self, event):
        # show closest point (when enbled)
        if self.client.enablePointLabel:
            # make up dict with info for the pointLabel
            # I've decided to mark the closest point on the closest curve
            dlst = self.client.GetClosestPoint(
                self.client.GetXY(event),
                pointScaled=True,
            )
            if dlst != []:  # returns [] if none
                curveNum, legend, pIndex, pointXY, scaledXY, distance = dlst
                # make up dictionary to pass to my user function (see
                # DrawPointLabel)
                mDataDict = {"curveNum": curveNum,
                             "legend": legend,
                             "pIndex": pIndex,
                             "pointXY": pointXY,
                             "scaledXY": scaledXY}
                # pass dict to update the pointLabel
                self.client.UpdatePointLabel(mDataDict)
        event.Skip()  # go to next handler

    def OnFilePageSetup(self, event):
        self.client.PageSetup()

    def OnFilePrintPreview(self, event):
        self.client.PrintPreview()

    def OnFilePrint(self, event):
        self.client.Printout()

    def OnSaveFile(self, event):
        self.client.SaveFile()

    def OnFileExit(self, event):
        self.Close()


    # -----------------------------------------------------------------------
    ### PlotDraw Events
    # -----------------------------------------------------------------------
    def OnPlotDraw1(self, event):
        """ Sin, Cos, and Points """
        self.resetDefaults()
        self.client.Draw(_draw1Objects())

    def OnPlotDraw2(self, event):
        """ Sin, Cos, Points, and lines between points """
        self.resetDefaults()
        self.client.Draw(_draw2Objects())

    def OnPlotDraw3(self, event):
        """ Various Marker Types """
        self.resetDefaults()
        self.client.SetFont(wx.Font(10,
                                    wx.FONTFAMILY_SCRIPT,
                                    wx.FONTSTYLE_NORMAL,
                                    wx.FONTWEIGHT_NORMAL)
                            )
        self.client.fontSizeAxis = 20
        self.client.fontSizeLegend = 12
        self.client.xSpec = 'min'
        self.client.ySpec = 'none'
        self.client.Draw(_draw3Objects())

    def OnPlotDraw4(self, event):
        """ 25,000 point line and markers """
        self.resetDefaults()
        drawObj = _draw4Objects()
        self.client.Draw(drawObj)
# profile
#        start = _time.perf_counter()
# for x in range(10):
# self.client.Draw(drawObj)
##        print("10x of Draw4 took: %f sec."%(_time.perf_counter() - start))
# profile end

    def OnPlotDraw5(self, event):
        """ Empty plot with just axes """
        self.resetDefaults()
        drawObj = _draw5Objects()
        # make the axis X= (0,5), Y=(0,10)
        # (default with None is X= (-1,1), Y= (-1,1))
        self.client.Draw(drawObj, xAxis=(0, 5), yAxis=(0, 10))

    def OnPlotDraw6(self, event):
        """ Bar Graph Example """
        self.resetDefaults()
        # self.client.SetEnableLegend(True)   #turn on Legend
        # self.client.SetEnableGrid(True)     #turn on Grid
        self.client.xSpec = 'none'
        self.client.ySpec = 'auto'
        self.client.Draw(_draw6Objects(), xAxis=(0, 7))

    def OnPlotDraw7(self, event):
        """ log scale example """
        self.resetDefaults()
        self.plot_options_menu.Check(271, True)
        self.plot_options_menu.Check(272, True)
        self.client.logScale = (True, True)
        self.client.Draw(_draw7Objects())

    def OnPlotDraw8(self, event):
        """ Box Plot example """
        self.resetDefaults()
        self.client.Draw(_draw8Objects())

    def OnPlotDraw9(self, event):
        """ Histogram example """
        self.resetDefaults()
        self.client.Draw(_draw9Objects())

    def OnPlotDraw10(self, event):
        """ Bar Chart example """
        self.resetDefaults()
        self.client.Draw(_draw10Objects())

    def OnPlotRedraw(self, event):
        self.client.Redraw()

    def OnPlotClear(self, event):
        self.client.Clear()

    def OnPlotScale(self, event):
        if self.client.last_draw is not None:
            graphics, xAxis, yAxis = self.client.last_draw
            self.client.Draw(graphics, (1, 3.05), (0, 1))

    # -----------------------------------------------------------------------
    ### Other Events
    # -----------------------------------------------------------------------
    def OnScrUp(self, event):
        self.client.ScrollUp(1)

    def OnScrRt(self, event):
        self.client.ScrollRight(2)

    def OnReset(self, event):
        self.client.Reset()

    def OnHelpAbout(self, event):
        from wx.lib.dialogs import ScrolledMessageDialog
        about = ScrolledMessageDialog(self, __doc__, "About...")
        about.ShowModal()

    def OnBackgroundGray(self, event):
        self.client.SetBackgroundColour("#CCCCCC")
        self.client.Redraw()

    def OnBackgroundWhite(self, event):
        self.client.SetBackgroundColour("white")
        self.client.Redraw()

    def OnForegroundRed(self, event):
        self.client.SetForegroundColour("red")
        self.client.Redraw()

    def OnForegroundBlack(self, event):
        self.client.SetForegroundColour("black")
        self.client.Redraw()

    # -----------------------------------------------------------------------
    ### Enable Grid Events
    # -----------------------------------------------------------------------
    def _checkOtherGridMenuItems(self):
        """ check or uncheck the submenu items """
        self.gridSubMenu.Check(2151, self.client.enableGrid[0])
        self.gridSubMenu.Check(2152, self.client.enableGrid[1])
        self.gridSubMenu.Check(2153, all(self.client.enableGrid))

    def OnEnableGridX(self, event):
        old = self.client.enableGrid
        self.client.enableGrid = (event.IsChecked(), old[1])
        self._checkOtherGridMenuItems()

    def OnEnableGridY(self, event):
        old = self.client.enableGrid
        self.client.enableGrid = (old[0], event.IsChecked())
        self._checkOtherGridMenuItems()

    def OnEnableGridAll(self, event):
        self.client.enableGrid = event.IsChecked()
        self._checkOtherGridMenuItems()
        self.gridSubMenu.Check(2151, event.IsChecked())
        self.gridSubMenu.Check(2152, event.IsChecked())

    # -----------------------------------------------------------------------
    ### Enable Axes Events
    # -----------------------------------------------------------------------
    def _checkOtherAxesMenuItems(self):
        """ check or uncheck the submenu items """
        self.axesSubMenu.Check(2401, self.client.enableAxes[0])
        self.axesSubMenu.Check(2402, self.client.enableAxes[1])
        self.axesSubMenu.Check(2403, self.client.enableAxes[2])
        self.axesSubMenu.Check(2404, self.client.enableAxes[3])
        self.axesSubMenu.Check(2405, all(self.client.enableAxes[:2]))
        self.axesSubMenu.Check(2406, all(self.client.enableAxes))

    def OnEnableAxesBottom(self, event):
        old = self.client.enableAxes
        self.client.enableAxes = (event.IsChecked(), old[1], old[2], old[3])
        self._checkOtherAxesMenuItems()

    def OnEnableAxesLeft(self, event):
        old = self.client.enableAxes
        self.client.enableAxes = (old[0], event.IsChecked(), old[2], old[3])
        self._checkOtherAxesMenuItems()

    def OnEnableAxesTop(self, event):
        old = self.client.enableAxes
        self.client.enableAxes = (old[0], old[1], event.IsChecked(), old[3])
        self._checkOtherAxesMenuItems()

    def OnEnableAxesRight(self, event):
        old = self.client.enableAxes
        self.client.enableAxes = (old[0], old[1], old[2], event.IsChecked())
        self._checkOtherAxesMenuItems()

    def OnEnableAxesBottomLeft(self, event):
        checked = event.IsChecked()
        old = self.client.enableAxes
        self.client.enableAxes = (checked, checked, old[2], old[3])
        self._checkOtherAxesMenuItems()

    def OnEnableAxesAll(self, event):
        checked = event.IsChecked()
        self.client.enableAxes = (checked, checked, checked, checked)
        self._checkOtherAxesMenuItems()

    # -----------------------------------------------------------------------
    ### Enable Ticks Events
    # -----------------------------------------------------------------------
    def _checkOtherTicksMenuItems(self):
        """ check or uncheck the submenu items """
        self.ticksSubMenu.Check(2501, self.client.enableTicks[0])
        self.ticksSubMenu.Check(2502, self.client.enableTicks[1])
        self.ticksSubMenu.Check(2503, self.client.enableTicks[2])
        self.ticksSubMenu.Check(2504, self.client.enableTicks[3])
        self.ticksSubMenu.Check(2505, all(self.client.enableTicks[:2]))
        self.ticksSubMenu.Check(2506, all(self.client.enableTicks))

    def OnEnableTicksBottom(self, event):
        old = self.client.enableTicks
        self.client.enableTicks = (event.IsChecked(), old[1],
                                   old[2], old[3])
        self._checkOtherTicksMenuItems()

    def OnEnableTicksLeft(self, event):
        old = self.client.enableTicks
        self.client.enableTicks = (old[0], event.IsChecked(),
                                   old[2], old[3])
        self._checkOtherTicksMenuItems()

    def OnEnableTicksTop(self, event):
        old = self.client.enableTicks
        self.client.enableTicks = (old[0], old[1],
                                   event.IsChecked(), old[3])
        self._checkOtherTicksMenuItems()

    def OnEnableTicksRight(self, event):
        old = self.client.enableTicks
        self.client.enableTicks = (old[0], old[1],
                                   old[2], event.IsChecked())
        self._checkOtherTicksMenuItems()

    def OnEnableTicksBottomLeft(self, event):
        checked = event.IsChecked()
        old = self.client.enableTicks
        self.client.enableTicks = (checked, checked, old[2], old[3])
        self._checkOtherTicksMenuItems()

    def OnEnableTicksAll(self, event):
        checked = event.IsChecked()
        self.client.enableTicks = tuple([checked] * 4)
        self._checkOtherTicksMenuItems()

    # -----------------------------------------------------------------------
    ### Enable AxesValues Events
    # -----------------------------------------------------------------------
    def OnEnableAxesValuesBottom(self, event):
        old = self.client.enableAxesValues
        self.client.enableAxesValues = (event.IsChecked(), old[1],
                                        old[2], old[3])

    def OnEnableAxesValuesLeft(self, event):
        old = self.client.enableAxesValues
        self.client.enableAxesValues = (old[0], event.IsChecked(),
                                        old[2], old[3])

    def OnEnableAxesValuesTop(self, event):
        old = self.client.enableAxesValues
        self.client.enableAxesValues = (old[0], old[1],
                                        event.IsChecked(), old[3])

    def OnEnableAxesValuesRight(self, event):
        old = self.client.enableAxesValues
        self.client.enableAxesValues = (old[0], old[1],
                                        old[2], event.IsChecked())

    # -----------------------------------------------------------------------
    ### Other Enable Events
    # -----------------------------------------------------------------------
    def OnEnableZoom(self, event):
        self.client.enableZoom = event.IsChecked()
        if self.mainmenu.IsChecked(217):
            self.mainmenu.Check(217, False)

    def OnEnableDrag(self, event):
        self.client.enableDrag = event.IsChecked()
        if self.mainmenu.IsChecked(214):
            self.mainmenu.Check(214, False)

    def OnEnableScrollbars(self, event):
        self.client.showScrollbars = event.IsChecked()

    def OnEnableLegend(self, event):
        self.client.enableLegend = event.IsChecked()

    def OnEnablePointLabel(self, event):
        self.client.enablePointLabel = event.IsChecked()

    def OnEnableAntiAliasing(self, event):
        self.client.enableAntiAliasing = event.IsChecked()

    def OnEnableHiRes(self, event):
        self.client.enableHiRes = event.IsChecked()

    def OnEnablePlotTitle(self, event):
        self.client.enablePlotTitle = event.IsChecked()

    def OnEnableAxesLabels(self, event):
        self.client.enableAxesLabels = event.IsChecked()

    def OnEnableCenterLines(self, event):
        self.client.enableCenterLines = event.IsChecked()

    def OnEnableDiagonals(self, event):
        self.client.enableDiagonals = event.IsChecked()

    def OnLogX(self, event):
        self.client.logScale = (event.IsChecked(), self.client.logScale[1])
        self.client.Redraw()

    def OnLogY(self, event):
        self.client.logScale = (self.client.logScale[0], event.IsChecked())
        self.client.Redraw()

    def OnAbsX(self, event):
        self.client.absScale = (event.IsChecked(), self.client.absScale[1])
        self.client.Redraw()

    def OnAbsY(self, event):
        self.client.absScale = (self.client.absScale[0], event.IsChecked())
        self.client.Redraw()

    def resetDefaults(self):
        """Just to reset the fonts back to the PlotCanvas defaults"""
        self.client.SetFont(wx.Font(10,
                                    wx.FONTFAMILY_SWISS,
                                    wx.FONTSTYLE_NORMAL,
                                    wx.FONTWEIGHT_NORMAL)
                            )
        self.client.fontSizeAxis = 10
        self.client.fontSizeLegend = 7
        self.client.logScale = (False, False)
        self.client.xSpec = 'auto'
        self.client.ySpec = 'auto'

    def DrawPointLabel(self, dc, mDataDict):
        """
        This is the function that defines how the pointLabels are plotted

        :param dc: DC that will be passed
        :param mDataDict: Dictionary of data that you want to use
                          for the pointLabel

        As an example I have decided I want a box at the curve point
        with some text information about the curve plotted below.
        Any wxDC method can be used.

        """
        dc.SetPen(wx.Pen(wx.BLACK))
        dc.SetBrush(wx.Brush(wx.BLACK, wx.BRUSHSTYLE_SOLID))

        sx, sy = mDataDict["scaledXY"]  # scaled x,y of closest point
        # 10by10 square centered on point
        dc.DrawRectangle(int(sx - 5), int(sy - 5), 10, 10)
        px, py = mDataDict["pointXY"]
        cNum = mDataDict["curveNum"]
        pntIn = mDataDict["pIndex"]
        legend = mDataDict["legend"]
        # make a string to display
        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" % (
            cNum, legend, px, py, pntIn)
        dc.DrawText(s, int(sx), int(sy + 1))


def run_demo():
    """
    Run the :mod:`wx.lib.plot` demo application.
    """
    PlotDemoApp()


if __name__ == '__main__':
    run_demo()