mwxlib 1.6.10__py3-none-any.whl → 1.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mwxlib might be problematic. Click here for more details.

mwx/matplot2lg.py CHANGED
@@ -18,7 +18,7 @@ from .matplot2 import NORMAL, MARK, LINE, REGION
18
18
 
19
19
 
20
20
  class LinePlot(MatplotPanel):
21
- """Line plot 1D base panel
21
+ """Line plot 1D base panel.
22
22
 
23
23
  region : selected range (l,r) on the plot
24
24
  """
@@ -45,7 +45,7 @@ class LinePlot(MatplotPanel):
45
45
  },
46
46
  })
47
47
  self.modeline.Show(0)
48
-
48
+
49
49
  def clear(self):
50
50
  MatplotPanel.clear(self)
51
51
 
@@ -64,14 +64,14 @@ class LinePlot(MatplotPanel):
64
64
  #<matplotlib.patches.Rectangle>
65
65
  self.__vspan = self.axes.axvspan(0, 0,
66
66
  color='none', ls='dashed', lw=1, ec='black', visible=0, zorder=2)
67
-
67
+
68
68
  ## the limit for dragging region
69
69
  boundary = None
70
-
70
+
71
71
  @property
72
72
  def region(self):
73
73
  return self.__region
74
-
74
+
75
75
  @region.setter
76
76
  def region(self, v):
77
77
  if v is not None:
@@ -95,11 +95,11 @@ class LinePlot(MatplotPanel):
95
95
  self.__vspan.set_visible(0)
96
96
  self.handler('region_unset', self.frame)
97
97
  self.__region = v
98
-
98
+
99
99
  @region.deleter
100
100
  def region(self):
101
101
  self.region = None
102
-
102
+
103
103
  def annotate(self):
104
104
  for art in self.__annotations:
105
105
  art.remove()
@@ -126,11 +126,11 @@ class LinePlot(MatplotPanel):
126
126
  _A(None, (a,y), (b,y), textcoords='data', arrowstyle='<->'),
127
127
  p,
128
128
  ]
129
-
129
+
130
130
  ## --------------------------------
131
131
  ## Motion/Drag actions (override)
132
132
  ## --------------------------------
133
-
133
+
134
134
  def region_test(self, evt):
135
135
  if self.region is not None:
136
136
  x = evt.xdata
@@ -140,11 +140,11 @@ class LinePlot(MatplotPanel):
140
140
  elif a-d < x < a+d: return 2 # left-edge
141
141
  elif b-d < x < b+d: return 3 # right-edge
142
142
  else: return 0 # outside
143
-
143
+
144
144
  def OnDraw(self, evt):
145
145
  """Called before canvas.draw."""
146
146
  self.annotate()
147
-
147
+
148
148
  def OnMotion(self, evt):
149
149
  MatplotPanel.OnMotion(self, evt)
150
150
 
@@ -155,11 +155,11 @@ class LinePlot(MatplotPanel):
155
155
  self.set_wxcursor(wx.CURSOR_SIZEWE) # on-edge
156
156
  else:
157
157
  self.set_wxcursor(wx.CURSOR_ARROW) # outside or None
158
-
158
+
159
159
  def OnDragLock(self, evt):
160
160
  self.__lastpoint = evt.xdata
161
161
  self.__selection = self.region_test(evt)
162
-
162
+
163
163
  def OnDragBegin(self, evt):
164
164
  v = self.__selection
165
165
  if v == 1:
@@ -172,7 +172,7 @@ class LinePlot(MatplotPanel):
172
172
  self.__lastpoint = self.region[0] # set origin left
173
173
  else:
174
174
  self.set_wxcursor(wx.CURSOR_SIZEWE) # outside
175
-
175
+
176
176
  def OnDragMove(self, evt):
177
177
  x = evt.xdata
178
178
  if self.__selection != 1:
@@ -198,10 +198,10 @@ class LinePlot(MatplotPanel):
198
198
  else:
199
199
  self.message("- No region.") #<FSM logic-error>
200
200
  self.draw()
201
-
201
+
202
202
  def OnDragEnd(self, evt):
203
203
  self.set_wxcursor(wx.CURSOR_ARROW)
204
-
204
+
205
205
  def OnEscapeSelection(self, evt):
206
206
  MatplotPanel.OnEscapeSelection(self, evt)
207
207
 
@@ -211,7 +211,7 @@ class LinePlot(MatplotPanel):
211
211
 
212
212
 
213
213
  class Histogram(LinePlot):
214
- """LinePlot panel for histogram (Multi-graph : Single-frame)
214
+ """LinePlot panel for histogram (Multi-graph : Single-frame).
215
215
 
216
216
  frame.image <uint8> (buffer ではない) を参照して,ヒストグラムをプロットする
217
217
  常に整数ビット画像となるので,高速なビンづめ法で計算する
@@ -240,12 +240,12 @@ class Histogram(LinePlot):
240
240
  self.modeline.Show(0)
241
241
 
242
242
  self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
243
-
243
+
244
244
  def OnDestroy(self, evt):
245
245
  for graph in self.__graphs:
246
246
  self.detach(graph)
247
247
  evt.Skip()
248
-
248
+
249
249
  def clear(self):
250
250
  LinePlot.clear(self)
251
251
 
@@ -258,23 +258,23 @@ class Histogram(LinePlot):
258
258
  #<matplotlib.patches.Polygon>
259
259
  self.__fil = patches.Polygon([(0,0)], color='c', alpha=1)
260
260
  self.axes.add_patch(self.__fil)
261
-
261
+
262
262
  def attach(self, *graphs):
263
263
  for graph in graphs:
264
264
  if graph not in self.__graphs:
265
265
  self.__graphs.append(graph)
266
266
  graph.handler.append(self.context)
267
-
267
+
268
268
  def detach(self, *graphs):
269
269
  for graph in graphs:
270
270
  if graph in self.__graphs:
271
271
  self.__graphs.remove(graph)
272
272
  graph.handler.remove(self.context)
273
-
273
+
274
274
  @property
275
275
  def boundary(self):
276
276
  return [0,255]
277
-
277
+
278
278
  def calc(self, frame):
279
279
  BINS = 256
280
280
  img = frame.image
@@ -288,7 +288,7 @@ class Histogram(LinePlot):
288
288
  hist, bins = np.histogram(img, BINS)
289
289
  bins = np.linspace(img.min(), img.max(), BINS)
290
290
  return bins, hist
291
-
291
+
292
292
  def hplot(self, frame):
293
293
  self.__frame = frame # update reference of the frame
294
294
  if frame:
@@ -300,7 +300,7 @@ class Histogram(LinePlot):
300
300
  self.toolbar.update()
301
301
  self.toolbar.push_current()
302
302
  self.draw()
303
-
303
+
304
304
  def hreplot(self, frame):
305
305
  self.__frame = frame # update reference of the frame
306
306
  if frame:
@@ -325,7 +325,7 @@ class Histogram(LinePlot):
325
325
  self.toolbar.update()
326
326
  self.toolbar.push_current()
327
327
  self.draw()
328
-
328
+
329
329
  def writeln(self):
330
330
  if not self.modeline.IsShown():
331
331
  return
@@ -343,11 +343,11 @@ class Histogram(LinePlot):
343
343
  ))
344
344
  else:
345
345
  self.modeline.SetLabel("")
346
-
346
+
347
347
  ## --------------------------------
348
348
  ## Motion/Drag actions (override)
349
349
  ## --------------------------------
350
-
350
+
351
351
  def annotate(self):
352
352
  if self.__frame:
353
353
  x, y = self.__frame.__data
@@ -362,7 +362,7 @@ class Histogram(LinePlot):
362
362
  else:
363
363
  self.__fil.set_xy([(0,0)])
364
364
  self.writeln()
365
-
365
+
366
366
  def OnDragEnd(self, evt):
367
367
  LinePlot.OnDragEnd(self, evt)
368
368
 
@@ -373,7 +373,7 @@ class Histogram(LinePlot):
373
373
  self.draw()
374
374
  self.__frame.clim = self.xlim
375
375
  self.__frame.parent.draw()
376
-
376
+
377
377
  def OnEscapeSelection(self, evt):
378
378
  LinePlot.OnEscapeSelection(self, evt)
379
379
 
@@ -384,7 +384,7 @@ class Histogram(LinePlot):
384
384
 
385
385
 
386
386
  class LineProfile(LinePlot):
387
- """LinePlot panel for line profile (Multi-graph : Single-frame)
387
+ """LinePlot panel for line profile (Multi-graph : Single-frame).
388
388
 
389
389
  Attributes:
390
390
  __graphs: list of attached graph <matplot2g.GraphPlot>
@@ -460,12 +460,12 @@ class LineProfile(LinePlot):
460
460
  ]
461
461
 
462
462
  self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
463
-
463
+
464
464
  def OnDestroy(self, evt):
465
465
  for graph in self.__graphs:
466
466
  self.detach(graph)
467
467
  evt.Skip()
468
-
468
+
469
469
  def clear(self):
470
470
  LinePlot.clear(self)
471
471
 
@@ -488,19 +488,19 @@ class LineProfile(LinePlot):
488
488
  self.__logicp = True
489
489
 
490
490
  self.selected.set_linestyle('')
491
-
491
+
492
492
  def attach(self, *graphs):
493
493
  for graph in graphs:
494
494
  if graph not in self.__graphs:
495
495
  self.__graphs.append(graph)
496
496
  graph.handler.append(self.context)
497
-
497
+
498
498
  def detach(self, *graphs):
499
499
  for graph in graphs:
500
500
  if graph in self.__graphs:
501
501
  self.__graphs.remove(graph)
502
502
  graph.handler.remove(self.context)
503
-
503
+
504
504
  def set_logic(self, p):
505
505
  prep = self.__logicp
506
506
  self.__logicp = p = bool(p)
@@ -515,25 +515,25 @@ class LineProfile(LinePlot):
515
515
  sel = self.selector
516
516
  self.selector = (sel[0] * ru, sel[1])
517
517
  self.draw()
518
-
518
+
519
519
  def set_linewidth(self, w):
520
520
  if 0 < w < 256:
521
521
  self.__linewidth = w
522
522
  if self.__frame:
523
523
  self.linplot(self.__frame, fit=0)
524
524
  self.writeln()
525
-
525
+
526
526
  @property
527
527
  def boundary(self):
528
528
  x = self.__plot.get_xdata(orig=0)
529
529
  if x.size:
530
530
  return x[[0,-1]]
531
-
531
+
532
532
  @property
533
533
  def plotdata(self):
534
534
  """Plotted (xdata, ydata) in single plot."""
535
535
  return self.__plot.get_data(orig=0)
536
-
536
+
537
537
  def calc_average(self):
538
538
  X, Y = self.plotdata
539
539
  if self.region is not None:
@@ -541,7 +541,7 @@ class LineProfile(LinePlot):
541
541
  Y = Y[(a <= X) & (X <= b)]
542
542
  if Y.size:
543
543
  return Y.mean()
544
-
544
+
545
545
  def linplot(self, frame, fit=True, force=True):
546
546
  if not force:
547
547
  if frame is self.__frame:
@@ -601,7 +601,7 @@ class LineProfile(LinePlot):
601
601
  self.toolbar.update()
602
602
  self.toolbar.push_current()
603
603
  self.draw()
604
-
604
+
605
605
  def writeln(self):
606
606
  if not self.modeline.IsShown():
607
607
  return
@@ -620,7 +620,7 @@ class LineProfile(LinePlot):
620
620
  a = '%%' if not frame.buffer.flags.writeable else '--'))
621
621
  else:
622
622
  self.modeline.SetLabel("")
623
-
623
+
624
624
  def write_data_to_clipboard(self):
625
625
  """Write plot data to clipboard."""
626
626
  X, Y = self.plotdata
@@ -629,7 +629,7 @@ class LineProfile(LinePlot):
629
629
  o.write("{:g}\t{:g}\n".format(x, y))
630
630
  Clipboard.write(o.getvalue())
631
631
  self.message("Write data to clipboard.")
632
-
632
+
633
633
  def annotate(self):
634
634
  LinePlot.annotate(self)
635
635
 
@@ -637,49 +637,49 @@ class LineProfile(LinePlot):
637
637
  if x.size:
638
638
  self.__fil.set_xy(list(chain([(x[0], 0)], zip(x, y), [(x[-1], 0)])))
639
639
  self.writeln()
640
-
640
+
641
641
  ## --------------------------------
642
642
  ## Motion/Drag actions (override)
643
643
  ## --------------------------------
644
-
644
+
645
645
  def OnHomeXPosition(self, evt):
646
646
  x = self.plotdata[0]
647
647
  if x.size:
648
648
  self.xlim = x[0], x[-1]
649
649
  self.toolbar.push_current()
650
650
  self.draw()
651
-
651
+
652
652
  def OnHomeYPosition(self, evt):
653
653
  y = self.plotdata[1]
654
654
  if y.size:
655
655
  self.ylim = 0, y.max()
656
656
  self.toolbar.push_current()
657
657
  self.draw()
658
-
658
+
659
659
  def OnLineWidth(self, evt):
660
660
  n = -2 if evt.key[-1] == '-' else 2
661
661
  self.set_linewidth(self.__linewidth + n)
662
-
662
+
663
663
  def OnRegionShift(self, evt):
664
664
  if self.__frame and self.region is not None:
665
665
  u = self.__frame.unit
666
666
  if evt.key == "left": self.region -= u
667
667
  if evt.key == "right": self.region += u
668
668
  self.draw()
669
-
669
+
670
670
  def OnEscapeSelection(self, evt):
671
671
  self.__hline.set_visible(0)
672
672
  LinePlot.OnEscapeSelection(self, evt)
673
-
673
+
674
674
  def OnDragLineBegin(self, evt):
675
675
  self.set_wxcursor(wx.CURSOR_SIZENS)
676
-
676
+
677
677
  def OnDragTrace(self, evt):
678
678
  """Show average value."""
679
679
  y = self.calc_average()
680
680
  if y is not None:
681
681
  self.message(f"ya = {y:g}")
682
-
682
+
683
683
  def OnRegionLock(self, evt):
684
684
  """Show FWHM region."""
685
685
  x, y = self.plotdata
@@ -713,7 +713,7 @@ class LineProfile(LinePlot):
713
713
  self.__hline.set_visible(1)
714
714
  self.draw()
715
715
  self.message(f"yc = {yc:g}")
716
-
716
+
717
717
  def OnMarkPeaks(self, evt):
718
718
  """Set markers on peaks."""
719
719
  x, y = self.plotdata
@@ -731,12 +731,12 @@ class LineProfile(LinePlot):
731
731
  peaks = np.sort(np.append(maxima, minima))
732
732
  if peaks.size:
733
733
  self.selector = x[peaks], y[peaks]
734
-
734
+
735
735
  def OnMarkErase(self, evt):
736
736
  """Erase markers on peaks."""
737
737
  ## del self.selector
738
738
  self.OnEscapeSelection(evt)
739
-
739
+
740
740
  def OnMarkSelectionBegin(self, evt):
741
741
  org = self.p_event
742
742
  xs, ys = self.selector
@@ -748,7 +748,7 @@ class LineProfile(LinePlot):
748
748
  self.__orgpoint = xs[j]
749
749
  self.set_wxcursor(wx.CURSOR_SIZEWE)
750
750
  self.draw()
751
-
751
+
752
752
  def OnMarkSelectionMove(self, evt):
753
753
  xs, ys = self.selector
754
754
  xc, yc = evt.xdata, evt.ydata
mwx/mgplt.py CHANGED
@@ -16,16 +16,16 @@ class Gnuplot:
16
16
  """Gnuplot backend - gnuplot pipe wrapper.
