import matplotlib.pyplot as plt

from bluesky import RunEngine, Mover, SynGauss
from bluesky.examples import adaptive_scan


RE = RunEngine()
RE.verbose = False
motor = Mover('motor', ['pos'])
det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1)


def live_scalar_plotter(ax, y, x):
    x_data, y_data = [], []
    line, = ax.plot([], [], 'ro', markersize=10)

    def update_plot(doc):
        # Update with the latest data.
        x_data.append(doc['data'][x])
        y_data.append(doc['data'][y])
        line.set_data(x_data, y_data)
        # Rescale and redraw.
        ax.relim(visible_only=True)
        ax.autoscale_view(tight=True)
        ax.figure.canvas.draw()
        ax.figure.canvas.flush_events()

    return update_plot

fig, ax = plt.subplots()
plt.show()
ax.set_xlim([-15, 5])
ax.set_ylim([0, 2])
# Point the function to our axes above, and specify what to plot.
my_plotter = live_scalar_plotter(ax, 'det', 'pos')
ad_scan = adaptive_scan(motor, det, 'pos', 'det', -15, 5, .01, 1, .05)
RE.run(ad_scan, subscriptions={'event': my_plotter})

import matplotlib.pyplot as plt

from bluesky import RunEngine
from bluesky.scans import AdaptiveAscan
from bluesky.examples import Mover, SynGauss
from bluesky.callbacks import LivePlot, LiveTable
from bluesky.tests.utils import setup_test_run_engine


#plt.ion()
RE = setup_test_run_engine()
motor = Mover('motor', ['pos'])
det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1)


#fig, ax = plt.subplots()
#ax.set_xlim([-15, 5])
#ax.set_ylim([0, 2])
# Point the function to our axes above, and specify what to plot.
#my_plotter = LivePlot('det', 'pos')
table = LiveTable(['det', 'pos'])
ad_scan = AdaptiveAscan(motor, [det], 'det', -15, 5, .01, 1, .05, True)
RE(ad_scan, subscriptions={'all': [table]}) #, my_plotter})

Fix adaptive example with LivePlot
WIP: Fix adaptive example with LivePlot

  import matplotlib.pyplot as plt
  
- from bluesky import RunEngine, Mover, SynGauss
+ from bluesky import RunEngine
- from bluesky.examples import adaptive_scan
+ from bluesky.scans import AdaptiveAscan
+ from bluesky.examples import Mover, SynGauss
+ from bluesky.callbacks import LivePlot, LiveTable
+ from bluesky.tests.utils import setup_test_run_engine
  
  
- RE = RunEngine()
- RE.verbose = False
+ #plt.ion()
+ RE = setup_test_run_engine()
  motor = Mover('motor', ['pos'])
  det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1)
  
  
- def live_scalar_plotter(ax, y, x):
-     x_data, y_data = [], []
-     line, = ax.plot([], [], 'ro', markersize=10)
+ #fig, ax = plt.subplots()
+ #ax.set_xlim([-15, 5])
+ #ax.set_ylim([0, 2])
+ # Point the function to our axes above, and specify what to plot.
+ #my_plotter = LivePlot('det', 'pos')
+ table = LiveTable(['det', 'pos'])
+ ad_scan = AdaptiveAscan(motor, [det], 'det', -15, 5, .01, 1, .05, True)
+ RE(ad_scan, subscriptions={'all': [table]}) #, my_plotter})
  
-     def update_plot(doc):
-         # Update with the latest data.
-         x_data.append(doc['data'][x])
-         y_data.append(doc['data'][y])
-         line.set_data(x_data, y_data)
-         # Rescale and redraw.
-         ax.relim(visible_only=True)
-         ax.autoscale_view(tight=True)
-         ax.figure.canvas.draw()
-         ax.figure.canvas.flush_events()
- 
-     return update_plot
- 
- fig, ax = plt.subplots()
- plt.show()
- ax.set_xlim([-15, 5])
- ax.set_ylim([0, 2])
- # Point the function to our axes above, and specify what to plot.
- my_plotter = live_scalar_plotter(ax, 'det', 'pos')
- ad_scan = adaptive_scan(motor, det, 'pos', 'det', -15, 5, .01, 1, .05)
- RE.run(ad_scan, subscriptions={'event': my_plotter})
- 
Fix adaptive example with LivePlot
## Code Before:
import matplotlib.pyplot as plt

from bluesky import RunEngine, Mover, SynGauss
from bluesky.examples import adaptive_scan


RE = RunEngine()
RE.verbose = False
motor = Mover('motor', ['pos'])
det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1)


def live_scalar_plotter(ax, y, x):
    x_data, y_data = [], []
    line, = ax.plot([], [], 'ro', markersize=10)

    def update_plot(doc):
        # Update with the latest data.
        x_data.append(doc['data'][x])
        y_data.append(doc['data'][y])
        line.set_data(x_data, y_data)
        # Rescale and redraw.
        ax.relim(visible_only=True)
        ax.autoscale_view(tight=True)
        ax.figure.canvas.draw()
        ax.figure.canvas.flush_events()

    return update_plot

fig, ax = plt.subplots()
plt.show()
ax.set_xlim([-15, 5])
ax.set_ylim([0, 2])
# Point the function to our axes above, and specify what to plot.
my_plotter = live_scalar_plotter(ax, 'det', 'pos')
ad_scan = adaptive_scan(motor, det, 'pos', 'det', -15, 5, .01, 1, .05)
RE.run(ad_scan, subscriptions={'event': my_plotter})

## Instruction:
Fix adaptive example with LivePlot
## Code After:
import matplotlib.pyplot as plt

from bluesky import RunEngine
from bluesky.scans import AdaptiveAscan
from bluesky.examples import Mover, SynGauss
from bluesky.callbacks import LivePlot, LiveTable
from bluesky.tests.utils import setup_test_run_engine


#plt.ion()
RE = setup_test_run_engine()
motor = Mover('motor', ['pos'])
det = SynGauss('det', motor, 'pos', center=0, Imax=1, sigma=1)


#fig, ax = plt.subplots()
#ax.set_xlim([-15, 5])
#ax.set_ylim([0, 2])
# Point the function to our axes above, and specify what to plot.
#my_plotter = LivePlot('det', 'pos')
table = LiveTable(['det', 'pos'])
ad_scan = AdaptiveAscan(motor, [det], 'det', -15, 5, .01, 1, .05, True)
RE(ad_scan, subscriptions={'all': [table]}) #, my_plotter})
