Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2199eadb9962
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 26a6e8c5dee9
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 10, 2016

  1. Copy the full SHA
    4136ff6 View commit details
  2. Copy the full SHA
    db06e73 View commit details
  3. Copy the full SHA
    26a6e8c View commit details
Showing with 105 additions and 4 deletions.
  1. +39 −0 artiq/applets/plot_hist.py
  2. +59 −0 artiq/applets/plot_xy.py
  3. +7 −4 artiq/applets/simple.py
39 changes: 39 additions & 0 deletions artiq/applets/plot_hist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3.5

import numpy as np
import pyqtgraph

from artiq.applets.simple import SimpleApplet


class HistogramPlot(pyqtgraph.PlotWidget):
def __init__(self, args):
pyqtgraph.PlotWidget.__init__(self)
self.args = args

def data_changed(self, data, mods):
try:
y = data[self.args.y][1]
if self.args.x is None:
x = None
else:
x = data[self.args.x][1]
except KeyError:
return
if x is None:
x = list(range(len(y)+1))

if len(y) and len(x) == len(y) + 1:
self.clear()
self.plot(x, y, stepMode=True, fillLevel=0,
brush=(0, 0, 255, 150))


def main():
applet = SimpleApplet(HistogramPlot)
applet.add_dataset("y", "Y values")
applet.add_dataset("x", "X values", required=False)
applet.run()

if __name__ == "__main__":
main()
59 changes: 59 additions & 0 deletions artiq/applets/plot_xy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3.5

import numpy as np
import pyqtgraph

from artiq.applets.simple import SimpleApplet


class XYPlot(pyqtgraph.PlotWidget):
def __init__(self, args):
pyqtgraph.PlotWidget.__init__(self)
self.args = args

def data_changed(self, data, mods):
try:
y = data[self.args.y][1]
except KeyError:
return
x = data.get(self.args.x, (False, None))[1]
if x is None:
x = list(range(len(y)))
error = data.get(self.args.error, (False, None))[1]
fit = data.get(self.args.fit, (False, None))[1]

if not len(y) or len(y) != len(x):
return
if error is not None and hasattr(error, "__len__"):
if not len(error):
error = None
elif len(error) != len(y):
return
if fit is not None:
if not len(fit):
fit = None
elif len(fit) != len(y):
return

self.clear()
self.plot(x, y, pen=None, symbol="x")
if error is not None:
# See https://github.com/pyqtgraph/pyqtgraph/issues/211
if hasattr(error, "__len__") and not isinstance(error, np.ndarray):
error = np.array(error)
errbars = pg.ErrorBarItem(x=np.array(x), y=np.array(y), height=error)
self.addItem(errbars)
if fit is not None:
self.plot(x, fit)


def main():
applet = SimpleApplet(XYPlot)
applet.add_dataset("y", "Y values")
applet.add_dataset("x", "X values", required=False)
applet.add_dataset("error", "Error bars for each X value", required=False)
applet.add_dataset("fit", "Fit values for each X value", required=False)
applet.run()

if __name__ == "__main__":
main()
11 changes: 7 additions & 4 deletions artiq/applets/simple.py
Original file line number Diff line number Diff line change
@@ -30,11 +30,14 @@ def __init__(self, main_widget_class, cmd_description=None):
help="embed main widget into existing window")
self._arggroup_datasets = self.argparser.add_argument_group("datasets")

def add_dataset(self, name, help=None):
if help is None:
self._arggroup_datasets.add_argument(name)
def add_dataset(self, name, help=None, required=True):
kwargs = dict()
if help is not None:
kwargs["help"] = help
if required:
self._arggroup_datasets.add_argument(name, **kwargs)
else:
self._arggroup_datasets.add_argument(name, help=help)
self._arggroup_datasets.add_argument("--" + name, **kwargs)

def args_init(self):
self.args = self.argparser.parse_args()