17
17
  """
18
18
  debug = 0
19
-
19
+
20
20
  PGNUPLOT = "gnuplot" # Note: gnuplot/pgnuplot is integrated
21
-
21
+
22
22
  @staticmethod
23
23
  def init_path(path):
24
24
  if not os.path.isdir(path):
25
25
  print("- {!r} is not a directory.".format(path))
26
26
  return False
27
27
  os.environ['PATH'] = "{};{}".format(path, os.environ['PATH'])
28
-
28
+
29
29
  def __init__(self, startup="__init__.plt", debug=0):
30
30
  print("Launching new gnuplot...")
31
31
  self.__gnuplot = Popen([self.PGNUPLOT],
@@ -36,13 +36,13 @@ class Gnuplot:
36
36
  self.tempfile = tempfile.mktemp()
37
37
  self.debug = debug
38
38
  self.reset()
39
-
39
+
40
40
  def __del__(self):
41
41
  print("bye gnuplot...")
42
42
  self.terminate()
43
43
  if os.path.isfile(self.tempfile):
44
44
  os.remove(self.tempfile)
45
-
45
+
46
46
  def __call__(self, text):
47
47
  for cmd in filter(None, (t.strip() for t in text.splitlines())):
48
48
  self.__gnuplot.stdin.write((cmd + '\n').encode())
@@ -50,7 +50,7 @@ class Gnuplot:
50
50
  print("pgnupot>", cmd)
51
51
  self.__gnuplot.stdin.flush()
52
52
  return self
53
-
53
+
54
54
  def plot(self, *args):
55
55
  if isinstance(args[0], str): # text command
56
56
  pcmd = [v.strip() for v in args]
@@ -91,7 +91,7 @@ class Gnuplot:
91
91
  o.write('\t'.join(self.data_format(x) for x in v) + '\n')
92
92
 
93
93
  self("plot " + ', '.join(pcmd))
94
-
94
+
95
95
  def terminate(self):
96
96
  if self.__gnuplot is not None:
97
97
  try:
@@ -101,21 +101,21 @@ class Gnuplot:
101
101
  except Exception:
102
102
  pass
103
103
  self.__gnuplot = None
104
-
104
+
105
105
  def restart(self):
106
106
  self.terminate()
107
107
  self.__init__(self.startupfile)
108
-
108
+
109
109
  def reset(self, startup=None):
110
110
  if startup:
111
111
  self.startupfile = startup
112
112
  if self.startupfile:
113
113
  self("load '{}'".format(self.startupfile))
114
114
  self("tempfile = '{}'".format(self.tempfile))
115
-
115
+
116
116
  def wait(self, msg=""):
117
117
  input(msg + " (Press ENTER to continue)")
118
-
118
+
119
119
  def edit(self):
120
120
  with warnings.catch_warnings():
121
121
  warnings.simplefilter("ignore", ResourceWarning)
@@ -152,7 +152,7 @@ class GnuplotFrame(mwx.Frame):
152
152
  lambda v: self.gnuplot.restart()),
153
153
  ]
154
154
  self.menubar.reset()
155
-
155
+
156
156
  def Destroy(self):
157
157
  del self.gnuplot
158
158
  return mwx.Frame.Destroy(self)