Publishers: plot with Plotly#
publish_plotly.py#
"""Example: Publishers: plot with Plotly.
Plots a simulated PSU voltage sweep on a Plotly figure with PlotlyPublisher, then
shows the figure once the sweep finishes. In a Jupyter notebook, display a
``go.FigureWidget`` instead to watch the plot update live.
Requires the plot extra: install with ``uv sync --extra plot``
(or ``pip install 'instro[plot]'``).
Start the simulated PSU first:
python -m instro.psu.scpi_sim_server
Then in another shell:
python examples/publishers/publish_plotly.py
"""
import time
from instro.lib.publishers import PlotlyPublisher
from instro.psu import InstroPSU
from instro.psu.drivers import SimulatedPSU
VISA_RESOURCE = "TCPIP0::127.0.0.1::5025::SOCKET"
psu = InstroPSU(
name="myPSU",
driver=SimulatedPSU(VISA_RESOURCE),
num_channels=2,
publishers=[PlotlyPublisher()],
)
with psu:
psu.set_current_limit(0.2, channel=1)
psu.output_enable(True, channel=1)
for v in range(10):
psu.set_voltage(v, channel=1)
time.sleep(0.5)
psu.get_voltage(channel=1)
psu.get_current(channel=1)
psu.output_enable(False, channel=1)