More restructuring
This commit is contained in:
parent
977b091191
commit
79cb5b3ec4
@ -4,9 +4,11 @@ from PyQt4.QtCore import QObject, Qt, pyqtSignal, pyqtSlot
|
||||
from PyQt4.QtGui import QColor
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
import ContainerWidgets
|
||||
import libyaff
|
||||
from BDSMathlib import Functions, id_to_color
|
||||
from math.BDSMathlib import id_to_color
|
||||
from math import libyaff
|
||||
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
|
@ -1,149 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright © 2009 Pierre Raybaut
|
||||
# Licensed under the terms of the MIT License
|
||||
|
||||
"""
|
||||
MatplotlibWidget
|
||||
================
|
||||
|
||||
Example of matplotlib widget for PyQt4
|
||||
|
||||
Copyright © 2009 Pierre Raybaut
|
||||
This software is licensed under the terms of the MIT License
|
||||
|
||||
Derived from 'embedding_in_pyqt4.py':
|
||||
Copyright © 2005 Florent Rougon, 2006 Darren Dale
|
||||
"""
|
||||
from QDSToolbar import CustomToolbar
|
||||
|
||||
__version__ = "1.0.0"
|
||||
|
||||
from PyQt4.QtGui import QSizePolicy, QWidget, QVBoxLayout
|
||||
from PyQt4.QtCore import QSize, Qt
|
||||
|
||||
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as Canvas
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from matplotlib import rcParams
|
||||
|
||||
rcParams['font.size'] = 9
|
||||
|
||||
|
||||
class MatplotlibWidget(Canvas):
|
||||
"""
|
||||
MatplotlibWidget inherits PyQt4.QtGui.QWidget
|
||||
and matplotlib.backend_bases.FigureCanvasBase
|
||||
|
||||
Options: option_name (default_value)
|
||||
-------
|
||||
parent (None): parent widget
|
||||
title (''): figure title
|
||||
xlabel (''): X-axis label
|
||||
ylabel (''): Y-axis label
|
||||
xlim (None): X-axis limits ([min, max])
|
||||
ylim (None): Y-axis limits ([min, max])
|
||||
xscale ('linear'): X-axis scale
|
||||
yscale ('linear'): Y-axis scale
|
||||
width (4): width in inches
|
||||
height (3): height in inches
|
||||
dpi (100): resolution in dpi
|
||||
hold (False): if False, figure will be cleared each time plot is called
|
||||
|
||||
Widget attributes:
|
||||
-----------------
|
||||
figure: instance of matplotlib.figure.Figure
|
||||
axes: figure axes
|
||||
|
||||
Example:
|
||||
-------
|
||||
self.widget = MatplotlibWidget(self, yscale='log', hold=True)
|
||||
from numpy import linspace
|
||||
x = linspace(-10, 10)
|
||||
self.widget.axes.plot(x, x**2)
|
||||
self.wdiget.axes.plot(x, x**3)
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None, title='', xlabel='', ylabel='',
|
||||
xlim=None, ylim=None, xscale='linear', yscale='linear',
|
||||
width=6, height=4, dpi=100, hold=False):
|
||||
self.figure = Figure(figsize=(width, height), dpi=dpi)
|
||||
self.axes = self.figure.add_subplot(111)
|
||||
self.axes.set_title(title)
|
||||
self.axes.set_xlabel(xlabel)
|
||||
self.axes.set_ylabel(ylabel)
|
||||
if xscale is not None:
|
||||
self.axes.set_xscale(xscale)
|
||||
if yscale is not None:
|
||||
self.axes.set_yscale(yscale)
|
||||
if xlim is not None:
|
||||
self.axes.set_xlim(*xlim)
|
||||
if ylim is not None:
|
||||
self.axes.set_ylim(*ylim)
|
||||
self.axes.hold(hold)
|
||||
|
||||
Canvas.__init__(self, self.figure)
|
||||
self.setParent(parent)
|
||||
|
||||
Canvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
Canvas.updateGeometry(self)
|
||||
|
||||
def sizeHint(self):
|
||||
w, h = self.get_width_height()
|
||||
return QSize(w, h)
|
||||
|
||||
def minimumSizeHint(self):
|
||||
return QSize(10, 10)
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Example
|
||||
#===============================================================================
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from PyQt4.QtGui import QMainWindow, QApplication
|
||||
from numpy import linspace
|
||||
|
||||
class ApplicationWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
QMainWindow.__init__(self)
|
||||
self.mplwidget = MatplotlibWidget(self, title='Example',
|
||||
xlabel='Linear scale',
|
||||
ylabel='Log scale',
|
||||
hold=True, yscale='log')
|
||||
self.mplwidget.setFocus()
|
||||
self.setCentralWidget(self.mplwidget)
|
||||
self.plot(self.mplwidget.axes)
|
||||
|
||||
def plot(self, axes):
|
||||
x = linspace(-10, 10)
|
||||
axes.plot(x, x ** 2)
|
||||
axes.plot(x, x ** 3)
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
win = ApplicationWindow()
|
||||
win.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
||||
class PlotWidget(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
QWidget.__init__(self)
|
||||
super(PlotWidget, self).__init__(parent)
|
||||
self.mplwidget = MatplotlibWidget(hold=True,
|
||||
xlim=(1e-2, 1e7),
|
||||
xscale='log',
|
||||
yscale='log')
|
||||
self.canvas = self.mplwidget.figure.canvas # shortcut
|
||||
self.canvas.axes.grid(True)
|
||||
#self.bbox_size = self.canvas.axes.bbox.size
|
||||
self.toolbar = CustomToolbar(self.canvas, self.mplwidget, parent)
|
||||
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
|
||||
layout = QVBoxLayout(parent)
|
||||
#self.mplwidget.setLayout(layout)
|
||||
layout.addWidget(self.canvas)
|
||||
layout.addWidget(self.mplwidget)
|
||||
layout.addWidget(self.toolbar)
|
||||
self._bg_cache = None
|
||||
self._axvlims = []
|
||||
self._axvname = []
|
2
QDS.py
2
QDS.py
@ -24,7 +24,7 @@ import pyqtgraph as pg
|
||||
|
||||
from Container import Conductivity, PowerComplex, Static, Peak, YAFF
|
||||
from ContainerWidgets import ParameterWidget
|
||||
from BDSMathlib import FunctionRegister, FitRoutine
|
||||
from math.BDSMathlib import FunctionRegister, FitRoutine
|
||||
from data.data import Data
|
||||
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
from PyQt4.QtCore import pyqtSignal
|
||||
from PyQt4.QtGui import QAction, QIcon, QPixmap
|
||||
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar, NavigationToolbar2QTAgg
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
|
||||
class CustomToolbar(NavigationToolbar):
|
||||
# our spanChanged signal
|
||||
spanSelectedTrigger = pyqtSignal(float, float, name='spanChanged')
|
||||
|
||||
def __init__(self, plotCanvas, plotWidget, parent=None):
|
||||
NavigationToolbar.__init__(self, plotCanvas, plotWidget, coordinates=True)
|
||||
self.canvas = plotCanvas
|
||||
# Span select Button
|
||||
#self.span_button = QAction(QIcon("border-1d-right-icon.png" ), "Span", self)
|
||||
self.span_button = QAction(QIcon(QPixmap(":/icons/fit_limits.png")), "Fit Limits", self)
|
||||
self.span_button.setCheckable(True)
|
||||
|
||||
self.cids = []
|
||||
self.cids.append(self.canvas.mpl_connect('button_press_event', self.press))
|
||||
self.cids.append(self.canvas.mpl_connect('motion_notify_event', self.onmove))
|
||||
self.cids.append(self.canvas.mpl_connect('button_release_event', self.release))
|
||||
self.cids.append(self.canvas.mpl_connect('draw_event', self.update_background))
|
||||
|
||||
|
||||
# act.setCheckable(True)
|
||||
# add actions before the coordinates widget
|
||||
self.insertAction(self.actions()[-1], self.span_button)
|
||||
|
||||
self.buttons = {}
|
||||
self._pressed = False
|
||||
self.background = None
|
||||
self.span = None
|
||||
self.istart = 0
|
||||
self.iend = 0
|
||||
self.xstart = 0
|
||||
self.xend = 0
|
||||
|
||||
def set_span(self, x1, x2):
|
||||
#trans = blended_transform_factory(self.axes.transData, self.axes.transAxes)
|
||||
cur = self.span.get_xy()
|
||||
cur[0, 0] = x1
|
||||
cur[1, 0] = x1
|
||||
cur[2, 0] = x2
|
||||
cur[3, 0] = x2
|
||||
self.span.set_xy(cur)
|
||||
|
||||
def ignore(self, event):
|
||||
# 'return ``True`` if *event* should be ignored'
|
||||
return event.inaxes != self.canvas.axes or event.button != 1
|
||||
|
||||
def update_background(self, event):
|
||||
#if self.canvas.axes is None:
|
||||
# raise SyntaxError,"Need an axes reference!"
|
||||
self.background = self.canvas.copy_from_bbox(self.canvas.axes.bbox)
|
||||
|
||||
def press(self, event):
|
||||
if self.span_button.isChecked():
|
||||
if self.background is None:
|
||||
self.update_background()
|
||||
else:
|
||||
self.canvas.restore_region(self.background)
|
||||
self.xstart = event.xdata
|
||||
self.istart = event.x
|
||||
if self.span is None:
|
||||
self.span = self.canvas.axes.axvspan(event.xdata, event.xdata, alpha=0.10, color="k", animated=False)
|
||||
else:
|
||||
self.set_span(event.xdata, event.xdata)
|
||||
self._pressed = True
|
||||
|
||||
def onmove(self, event):
|
||||
if self.span_button.isChecked() and self._pressed and not self.ignore(event):
|
||||
self.set_span(self.xstart, event.xdata)
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
"""Overrides method of NavigationToolbar.
|
||||
Allows fast drawing of the span selector with blitting
|
||||
"""
|
||||
self.canvas.restore_region(self.background)
|
||||
self.canvas.axes.draw_artist(self.span)
|
||||
for line in self.canvas.axes.get_lines():
|
||||
self.canvas.axes.draw_artist(line)
|
||||
self.canvas.blit(self.canvas.axes.bbox)
|
||||
|
||||
def release(self, event):
|
||||
self.span_button.setChecked(False)
|
||||
self.xend = event.xdata
|
||||
self.iend = event.x
|
||||
if self.iend < self.istart:
|
||||
self.iend, self.istart = self.istart, self.iend
|
||||
#print "released", self.xstart, self.xend
|
||||
if self._pressed:
|
||||
if self.ignore(event):
|
||||
self.istart = 0
|
||||
self.spanSelectedTrigger.emit(self.xstart, self.xend)
|
||||
self._pressed = False
|
@ -3,7 +3,8 @@ from PyQt4.QtGui import QColor
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
from BDSMathlib import FitFunctionCreator
|
||||
from math.BDSMathlib import FitFunctionCreator
|
||||
|
||||
|
||||
class Data:
|
||||
def __init__(self, frequency=np.zeros(1), die_real=np.zeros(1), die_imag=np.zeros(1)):
|
||||
|
@ -1,8 +1,9 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
from gui import ExtraDifferential
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
from PyQt4.QtGui import QColor
|
||||
import ExtraDifferential
|
||||
import pyqtgraph as pg
|
||||
import numpy as np
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
from math import libyaff
|
||||
|
||||
__author__ = 'markusro'
|
||||
|
||||
from PyQt4.QtGui import QColor
|
||||
from PyQt4.QtCore import QObject, pyqtSignal, QThread, pyqtSlot
|
||||
from PyQt4.QtCore import QObject, pyqtSignal, pyqtSlot
|
||||
|
||||
import numpy as np
|
||||
from scipy import optimize as opt, odr
|
||||
|
||||
import libyaff
|
||||
|
||||
|
||||
def id_to_color( id ):
|
||||
colors = [
|
0
libmath/__init__.py
Normal file
0
libmath/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user